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

feat(hogql): bunch of improvements (HogVM part 1) #16274

Merged
merged 10 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
14 changes: 9 additions & 5 deletions posthog/hogql/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,18 @@ class Alias(Expr):
expr: Expr


class BinaryOperationOp(str, Enum):
class ArithmeticOperationOp(str, Enum):
Add = "+"
Sub = "-"
Mult = "*"
Div = "/"
Mod = "%"


class BinaryOperation(Expr):
class ArithmeticOperation(Expr):
left: Expr
right: Expr
op: BinaryOperationOp
op: ArithmeticOperationOp


class And(Expr):
Expand All @@ -334,17 +334,21 @@ class CompareOperationOp(str, Enum):
Eq = "=="
NotEq = "!="
Gt = ">"
GtE = ">="
GtEq = ">="
Lt = "<"
LtE = "<="
LtEq = "<="
Like = "like"
ILike = "ilike"
NotLike = "not like"
NotILike = "not ilike"
In = "in"
NotIn = "not in"
InCohort = "in cohort"
NotInCohort = "not in cohort"
Regex = "=~"
IRegex = "=~*"
NotRegex = "!~"
NotIRegex = "!~*"


class CompareOperation(Expr):
Expand Down
28 changes: 16 additions & 12 deletions posthog/hogql/database/test/__snapshots__/test_database.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@
"key": "console_error_count",
"type": "integer"
},
{
"key": "size",
"type": "integer"
},
{
"key": "pdi",
"type": "lazy_table",
Expand Down Expand Up @@ -439,6 +443,10 @@
"key": "console_error_count",
"type": "integer"
},
{
"key": "size",
"type": "integer"
},
{
"key": "pdi",
"type": "lazy_table",
Expand Down Expand Up @@ -580,12 +588,6 @@
"key": "version",
"type": "integer"
}
],
"whatever": [
{
"key": "id",
"type": "string"
}
]
}
'
Expand Down Expand Up @@ -921,6 +923,10 @@
"key": "console_error_count",
"type": "integer"
},
{
"key": "size",
"type": "integer"
},
{
"key": "pdi",
"type": "lazy_table",
Expand Down Expand Up @@ -1026,6 +1032,10 @@
"key": "console_error_count",
"type": "integer"
},
{
"key": "size",
"type": "integer"
},
{
"key": "pdi",
"type": "lazy_table",
Expand Down Expand Up @@ -1167,12 +1177,6 @@
"key": "version",
"type": "integer"
}
],
"whatever": [
{
"key": "id",
"type": "string"
}
]
}
'
Expand Down
10 changes: 8 additions & 2 deletions posthog/hogql/grammar/HogQLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,26 @@ DOLLAR: '$';
DOT: '.';
EQ_DOUBLE: '==';
EQ_SINGLE: '=';
GE: '>=';
GT_EQ: '>=';
GT: '>';
HASH: '#';
IREGEX_SINGLE: '~*';
IREGEX_DOUBLE: '=~*';
LBRACE: '{';
LBRACKET: '[';
LE: '<=';
LPAREN: '(';
LT_EQ: '<=';
LT: '<';
NOT_EQ: '!=' | '<>';
NOT_IREGEX: '!~*';
NOT_REGEX: '!~';
PERCENT: '%';
PLUS: '+';
QUERY: '?';
QUOTE_DOUBLE: '"';
QUOTE_SINGLE: '\'';
REGEX_SINGLE: '~';
REGEX_DOUBLE: '=~';
RBRACE: '}';
RBRACKET: ']';
RPAREN: ')';
Expand Down
30 changes: 24 additions & 6 deletions posthog/hogql/grammar/HogQLLexer.interp

Large diffs are not rendered by default.

1,743 changes: 883 additions & 860 deletions posthog/hogql/grammar/HogQLLexer.py

Large diffs are not rendered by default.

