hogql-parser 1.2.0__tar.gz → 1.2.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of hogql-parser might be problematic. Click here for more details.
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/PKG-INFO +12 -2
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/README.md +1 -1
- hogql_parser-1.2.8/hogql_parser-stubs/__init__.pyi +44 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/hogql_parser.egg-info/PKG-INFO +13 -3
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/hogql_parser.egg-info/SOURCES.txt +1 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/parser.cpp +122 -1
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/pyproject.toml +7 -9
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/setup.py +3 -2
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/HogQLLexer.cpp +0 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/HogQLParser.cpp +0 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/HogQLParserBaseVisitor.cpp +0 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/HogQLParserVisitor.cpp +0 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/error.cpp +0 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/hogql_parser.egg-info/dependency_links.txt +0 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/hogql_parser.egg-info/top_level.txt +0 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/setup.cfg +0 -0
- {hogql_parser-1.2.0 → hogql_parser-1.2.8}/string.cpp +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: hogql_parser
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.8
|
|
4
4
|
Summary: HogQL parser for internal PostHog use
|
|
5
5
|
Home-page: https://github.com/PostHog/posthog/tree/master/common/hogql_parser
|
|
6
6
|
Author: PostHog Inc.
|
|
@@ -17,6 +17,16 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
18
|
Requires-Python: >=3.10
|
|
19
19
|
Description-Content-Type: text/markdown
|
|
20
|
+
Dynamic: author
|
|
21
|
+
Dynamic: author-email
|
|
22
|
+
Dynamic: classifier
|
|
23
|
+
Dynamic: description
|
|
24
|
+
Dynamic: description-content-type
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: maintainer
|
|
27
|
+
Dynamic: maintainer-email
|
|
28
|
+
Dynamic: requires-python
|
|
29
|
+
Dynamic: summary
|
|
20
30
|
|
|
21
31
|
# HogQL Parser
|
|
22
32
|
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
Blazing fast HogQL parsing. This package can only work in the context of the PostHog Django app, as it imports from `posthog.hogql`.
|
|
4
4
|
|
|
5
|
-
You can test changes locally by running `pip install ./hogql_parser`
|
|
5
|
+
You can test changes locally by running `pip install ./hogql_parser`
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from posthog.hogql.ast import Program, SelectQuery, SelectSetQuery
|
|
2
|
+
from posthog.hogql.base import AST
|
|
3
|
+
|
|
4
|
+
def parse_expr(expr: str, /, *, is_internal: bool = False) -> AST:
|
|
5
|
+
"""Parse the HogQL expression string into an AST.
|
|
6
|
+
|
|
7
|
+
If the expr `is_internal`, spans and notices won't be included in the AST.
|
|
8
|
+
"""
|
|
9
|
+
...
|
|
10
|
+
|
|
11
|
+
def parse_order_expr(expr: str, /, *, is_internal: bool = False) -> AST:
|
|
12
|
+
"""Parse the ORDER BY clause string into an AST.
|
|
13
|
+
|
|
14
|
+
If the expr `is_internal`, spans and notices won't be included in the AST.
|
|
15
|
+
"""
|
|
16
|
+
...
|
|
17
|
+
|
|
18
|
+
def parse_select(expr: str, /, *, is_internal: bool = False) -> SelectQuery | SelectSetQuery:
|
|
19
|
+
"""Parse the HogQL SELECT statement string into an AST.
|
|
20
|
+
|
|
21
|
+
If the expr `is_internal`, spans and notices won't be included in the AST.
|
|
22
|
+
"""
|
|
23
|
+
...
|
|
24
|
+
|
|
25
|
+
def parse_full_template_string(expr: str, /, *, is_internal: bool = False) -> AST:
|
|
26
|
+
"""Parse a Hog template string into an AST.
|
|
27
|
+
|
|
28
|
+
If the expr `is_internal`, spans and notices won't be included in the AST.
|
|
29
|
+
"""
|
|
30
|
+
...
|
|
31
|
+
|
|
32
|
+
def parse_string_literal_text(value: str, /) -> str:
|
|
33
|
+
"""Unquote the string (an identifier or a string literal).
|
|
34
|
+
|
|
35
|
+
If the expr is `internal`, spans and notices won't be included in the AST.
|
|
36
|
+
"""
|
|
37
|
+
...
|
|
38
|
+
|
|
39
|
+
def parse_program(source: str, /, *, is_internal: bool = False) -> Program:
|
|
40
|
+
"""Parse a Hog program.
|
|
41
|
+
|
|
42
|
+
If the expr `is_internal`, spans and notices won't be included in the AST.
|
|
43
|
+
"""
|
|
44
|
+
...
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
2
|
-
Name:
|
|
3
|
-
Version: 1.2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hogql_parser
|
|
3
|
+
Version: 1.2.8
|
|
4
4
|
Summary: HogQL parser for internal PostHog use
|
|
5
5
|
Home-page: https://github.com/PostHog/posthog/tree/master/common/hogql_parser
|
|
6
6
|
Author: PostHog Inc.
|
|
@@ -17,6 +17,16 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
18
|
Requires-Python: >=3.10
|
|
19
19
|
Description-Content-Type: text/markdown
|
|
20
|
+
Dynamic: author
|
|
21
|
+
Dynamic: author-email
|
|
22
|
+
Dynamic: classifier
|
|
23
|
+
Dynamic: description
|
|
24
|
+
Dynamic: description-content-type
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: maintainer
|
|
27
|
+
Dynamic: maintainer-email
|
|
28
|
+
Dynamic: requires-python
|
|
29
|
+
Dynamic: summary
|
|
20
30
|
|
|
21
31
|
# HogQL Parser
|
|
22
32
|
|
|
@@ -2124,7 +2124,128 @@ class HogQLParseTreeConverter : public HogQLParserBaseVisitor {
|
|
|
2124
2124
|
RETURN_NEW_AST_NODE("ArrayAccess", "{s:N,s:N,s:O}", "array", object, "property", property, "nullish", Py_True);
|
|
2125
2125
|
}
|
|
2126
2126
|
|
|
2127
|
-
|
|
2127
|
+
VISIT(ColumnExprBetween) {
|
|
2128
|
+
// x [NOT] BETWEEN y AND z -> inclusive ends: (x >= y AND x <= z) or NOT: (x < y OR x > z)
|
|
2129
|
+
PyObject* x = visitAsPyObject(ctx->columnExpr(0));
|
|
2130
|
+
PyObject* low;
|
|
2131
|
+
try {
|
|
2132
|
+
low = visitAsPyObject(ctx->columnExpr(1));
|
|
2133
|
+
} catch (...) {
|
|
2134
|
+
Py_DECREF(x);
|
|
2135
|
+
throw;
|
|
2136
|
+
}
|
|
2137
|
+
PyObject* high;
|
|
2138
|
+
try {
|
|
2139
|
+
high = visitAsPyObject(ctx->columnExpr(2));
|
|
2140
|
+
} catch (...) {
|
|
2141
|
+
Py_DECREF(low);
|
|
2142
|
+
Py_DECREF(x);
|
|
2143
|
+
throw;
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
if (ctx->NOT()) {
|
|
2147
|
+
// (x < low) OR (x > high)
|
|
2148
|
+
PyObject* lt_op = get_ast_enum_member("CompareOperationOp", "Lt");
|
|
2149
|
+
PyObject* gt_op = get_ast_enum_member("CompareOperationOp", "Gt");
|
|
2150
|
+
if (!lt_op || !gt_op) {
|
|
2151
|
+
Py_XDECREF(lt_op);
|
|
2152
|
+
Py_XDECREF(gt_op);
|
|
2153
|
+
Py_DECREF(high);
|
|
2154
|
+
Py_DECREF(low);
|
|
2155
|
+
Py_DECREF(x);
|
|
2156
|
+
throw PyInternalError();
|
|
2157
|
+
}
|
|
2158
|
+
Py_INCREF(x);
|
|
2159
|
+
PyObject* lt = build_ast_node("CompareOperation", "{s:N,s:N,s:N}", "left", x, "right", low, "op", lt_op);
|
|
2160
|
+
if (!lt) {
|
|
2161
|
+
Py_DECREF(gt_op);
|
|
2162
|
+
Py_DECREF(high);
|
|
2163
|
+
Py_DECREF(low);
|
|
2164
|
+
Py_DECREF(x);
|
|
2165
|
+
throw PyInternalError();
|
|
2166
|
+
}
|
|
2167
|
+
Py_INCREF(x);
|
|
2168
|
+
PyObject* gt = build_ast_node("CompareOperation", "{s:N,s:N,s:N}", "left", x, "right", high, "op", gt_op);
|
|
2169
|
+
if (!gt) {
|
|
2170
|
+
Py_DECREF(lt);
|
|
2171
|
+
Py_DECREF(high);
|
|
2172
|
+
Py_DECREF(low);
|
|
2173
|
+
Py_DECREF(x);
|
|
2174
|
+
throw PyInternalError();
|
|
2175
|
+
}
|
|
2176
|
+
PyObject* or_list = Py_BuildValue("[NN]", lt, gt);
|
|
2177
|
+
if (!or_list) {
|
|
2178
|
+
Py_DECREF(gt);
|
|
2179
|
+
Py_DECREF(lt);
|
|
2180
|
+
Py_DECREF(high);
|
|
2181
|
+
Py_DECREF(low);
|
|
2182
|
+
Py_DECREF(x);
|
|
2183
|
+
throw PyInternalError();
|
|
2184
|
+
}
|
|
2185
|
+
PyObject* result = build_ast_node("Or", "{s:N}", "exprs", or_list);
|
|
2186
|
+
if (!result) {
|
|
2187
|
+
Py_DECREF(or_list);
|
|
2188
|
+
Py_DECREF(high);
|
|
2189
|
+
Py_DECREF(low);
|
|
2190
|
+
Py_DECREF(x);
|
|
2191
|
+
throw PyInternalError();
|
|
2192
|
+
}
|
|
2193
|
+
Py_DECREF(x);
|
|
2194
|
+
return result;
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
// (x >= low) AND (x <= high)
|
|
2198
|
+
PyObject* gte_op = get_ast_enum_member("CompareOperationOp", "GtEq");
|
|
2199
|
+
PyObject* lte_op = get_ast_enum_member("CompareOperationOp", "LtEq");
|
|
2200
|
+
if (!gte_op || !lte_op) {
|
|
2201
|
+
Py_XDECREF(gte_op);
|
|
2202
|
+
Py_XDECREF(lte_op);
|
|
2203
|
+
Py_DECREF(high);
|
|
2204
|
+
Py_DECREF(low);
|
|
2205
|
+
Py_DECREF(x);
|
|
2206
|
+
throw PyInternalError();
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
Py_INCREF(x);
|
|
2210
|
+
PyObject* gte = build_ast_node("CompareOperation", "{s:N,s:N,s:N}", "left", x, "right", low, "op", gte_op);
|
|
2211
|
+
if (!gte) {
|
|
2212
|
+
Py_DECREF(lte_op);
|
|
2213
|
+
Py_DECREF(high);
|
|
2214
|
+
Py_DECREF(low);
|
|
2215
|
+
Py_DECREF(x);
|
|
2216
|
+
throw PyInternalError();
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
Py_INCREF(x);
|
|
2220
|
+
PyObject* lte = build_ast_node("CompareOperation", "{s:N,s:N,s:N}", "left", x, "right", high, "op", lte_op);
|
|
2221
|
+
if (!lte) {
|
|
2222
|
+
Py_DECREF(gte);
|
|
2223
|
+
Py_DECREF(high);
|
|
2224
|
+
Py_DECREF(low);
|
|
2225
|
+
Py_DECREF(x);
|
|
2226
|
+
throw PyInternalError();
|
|
2227
|
+
}
|
|
2228
|
+
PyObject* and_list = Py_BuildValue("[NN]", gte, lte);
|
|
2229
|
+
if (!and_list) {
|
|
2230
|
+
Py_DECREF(lte);
|
|
2231
|
+
Py_DECREF(gte);
|
|
2232
|
+
Py_DECREF(high);
|
|
2233
|
+
Py_DECREF(low);
|
|
2234
|
+
Py_DECREF(x);
|
|
2235
|
+
throw PyInternalError();
|
|
2236
|
+
}
|
|
2237
|
+
PyObject* result = build_ast_node("And", "{s:N}", "exprs", and_list);
|
|
2238
|
+
if (!result) {
|
|
2239
|
+
Py_DECREF(and_list);
|
|
2240
|
+
Py_DECREF(high);
|
|
2241
|
+
Py_DECREF(low);
|
|
2242
|
+
Py_DECREF(x);
|
|
2243
|
+
throw PyInternalError();
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
Py_DECREF(x);
|
|
2247
|
+
return result;
|
|
2248
|
+
}
|
|
2128
2249
|
|
|
2129
2250
|
VISIT(ColumnExprParens) { return visit(ctx->columnExpr()); }
|
|
2130
2251
|
|
|
@@ -12,27 +12,25 @@ build = [ # Build CPython wheels on Linux and macOS, for x86 as well as ARM
|
|
|
12
12
|
build-frontend = "build" # This is the successor to building with pip
|
|
13
13
|
|
|
14
14
|
[tool.cibuildwheel.macos]
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"arm64",
|
|
18
|
-
]
|
|
19
|
-
before-build = [ # We need to install the libraries for each architecture separately
|
|
20
|
-
"brew uninstall --ignore-dependencies --force boost antlr4-cpp-runtime",
|
|
21
|
-
"brew fetch --force --bottle-tag=${ARCHFLAGS##'-arch '}_ventura boost antlr4-cpp-runtime",
|
|
22
|
-
"brew install $(brew --cache --bottle-tag=${ARCHFLAGS##'-arch '}_ventura boost antlr4-cpp-runtime)",
|
|
15
|
+
before-build = [
|
|
16
|
+
"brew install boost antlr4-cpp-runtime",
|
|
23
17
|
]
|
|
24
18
|
|
|
25
19
|
[tool.cibuildwheel.linux]
|
|
26
20
|
before-all = [
|
|
27
21
|
# manylinux_2_28 is based on AlmaLinux 8, which uses Fedora's dnf as its package manager
|
|
28
22
|
"dnf install -y boost-devel unzip cmake curl uuid pkg-config",
|
|
23
|
+
# update cmake for antlr
|
|
24
|
+
"dnf install -y epel-release",
|
|
25
|
+
"dnf install -y cmake3",
|
|
26
|
+
"cmake3 --version",
|
|
29
27
|
"curl https://www.antlr.org/download/antlr4-cpp-runtime-4.13.1-source.zip --output antlr4-source.zip",
|
|
30
28
|
# Check that the downloaded archive is the expected runtime - a security measure
|
|
31
29
|
"antlr_known_md5sum=\"c875c148991aacd043f733827644a76f\"",
|
|
32
30
|
"antlr_found_ms5sum=\"$(md5sum antlr4-source.zip | cut -d' ' -f1)\"",
|
|
33
31
|
'if [[ "$antlr_known_md5sum" != "$antlr_found_ms5sum" ]]; then exit 64; fi',
|
|
34
32
|
"unzip antlr4-source.zip -d antlr4-source && cd antlr4-source",
|
|
35
|
-
"
|
|
33
|
+
"cmake3 . -DBUILD_TESTING=OFF -DANTLR4_BUILD_TESTS=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5",
|
|
36
34
|
"DESTDIR=out make install",
|
|
37
35
|
"cp -r out/usr/local/include/antlr4-runtime /usr/include/",
|
|
38
36
|
"cp out/usr/local/lib64/libantlr4-runtime.so* /usr/lib64/",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
from setuptools import setup, Extension
|
|
2
1
|
import platform
|
|
3
2
|
|
|
3
|
+
from setuptools import Extension, setup
|
|
4
|
+
|
|
4
5
|
system = platform.system()
|
|
5
6
|
if system not in ("Darwin", "Linux"):
|
|
6
7
|
raise Exception("Only Linux and macOS are supported by hogql_parser")
|
|
@@ -32,7 +33,7 @@ module = Extension(
|
|
|
32
33
|
|
|
33
34
|
setup(
|
|
34
35
|
name="hogql_parser",
|
|
35
|
-
version="1.2.
|
|
36
|
+
version="1.2.8",
|
|
36
37
|
url="https://github.com/PostHog/posthog/tree/master/common/hogql_parser",
|
|
37
38
|
description="HogQL parser for internal PostHog use",
|
|
38
39
|
author="PostHog Inc.",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|