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(hog): trailing commas #23104

Merged
merged 5 commits into from
Jun 20, 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
2,675 changes: 1,405 additions & 1,270 deletions hogql_parser/HogQLParser.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hogql_parser/HogQLParser.interp

Large diffs are not rendered by default.

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.15",
version="1.0.16",
url="https://github.com/PostHog/posthog/tree/master/hogql_parser",
author="PostHog Inc.",
author_email="[email protected]",
Expand Down
3 changes: 2 additions & 1 deletion hogvm/__tests__/__snapshots__/tuples.hoge
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
["_h", 2, "tuple", 0, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 3, 2, "print", 1, 35, 33, 1, 32, "2", 33, 3, 44, 3, 2,
["_h", 2, "tuple", 0, 2, "print", 1, 35, 33, 1, 44, 1, 2, "print", 1, 35, 33, 1, 33, 2, 44, 2, 2, "print", 1, 35, 33, 1,
33, 2, 44, 2, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 3, 2, "print", 1, 35, 33, 1, 32, "2", 33, 3, 44, 3, 2,
"print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 2, 33, 4, 44, 3, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2,
33, 5, 44, 3, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 3, 36, 0, 33, 1, 45, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3,
33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 1, 45, 33, 1, 45, 33, 1, 45, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44,
Expand Down
3 changes: 3 additions & 0 deletions hogvm/__tests__/__snapshots__/tuples.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
tuple()
tuple(1)
(1, 2)
(1, 2)
(1, 2, 3)
(1, '2', 3)
(1, (2, 3), 4)
Expand Down
10 changes: 5 additions & 5 deletions hogvm/__tests__/arrays.hog
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
print([])
print([1, 2, 3])
print([1, '2', 3])
print([1, '2', 3, ])
print([1, [2, 3], 4])
print([1, [2, [3, 4]], 5])

let a := [1, 2, 3]
print(a[1])
print([1, 2, 3][1])
print([1, [2, [3, 4]], 5][1][1][1])
print(a[1], )
print([1, 2, 3][1], )
print([1, [2, [3, 4], ], 5][1][1][1])
print([1, [2, [3, 4]], 5][1][1][1] + 1)
print([1, [2, [3, 4]], 5].1.1.1)
print([1, [2, [3, 4, ], ], 5, ].1.1.1)
4 changes: 2 additions & 2 deletions hogvm/__tests__/dicts.hog
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ print({key: 'value'})
let key := 3
print({key: 'value'})

print({'key': 'value'}.key)
print({'key': 'value', }.key)
print({'key': 'value'}['key'])
print({'key': {'otherKey': 'value'}}.key.otherKey)
print({'key': {'otherKey': 'value'}}['key'].otherKey)
print({'key': {'otherKey': 'value', } , }['key'].otherKey)
5 changes: 4 additions & 1 deletion hogvm/__tests__/tuples.hog
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
print(tuple())
print((1,))
print((1, 2))
print((1, 2,))
print((1, 2, 3))
print((1, '2', 3))
print((1, (2, 3), 4))
print((1, (2, (3, 4)), 5))
let a := (1, 2, 3)
print(a[1])
print((1, (2, (3, 4)), 5)[1][1][1])
print((1, (2, (3, 4)), 5).1.1.1)
print((1, (2, (3, 4, ), ), 5, ).1.1.1)
print((1, (2, (3, 4)), 5)[1][1][1] + 1)
2 changes: 1 addition & 1 deletion posthog/api/test/batch_exports/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def test_create_batch_export_with_custom_schema(client: HttpClient):
"invalid_query",
[
"SELECT",
"SELECT event, FROM events",
"SELECT event,, FROM events",
"SELECT unknown_field FROM events",
"SELECT event, persons.id FROM events LEFT JOIN persons ON events.person_id = persons.id",
"SELECT event FROM events UNION ALL SELECT event FROM events",
Expand Down
22 changes: 11 additions & 11 deletions posthog/hogql/grammar/HogQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ declaration: varDecl | statement ;
expression: columnExpr;

varDecl: LET identifier ( COLON EQ_SINGLE expression )? ;
identifierList: identifier (COMMA identifier)*;
identifierList: identifier (COMMA identifier)* COMMA?;

statement : returnStmt
| ifStmt
Expand All @@ -39,7 +39,7 @@ emptyStmt : SEMICOLON ;
block : LBRACE declaration* RBRACE ;

kvPair: expression ':' expression ;
kvPairList: kvPair (COMMA kvPair)* ;
kvPairList: kvPair (COMMA kvPair)* COMMA?;


// SELECT statement
Expand Down Expand Up @@ -128,12 +128,12 @@ winFrameBound: (CURRENT ROW | UNBOUNDED PRECEDING | UNBOUNDED FOLLOWING | number
expr: columnExpr EOF;
columnTypeExpr
: identifier # ColumnTypeExprSimple // UInt64
| identifier LPAREN identifier columnTypeExpr (COMMA identifier columnTypeExpr)* RPAREN # ColumnTypeExprNested // Nested
| identifier LPAREN enumValue (COMMA enumValue)* RPAREN # ColumnTypeExprEnum // Enum
| identifier LPAREN columnTypeExpr (COMMA columnTypeExpr)* RPAREN # ColumnTypeExprComplex // Array, Tuple
| identifier LPAREN identifier columnTypeExpr (COMMA identifier columnTypeExpr)* COMMA? RPAREN # ColumnTypeExprNested // Nested
| identifier LPAREN enumValue (COMMA enumValue)* COMMA? RPAREN # ColumnTypeExprEnum // Enum
| identifier LPAREN columnTypeExpr (COMMA columnTypeExpr)* COMMA? RPAREN # ColumnTypeExprComplex // Array, Tuple
| identifier LPAREN columnExprList? RPAREN # ColumnTypeExprParam // FixedString(N)
;
columnExprList: columnExpr (COMMA columnExpr)*;
columnExprList: columnExpr (COMMA columnExpr)* COMMA?;
columnExpr
: CASE caseExpr=columnExpr? (WHEN whenExpr=columnExpr THEN thenExpr=columnExpr)+ (ELSE elseExpr=columnExpr)? END # ColumnExprCase
| CAST LPAREN columnExpr AS columnTypeExpr RPAREN # ColumnExprCast
Expand Down Expand Up @@ -198,11 +198,11 @@ columnExpr
| columnIdentifier # ColumnExprIdentifier
;

columnArgList: columnArgExpr (COMMA columnArgExpr)*;
columnArgList: columnArgExpr (COMMA columnArgExpr)* COMMA?;
columnArgExpr: columnLambdaExpr | columnExpr;
columnLambdaExpr:
( LPAREN identifier (COMMA identifier)* RPAREN
| identifier (COMMA identifier)*
( LPAREN identifier (COMMA identifier)* COMMA? RPAREN
| identifier (COMMA identifier)* COMMA?
)
ARROW columnExpr
;
Expand All @@ -218,7 +218,7 @@ hogqlxTagAttribute
| identifier
;

withExprList: withExpr (COMMA withExpr)*;
withExprList: withExpr (COMMA withExpr)* COMMA?;
withExpr
: identifier AS LPAREN selectUnionStmt RPAREN # WithExprSubquery
// NOTE: asterisk and subquery goes before |columnExpr| so that we can mark them as multi-column expressions.
Expand All @@ -242,7 +242,7 @@ tableExpr
;
tableFunctionExpr: identifier LPAREN tableArgList? RPAREN;
tableIdentifier: (databaseIdentifier DOT)? identifier;
tableArgList: columnExpr (COMMA columnExpr)*;
tableArgList: columnExpr (COMMA columnExpr)* COMMA?;

// Databases

Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/grammar/HogQLParser.interp

Large diffs are not rendered by default.

Loading
Loading