86 changes: 49 additions & 37 deletions posthog/hogql/grammar/HogQLLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -210,29 +210,35 @@ DOLLAR=209
DOT=210
EQ_DOUBLE=211
EQ_SINGLE=212
GE=213
GT_EQ=213
GT=214
HASH=215
LBRACE=216
LBRACKET=217
LE=218
LPAREN=219
LT=220
NOT_EQ=221
PERCENT=222
PLUS=223
QUERY=224
QUOTE_DOUBLE=225
QUOTE_SINGLE=226
RBRACE=227
RBRACKET=228
RPAREN=229
SEMICOLON=230
SLASH=231
UNDERSCORE=232
MULTI_LINE_COMMENT=233
SINGLE_LINE_COMMENT=234
WHITESPACE=235
IREGEX_SINGLE=216
IREGEX_DOUBLE=217
LBRACE=218
LBRACKET=219
LPAREN=220
LT_EQ=221
LT=222
NOT_EQ=223
NOT_IREGEX=224
NOT_REGEX=225
PERCENT=226
PLUS=227
QUERY=228
QUOTE_DOUBLE=229
QUOTE_SINGLE=230
REGEX_SINGLE=231
REGEX_DOUBLE=232
RBRACE=233
RBRACKET=234
RPAREN=235
SEMICOLON=236
SLASH=237
UNDERSCORE=238
MULTI_LINE_COMMENT=239
SINGLE_LINE_COMMENT=240
WHITESPACE=241
'false'=191
'true'=192
'->'=201
Expand All @@ -250,19 +256,25 @@ WHITESPACE=235
'>='=213
'>'=214
'#'=215
'{'=216
'['=217
'<='=218
'('=219
'<'=220
'%'=222
'+'=223
'?'=224
'"'=225
'\''=226
'}'=227
']'=228
')'=229
';'=230
'/'=231
'_'=232
'~*'=216
'=~*'=217
'{'=218
'['=219
'('=220
'<='=221
'<'=222
'!~*'=224
'!~'=225
'%'=226
'+'=227
'?'=228
'"'=229
'\''=230
'~'=231
'=~'=232
'}'=233
']'=234
')'=235
';'=236
'/'=237
'_'=238
42 changes: 24 additions & 18 deletions posthog/hogql/grammar/HogQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,30 @@ columnExpr
| columnExpr DOT DECIMAL_LITERAL # ColumnExprTupleAccess
| columnExpr DOT identifier # ColumnExprPropertyAccess
| DASH columnExpr # ColumnExprNegate
| left=columnExpr ( operator=ASTERISK // multiply
| operator=SLASH // divide
| operator=PERCENT // modulo
) right=columnExpr # ColumnExprPrecedence1
| left=columnExpr ( operator=PLUS // plus
| operator=DASH // minus
| operator=CONCAT // concat
) right=columnExpr # ColumnExprPrecedence2
| left=columnExpr ( operator=EQ_DOUBLE // equals
| operator=EQ_SINGLE // equals
| operator=NOT_EQ // notEquals
| operator=LE // lessOrEquals
| operator=GE // greaterOrEquals
| operator=LT // less
| operator=GT // greater
| operator=NOT? IN COHORT? // in, notIn; cohort()
| operator=NOT? (LIKE | ILIKE) // like, notLike, ilike, notILike
) right=columnExpr # ColumnExprPrecedence3
| left=columnExpr ( operator=ASTERISK // *
| operator=SLASH // /
| operator=PERCENT // %
) right=columnExpr # ColumnExprPrecedence1
| left=columnExpr ( operator=PLUS // +
| operator=DASH // -
| operator=CONCAT // ||
) right=columnExpr # ColumnExprPrecedence2
| left=columnExpr ( operator=EQ_DOUBLE // =
| operator=EQ_SINGLE // ==
| operator=NOT_EQ // !=
| operator=LT_EQ // <=
| operator=LT // <
| operator=GT_EQ // >=
| operator=GT // >
| operator=NOT? IN COHORT? // in, not in; in cohort; not in cohort
| operator=NOT? (LIKE | ILIKE) // like, not like, ilike, not ilike
| operator=REGEX_SINGLE // ~
| operator=REGEX_DOUBLE // =~
| operator=NOT_REGEX // !~
| operator=IREGEX_SINGLE // ~*
| operator=IREGEX_DOUBLE // =~*
| operator=NOT_IREGEX // !~*
) right=columnExpr # ColumnExprPrecedence3
| columnExpr IS NOT? NULL_SQL # ColumnExprIsNull
| NOT columnExpr # ColumnExprNot
| columnExpr AND columnExpr # ColumnExprAnd
Expand Down
20 changes: 16 additions & 4 deletions posthog/hogql/grammar/HogQLParser.interp

Large diffs are not rendered by default.

Loading