Skip to content

Commit

Permalink
fix(engine/sqlite): fix table_alias rules (#2465)
Browse files Browse the repository at this point in the history
* fix(engine/sqlite): fix table_alias rules

changed rules to conform to fallback directive behavior

fix #2271

* test: update endtoend

* Update parser code

---------

Co-authored-by: Kyle Conroy <[email protected]>
  • Loading branch information
orisano and kyleconroy authored Jul 24, 2023
1 parent 5ffe722 commit c236b74
Show file tree
Hide file tree
Showing 8 changed files with 2,878 additions and 2,429 deletions.
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/join_left/sqlite/go/query.sql.go

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

7 changes: 7 additions & 0 deletions internal/endtoend/testdata/join_left/sqlite/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ FROM users_2 AS u
LEFT JOIN media AS m
ON u.user_avatar_id = m.media_id
WHERE u.user_id != @user_id;

-- name: GetSuggestedUsersByID2 :many
SELECT users_2.user_id
FROM users_2
LEFT JOIN media AS m
ON user_avatar_id = m.media_id
WHERE user_id != @user_id;
4 changes: 4 additions & 0 deletions internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,10 @@ func (c *cc) convertTablesOrSubquery(n []parser.ITable_or_subqueryContext) []ast
alias := from.Table_alias().GetText()
rv.Alias = &ast.Alias{Aliasname: &alias}
}
if from.Table_alias_fallback() != nil {
alias := identifier(from.Table_alias_fallback().GetText())
rv.Alias = &ast.Alias{Aliasname: &alias}
}

tables = append(tables, rv)
} else if from.Table_function_name() != nil {
Expand Down
22 changes: 10 additions & 12 deletions internal/engine/sqlite/parser/SQLiteParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,15 @@ compound_select_stmt:
)+ order_by_stmt? limit_stmt?
;

table_or_subquery: (
(schema_name DOT)? table_name (AS_? table_alias)? (
INDEXED_ BY_ index_name
| NOT_ INDEXED_
)?
)
| (schema_name DOT)? table_function_name OPEN_PAR expr (COMMA expr)* CLOSE_PAR (
AS_? table_alias
)?
table_or_subquery:
(schema_name DOT)? table_name (AS_? table_alias)? (INDEXED_ BY_ index_name | NOT_ INDEXED_)?
| (schema_name DOT)? table_function_name OPEN_PAR expr (COMMA expr)* CLOSE_PAR (AS_? table_alias)?
| OPEN_PAR (table_or_subquery (COMMA table_or_subquery)* | join_clause) CLOSE_PAR
| OPEN_PAR select_stmt CLOSE_PAR (AS_? table_alias)?
| (schema_name DOT)? table_name (AS_? table_alias_fallback)? (INDEXED_ BY_ index_name | NOT_ INDEXED_)?
| (schema_name DOT)? table_function_name OPEN_PAR expr (COMMA expr)* CLOSE_PAR (AS_? table_alias_fallback)?
| OPEN_PAR (table_or_subquery (COMMA table_or_subquery)* | join_clause) CLOSE_PAR
| OPEN_PAR select_stmt CLOSE_PAR (AS_? table_alias_fallback)?
;

result_column:
Expand Down Expand Up @@ -880,9 +878,9 @@ savepoint_name:
any_name
;

table_alias:
any_name
;
table_alias: IDENTIFIER | STRING_LITERAL;

table_alias_fallback: any_name;

transaction_name:
any_name
Expand Down
3 changes: 2 additions & 1 deletion internal/engine/sqlite/parser/SQLiteParser.interp

Large diffs are not rendered by default.

5,228 changes: 2,812 additions & 2,416 deletions internal/engine/sqlite/parser/sqlite_parser.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions internal/engine/sqlite/parser/sqliteparser_base_listener.go

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

6 changes: 6 additions & 0 deletions internal/engine/sqlite/parser/sqliteparser_listener.go

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

0 comments on commit c236b74

Please sign in to comment.