Skip to content

Commit

Permalink
Merge pull request #2055 from taozhi8833998/refactor-as-keyword-snowf…
Browse files Browse the repository at this point in the history
…lake

refactor: support reserved words in as clause in snowflake
  • Loading branch information
taozhi8833998 authored Aug 6, 2024
2 parents aad2039 + d938d3a commit 4b5fe45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
33 changes: 7 additions & 26 deletions pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -519,32 +519,13 @@ create_table_stmt
tp:KW_TEMPORARY? __
KW_TABLE __
ife:if_not_exists_stmt? __
t:table_ref_list __
t:table_name __
c:create_table_definition? __
to:table_options? __
ir: (KW_IGNORE / KW_REPLACE)? __
as: KW_AS? __
qe: union_stmt? {
/*
export type create_table_stmt_node = create_table_stmt_node_simple | create_table_stmt_node_like;
export interface create_table_stmt_node_base {
type: 'create';
keyword: 'table';
temporary?: 'temporary';
replace?: string;
if_not_exists?: 'if not exists';
table: table_ref_list;
}
export interface create_table_stmt_node_simple extends create_table_stmt_node_base{
ignore_replace?: 'ignore' | 'replace';
as?: 'as';
query_expr?: union_stmt_node;
create_definitions?: create_table_definition;
table_options?: table_options;
}
=> AstStatement<create_table_stmt_node>
*/
if(t) t.forEach(tt => tableList.add(`create::${tt.db}::${tt.table}`));
ir:(KW_IGNORE / KW_REPLACE)? __
as:KW_AS? __
qe:union_stmt? {
tableList.add(`create::${t.db}::${t.table}`)
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
Expand All @@ -553,7 +534,7 @@ create_table_stmt
keyword: 'table',
temporary: tp && tp[0].toLowerCase(),
if_not_exists:ife,
table: t,
table: [t],
replace: or && 'or replace',
ignore_replace: ir && ir[0].toLowerCase(),
as: as && as[0].toLowerCase(),
Expand Down Expand Up @@ -2296,7 +2277,7 @@ value_alias_clause
= KW_AS? __ i:alias_ident { /*=>alias_ident*/ return i; }

alias_clause
= KW_AS __ i:alias_ident { /*=>alias_ident*/ return i; }
= KW_AS __ i:ident_without_kw { /*=>alias_ident*/ return i; }
/ KW_AS? __ i:ident { /*=>ident*/ return i; }

into_clause
Expand Down
7 changes: 7 additions & 0 deletions test/snowflake.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@ describe('snowflake', () => {
'CREATE OR REPLACE VIEW "JACEK_DB"."PUBLIC"."VALIDATION_DATA_VIEW" ("ID", "DATA", "LOLZ") AS (SELECT *, "DATA" AS "LOLZ" FROM "VALIDATION_DATA")'
]
},
{
title: 'keyword in alias clause',
sql: [
'select user_id, Limits as Limit from tableName',
'SELECT "user_id", "Limits" AS "Limit" FROM "tableName"',
]
},
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down

0 comments on commit 4b5fe45

Please sign in to comment.