Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hogql): remove unsupported extract(..from..) #21157

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,312 changes: 628 additions & 684 deletions hogql_parser/HogQLParser.cpp

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions hogql_parser/HogQLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -988,20 +988,6 @@ class HogQLParser : public antlr4::Parser {
virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
};

class ColumnExprExtractContext : public ColumnExprContext {
public:
ColumnExprExtractContext(ColumnExprContext *ctx);

antlr4::tree::TerminalNode *EXTRACT();
antlr4::tree::TerminalNode *LPAREN();
IntervalContext *interval();
antlr4::tree::TerminalNode *FROM();
ColumnExprContext *columnExpr();
antlr4::tree::TerminalNode *RPAREN();

virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
};

class ColumnExprNegateContext : public ColumnExprContext {
public:
ColumnExprNegateContext(ColumnExprContext *ctx);
Expand Down
2 changes: 1 addition & 1 deletion hogql_parser/HogQLParser.interp

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions hogql_parser/HogQLParserBaseVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ class HogQLParserBaseVisitor : public HogQLParserVisitor {
return visitChildren(ctx);
}

virtual std::any visitColumnExprExtract(HogQLParser::ColumnExprExtractContext *ctx) override {
return visitChildren(ctx);
}

virtual std::any visitColumnExprNegate(HogQLParser::ColumnExprNegateContext *ctx) override {
return visitChildren(ctx);
}
Expand Down
2 changes: 0 additions & 2 deletions hogql_parser/HogQLParserVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ class HogQLParserVisitor : public antlr4::tree::AbstractParseTreeVisitor {

virtual std::any visitColumnExprAlias(HogQLParser::ColumnExprAliasContext *context) = 0;

virtual std::any visitColumnExprExtract(HogQLParser::ColumnExprExtractContext *context) = 0;

virtual std::any visitColumnExprNegate(HogQLParser::ColumnExprNegateContext *context) = 0;

virtual std::any visitColumnExprSubquery(HogQLParser::ColumnExprSubqueryContext *context) = 0;
Expand Down
2 changes: 0 additions & 2 deletions hogql_parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,6 @@ class HogQLParseTreeConverter : public HogQLParserBaseVisitor {
RETURN_NEW_AST_NODE("Alias", "{s:N,s:s#}", "expr", expr, "alias", alias.data(), alias.size());
}

VISIT_UNSUPPORTED(ColumnExprExtract)

VISIT(ColumnExprNegate) {
PyObject* left = build_ast_node("Constant", "{s:i}", "value", 0);
if (!left) throw PyInternalException();
Expand Down
2 changes: 1 addition & 1 deletion hogql_parser/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

setup(
name="hogql_parser",
version="1.0.3",
version="1.0.4",
url="https://github.com/PostHog/posthog/tree/master/hogql_parser",
author="PostHog Inc.",
author_email="[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/grammar/HogQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ columnExpr
: CASE caseExpr=columnExpr? (WHEN whenExpr=columnExpr THEN thenExpr=columnExpr)+ (ELSE elseExpr=columnExpr)? END # ColumnExprCase
| CAST LPAREN columnExpr AS columnTypeExpr RPAREN # ColumnExprCast
| DATE STRING_LITERAL # ColumnExprDate
| EXTRACT LPAREN interval FROM columnExpr RPAREN # ColumnExprExtract
// | EXTRACT LPAREN interval FROM columnExpr RPAREN # ColumnExprExtract // Interferes with a function call
| INTERVAL columnExpr interval # ColumnExprInterval
| SUBSTRING LPAREN columnExpr FROM columnExpr (FOR columnExpr)? RPAREN # ColumnExprSubstring
| TIMESTAMP STRING_LITERAL # ColumnExprTimestamp
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/grammar/HogQLParser.interp

Large diffs are not rendered by default.

1,352 changes: 652 additions & 700 deletions posthog/hogql/grammar/HogQLParser.py

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions posthog/hogql/grammar/HogQLParserVisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,6 @@ def visitColumnExprAlias(self, ctx:HogQLParser.ColumnExprAliasContext):
return self.visitChildren(ctx)


# Visit a parse tree produced by HogQLParser#ColumnExprExtract.
def visitColumnExprExtract(self, ctx:HogQLParser.ColumnExprExtractContext):
return self.visitChildren(ctx)


# Visit a parse tree produced by HogQLParser#ColumnExprNegate.
def visitColumnExprNegate(self, ctx:HogQLParser.ColumnExprNegateContext):
return self.visitChildren(ctx)
Expand Down
3 changes: 0 additions & 3 deletions posthog/hogql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,6 @@ def visitColumnExprAlias(self, ctx: HogQLParser.ColumnExprAliasContext):

return ast.Alias(expr=expr, alias=alias)

def visitColumnExprExtract(self, ctx: HogQLParser.ColumnExprExtractContext):
raise NotImplementedException(f"Unsupported node: ColumnExprExtract")

def visitColumnExprNegate(self, ctx: HogQLParser.ColumnExprNegateContext):
return ast.ArithmeticOperation(
op=ast.ArithmeticOperationOp.Sub,
Expand Down
13 changes: 13 additions & 0 deletions posthog/hogql/test/_test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,4 +1594,17 @@ def test_visit_hogqlx_tag_source(self):
],
)

def test_select_extract_as_function(self):
node = self._select("select extract('string', 'other string') from events")

assert node == ast.SelectQuery(
select=[
ast.Call(
name="extract",
args=[ast.Constant(value="string"), ast.Constant(value="other string")],
)
],
select_from=ast.JoinExpr(table=ast.Field(chain=["events"])),
)

return TestParser
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ phonenumberslite==8.13.6
openai==1.10.0
tiktoken==0.6.0
nh3==0.2.14
hogql-parser==1.0.3
hogql-parser==1.0.4
urllib3[secure,socks]==1.26.18
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ h11==0.13.0
# wsproto
hexbytes==1.0.0
# via dlt
hogql-parser==1.0.3
hogql-parser==1.0.4
# via -r requirements.in
httpcore==1.0.2
# via httpx
Expand Down
Loading