Skip to content

Commit

Permalink
fix(engine/sqlite): fix grammer to avoid missing join_constraint (#2732)
Browse files Browse the repository at this point in the history
close #2729

ANTLR's API has difficulty handling the case where there is no join_constraint
corresponding to join_operator in join_clause, so an empty join_constraint is accepted.

It is defined as such in the sqlite documentation.
https://www.sqlite.org/syntax/join-clause.html
https://www.sqlite.org/syntax/join-constraint.html
  • Loading branch information
orisano committed Sep 14, 2023
1 parent 79cb8b5 commit e465d0b
Show file tree
Hide file tree
Showing 13 changed files with 1,328 additions and 1,141 deletions.
35 changes: 35 additions & 0 deletions internal/endtoend/testdata/join_where_clause/mysql/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion internal/endtoend/testdata/join_where_clause/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ WHERE owner = ?;
SELECT foo.*
FROM foo
JOIN bar ON bar.id = ?
WHERE owner = ?;
WHERE owner = ?;

-- name: JoinNoConstraints :many
SELECT foo.*
FROM foo
CROSS JOIN bar
WHERE bar.id = ? AND owner = ?;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ WHERE owner = $1;
SELECT foo.*
FROM foo
JOIN bar ON bar.id = $2
WHERE owner = $1;
WHERE owner = $1;

-- name: JoinNoConstraints :many
SELECT foo.*
FROM foo
CROSS JOIN bar
WHERE bar.id = $2 AND owner = $1;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ WHERE owner = $1;
SELECT foo.*
FROM foo
JOIN bar ON bar.id = $2
WHERE owner = $1;
WHERE owner = $1;

-- name: JoinNoConstraints :many
SELECT foo.*
FROM foo
CROSS JOIN bar
WHERE bar.id = $2 AND owner = $1;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ WHERE owner = $1;
SELECT foo.*
FROM foo
JOIN bar ON bar.id = $2
WHERE owner = $1;
WHERE owner = $1;

-- name: JoinNoConstraints :many
SELECT foo.*
FROM foo
CROSS JOIN bar
WHERE bar.id = $2 AND owner = $1;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ WHERE owner = ?;
SELECT foo.*
FROM foo
JOIN bar ON bar.id = ?
WHERE owner = ?;
WHERE owner = ?;

-- name: JoinNoConstraints :many
SELECT foo.*
FROM foo
CROSS JOIN bar
WHERE bar.id = ? AND owner = ?;
6 changes: 3 additions & 3 deletions internal/engine/sqlite/parser/SQLiteParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ select_stmt:
;

join_clause:
table_or_subquery (join_operator table_or_subquery join_constraint?)*
table_or_subquery (join_operator table_or_subquery join_constraint)*
;

select_core:
Expand Down Expand Up @@ -454,8 +454,8 @@ join_operator:
;

join_constraint:
ON_ expr
| USING_ OPEN_PAR column_name ( COMMA column_name)* CLOSE_PAR
(ON_ expr
| USING_ OPEN_PAR column_name ( COMMA column_name)* CLOSE_PAR)?
;

compound_operator:
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/sqlite/parser/SQLiteParser.interp

Large diffs are not rendered by default.

0 comments on commit e465d0b

Please sign in to comment.