Skip to content

Commit

Permalink
Merge pull request #1911 from taozhi8833998/feat-multiple-set-items-m…
Browse files Browse the repository at this point in the history
…ysql

feat: support multiple set items in mysql
  • Loading branch information
taozhi8833998 authored May 21, 2024
2 parents 57e6346 + a8ea6b9 commit a6b7aa4
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 55 deletions.
5 changes: 4 additions & 1 deletion ast/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,8 @@ export type rename_stmt = AstStatement<rename_stmt_node>;

export interface set_stmt_node {
type: 'set';
expr: assign_stmt & { keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY'; };
keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY' | undefined;
expr: assign_stmt_list;
}

export type set_stmt = AstStatement<set_stmt_node>;
Expand Down Expand Up @@ -1791,6 +1792,8 @@ export interface proc_stmt_t { type: 'proc'; stmt: assign_stmt | return_stmt; va

export type proc_stmt = AstStatement<proc_stmt_t>;

export type assign_stmt_list = assign_stmt[];

export type assign_stmt = { type: 'assign'; left: var_decl | without_prefix_var_decl; symbol: ':=' | '='; right: proc_expr; };

export type return_stmt = { type: 'return'; expr: proc_expr; };
Expand Down
8 changes: 7 additions & 1 deletion pegjs/athena.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -860,13 +860,14 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
a: assign_stmt_list {
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -2519,6 +2520,11 @@ proc_stmt
return { stmt: s, vars: varList };
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s: (KW_ASSIGN / KW_ASSIGIN_EQUAL) __ e:proc_expr {
return {
Expand Down
8 changes: 7 additions & 1 deletion pegjs/bigquery.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ proc_stmt
return { stmt: s, vars: varList };
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s: (KW_ASSIGN / KW_ASSIGIN_EQUAL) __ e:proc_expr {
return {
Expand Down Expand Up @@ -705,13 +710,14 @@ alter_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
a: assign_stmt_list {
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down
8 changes: 7 additions & 1 deletion pegjs/db2.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -921,13 +921,14 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
a: assign_stmt_list {
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -2486,6 +2487,11 @@ proc_stmt
return { stmt: s, vars: varList };
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s: (KW_ASSIGN / KW_ASSIGIN_EQUAL) __ e:proc_expr {
return {
Expand Down
12 changes: 9 additions & 3 deletions pegjs/flinksql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1528,20 +1528,21 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
a: assign_stmt_list {
/*
export interface set_stmt_node {
type: 'set';
expr: assign_stmt & { keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY'; };
keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY' | undefined;
expr: assign_stmt;
}
=> AstStatement<set_stmt_node>
*/
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -3621,6 +3622,11 @@ proc_stmt
return { type: 'proc', stmt: s, vars: varList };
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s: (KW_ASSIGN / KW_ASSIGIN_EQUAL) __ e:proc_expr {
// => { type: 'assign'; left: var_decl | without_prefix_var_decl; symbol: ':=' | '='; right: proc_expr; }
Expand Down
8 changes: 7 additions & 1 deletion pegjs/hive.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -860,13 +860,14 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
a: assign_stmt_list {
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -2487,6 +2488,11 @@ proc_stmt
return { stmt: s, vars: varList };
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s: (KW_ASSIGN / KW_ASSIGIN_EQUAL) __ e:proc_expr {
return {
Expand Down
8 changes: 7 additions & 1 deletion pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,13 +1482,14 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
a: assign_stmt_list {
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -3747,6 +3748,11 @@ proc_stmt
return { stmt: s, vars: varList };
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s: (KW_ASSIGN / KW_ASSIGIN_EQUAL) __ e:proc_expr {
return {
Expand Down
8 changes: 7 additions & 1 deletion pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,13 +1705,14 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
a: assign_stmt_list {
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -4068,6 +4069,11 @@ proc_stmt
return { stmt: s, vars: varList };
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s: (KW_ASSIGN / KW_ASSIGIN_EQUAL) __ e:proc_expr {
return {
Expand Down
16 changes: 7 additions & 9 deletions pegjs/noql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2135,20 +2135,14 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
/*
export interface set_stmt_node {
type: 'set';
expr: assign_stmt & { keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY'; };
}
=> AstStatement<set_stmt_node>
*/
a: assign_stmt_list {
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -5047,6 +5041,11 @@ proc_stmt
return { type: 'proc', stmt: s, vars: varList }
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s: (KW_ASSIGN / KW_ASSIGIN_EQUAL) __ e:proc_expr {
// => { type: 'assign'; left: var_decl | without_prefix_var_decl; symbol: ':=' | '='; right: proc_expr; }
Expand All @@ -5058,7 +5057,6 @@ assign_stmt
};
}


return_stmt
= KW_RETURN __ e:proc_expr {
// => { type: 'return'; expr: proc_expr; }
Expand Down
13 changes: 10 additions & 3 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2267,20 +2267,21 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
a: assign_stmt_list {
/*
export interface set_stmt_node {
type: 'set';
expr: assign_stmt & { keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY'; };
keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY' | undefined;
expr: assign_stmt_list;
}
=> AstStatement<set_stmt_node>
*/
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -5258,6 +5259,12 @@ proc_stmt
return { type: 'proc', stmt: s, vars: varList }
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
// => assign_stmt[]
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s:(KW_ASSIGN / KW_ASSIGIN_EQUAL / KW_TO) __ e:proc_expr {
// => { type: 'assign'; left: var_decl | without_prefix_var_decl; symbol: ':=' | '='; right: proc_expr; }
Expand Down
15 changes: 7 additions & 8 deletions pegjs/redshift.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2152,20 +2152,14 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
/*
export interface set_stmt_node {
type: 'set';
expr: assign_stmt & { keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY'; };
}
=> AstStatement<set_stmt_node>
*/
a: assign_stmt_list {
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -5119,6 +5113,11 @@ proc_stmt
return { type: 'proc', stmt: s, vars: varList }
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s:(KW_ASSIGN / KW_ASSIGIN_EQUAL / KW_TO) __ e:proc_expr {
// => { type: 'assign'; left: var_decl | without_prefix_var_decl; symbol: ':=' | '='; right: proc_expr; }
Expand Down
15 changes: 7 additions & 8 deletions pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,20 +1857,14 @@ rename_stmt
set_stmt
= KW_SET __
kw: (KW_GLOBAL / KW_SESSION / KW_LOCAL / KW_PERSIST / KW_PERSIST_ONLY)? __
a: assign_stmt {
/*
export interface set_stmt_node {
type: 'set';
expr: assign_stmt & { keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY'; };
}
=> AstStatement<set_stmt_node>
*/
a: assign_stmt_list {
a.keyword = kw
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
ast: {
type: 'set',
keyword: kw,
expr: a
}
}
Expand Down Expand Up @@ -4529,6 +4523,11 @@ proc_stmt
return { type: 'proc', stmt: s, vars: varList };
}

assign_stmt_list
= head:assign_stmt tail:(__ COMMA __ assign_stmt)* {
return createList(head, tail);
}

assign_stmt
= va:(var_decl / without_prefix_var_decl) __ s: (KW_ASSIGN / KW_ASSIGIN_EQUAL) __ e:proc_expr {
// => { type: 'assign'; left: var_decl | without_prefix_var_decl; symbol: ':=' | '='; right: proc_expr; }
Expand Down
Loading

0 comments on commit a6b7aa4

Please sign in to comment.