Skip to content

Commit

Permalink
Merge pull request #1994 from taozhi8833998/fix-collate-mysql
Browse files Browse the repository at this point in the history
fix: collate in mysql
  • Loading branch information
taozhi8833998 authored Jul 10, 2024
2 parents c609d7f + 1da287f commit 63673f2
Show file tree
Hide file tree
Showing 32 changed files with 366 additions and 115 deletions.
20 changes: 18 additions & 2 deletions pegjs/athena.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,28 @@ create_column_definition
}

collate_expr
= KW_COLLATE __ ca:ident_name {
= KW_COLLATE __ ca:ident_name __ s:KW_ASSIGIN_EQUAL __ t:ident {
return {
type: 'collate',
value: ca,
keyword: 'collate',
collate: {
name: ca,
symbol: s,
value: t
}
}
}
/ KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident {
return {
type: 'collate',
keyword: 'collate',
collate: {
name: ca,
symbol: s,
}
}
}

column_format
= k:'COLUMN_FORMAT'i __ f:('FIXED'i / 'DYNAMIC'i / 'DEFAULT'i) {
return {
Expand Down
20 changes: 17 additions & 3 deletions pegjs/bigquery.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,11 +1159,25 @@ keyword_comment
}

collate_expr
= KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident_name {
= KW_COLLATE __ ca:ident_name __ s:KW_ASSIGIN_EQUAL __ t:ident {
return {
type: 'collate',
symbol: s,
value: ca,
keyword: 'collate',
collate: {
name: ca,
symbol: s,
value: t
}
}
}
/ KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident {
return {
type: 'collate',
keyword: 'collate',
collate: {
name: ca,
symbol: s,
}
}
}

Expand Down
22 changes: 18 additions & 4 deletions pegjs/db2.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,25 @@ create_column_definition
}

collate_expr
= KW_COLLATE __ ca:ident_name {
= KW_COLLATE __ ca:ident_name __ s:KW_ASSIGIN_EQUAL __ t:ident {
return {
type: 'collate',
value: ca,
keyword: 'collate',
collate: {
name: ca,
symbol: s,
value: t
}
}
}
/ KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident {
return {
type: 'collate',
keyword: 'collate',
collate: {
name: ca,
symbol: s,
}
}
}
column_format
Expand Down Expand Up @@ -1811,14 +1826,13 @@ unary_operator
= '!' / '-' / '+' / '~'

column_ref
= tbl:(ident __ DOT __)? col:column __ a:((DOUBLE_ARROW / SINGLE_ARROW) __ (literal_string / literal_numeric))+ __ ca:collate_expr? {
= tbl:(ident __ DOT __)? col:column __ a:((DOUBLE_ARROW / SINGLE_ARROW) __ (literal_string / literal_numeric))+ {
const tableName = tbl && tbl[0] || null
columnList.add(`select::${tableName}::${col}`);
return {
type: 'column_ref',
table: tableName,
column: col,
collate: ca,
arrows: a.map(item => item[0]),
properties: a.map(item => item[2])
};
Expand Down
20 changes: 17 additions & 3 deletions pegjs/flinksql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -892,11 +892,25 @@ create_column_definition


collate_expr
= KW_COLLATE __ ca:ident {
// => { type: 'collate'; value: ident; }
= KW_COLLATE __ ca:ident_name __ s:KW_ASSIGIN_EQUAL __ t:ident {
return {
type: 'collate',
value: ca,
keyword: 'collate',
collate: {
name: ca,
symbol: s,
value: t
}
}
}
/ KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident {
return {
type: 'collate',
keyword: 'collate',
collate: {
name: ca,
symbol: s,
}
}
}
column_format
Expand Down
19 changes: 17 additions & 2 deletions pegjs/hive.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,25 @@ create_column_definition
}

collate_expr
= KW_COLLATE __ ca:ident_name {
= KW_COLLATE __ ca:ident_name __ s:KW_ASSIGIN_EQUAL __ t:ident {
return {
type: 'collate',
value: ca,
keyword: 'collate',
collate: {
name: ca,
symbol: s,
value: t
}
}
}
/ KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident {
return {
type: 'collate',
keyword: 'collate',
collate: {
name: ca,
symbol: s,
}
}
}
column_format
Expand Down
34 changes: 23 additions & 11 deletions pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,25 @@ create_trigger_stmt
}

collate_expr
= KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident_name {
= KW_COLLATE __ ca:ident_name __ s:KW_ASSIGIN_EQUAL __ t:ident {
return {
type: 'collate',
symbol: s,
value: ca,
keyword: 'collate',
collate: {
name: ca,
symbol: s,
value: t
}
}
}
/ KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident {
return {
type: 'collate',
keyword: 'collate',
collate: {
name: ca,
symbol: s,
}
}
}

Expand Down Expand Up @@ -1880,6 +1894,7 @@ select_stmt_nake
g:group_by_clause? __
h:having_clause? __
o:order_by_clause? __
ce:collate_expr? __
l:limit_clause? __
lr: locking_read? __
win:window_clause? __
Expand All @@ -1903,6 +1918,7 @@ select_stmt_nake
groupby: g,
having: h,
orderby: o,
collate: ce,
limit: l,
locking_read: lr && lr,
window: win,
Expand Down Expand Up @@ -2205,8 +2221,7 @@ on_clause
= KW_ON __ e:or_and_expr { return e; }

where_clause
= KW_WHERE __ e:or_and_where_expr __ ca:collate_expr? {
if (ca) e.suffix = [ca]
= KW_WHERE __ e:or_and_where_expr {
return e;
}

Expand Down Expand Up @@ -2719,9 +2734,8 @@ in_op
/ KW_IN

like_op_right
= op:like_op __ right:(literal / param / comparison_expr ) __ ca:(__ collate_expr)? __ es:escape_op? {
= op:like_op __ right:(literal / param / comparison_expr ) __ es:escape_op? {
if (es) right.escape = es
if (ca) right.suffix = { collate: ca[1] }
return { op: op, right: right };
}

Expand Down Expand Up @@ -3202,12 +3216,11 @@ trim_func_clause

func_call
= extract_func / trim_func_clause
/ 'convert'i __ LPAREN __ l:convert_args __ RPAREN __ ca:collate_expr? {
/ 'convert'i __ LPAREN __ l:convert_args __ RPAREN {
return {
type: 'function',
name: { name: [{ type: 'origin', value: 'convert' }] },
args: l,
collate: ca,
};
}
/ name:scalar_func __ LPAREN __ l:expr_list? __ RPAREN __ bc:over_partition? {
Expand Down Expand Up @@ -3247,7 +3260,7 @@ scalar_func
/ KW_SYSTEM_USER

cast_expr
= c:KW_CAST __ LPAREN __ e:expr __ KW_AS __ ch:character_string_type __ cs:create_option_character_set_kw __ v:ident_without_kw_type __ RPAREN __ ca:collate_expr? {
= c:KW_CAST __ LPAREN __ e:expr __ KW_AS __ ch:character_string_type __ cs:create_option_character_set_kw __ v:ident_without_kw_type __ RPAREN {
const { dataType, length } = ch
let dataTypeStr = dataType
if (length !== undefined) dataTypeStr = `${dataTypeStr}(${length})`
Expand All @@ -3260,7 +3273,6 @@ cast_expr
dataType: dataTypeStr,
suffix: [{ type: 'origin', value: cs }, v],
},
collate: ca,
};
}
/ c:KW_CAST __ LPAREN __ e:expr __ KW_AS __ t:data_type __ RPAREN {
Expand Down
40 changes: 26 additions & 14 deletions pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,13 +1010,28 @@ create_trigger_stmt
}

collate_expr
= KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident_name {
= KW_COLLATE __ ca:ident_name __ s:KW_ASSIGIN_EQUAL __ t:ident {
return {
type: 'collate',
symbol: s,
value: ca,
keyword: 'collate',
collate: {
name: ca,
symbol: s,
value: t
}
}
}
/ KW_COLLATE __ s:KW_ASSIGIN_EQUAL? __ ca:ident {
return {
type: 'collate',
keyword: 'collate',
collate: {
name: ca,
symbol: s,
}
}
}

column_format
= k:'COLUMN_FORMAT'i __ f:('FIXED'i / 'DYNAMIC'i / 'DEFAULT'i) {
return {
Expand Down Expand Up @@ -2130,8 +2145,9 @@ select_stmt_nake
g:group_by_clause? __
h:having_clause? __
o:order_by_clause? __
ce:collate_expr? __
l:limit_clause? __
lr: locking_read? __
lr:locking_read? __
win:window_clause? __
li:into_clause? {
if ((ci && fi) || (ci && li) || (fi && li) || (ci && fi && li)) {
Expand All @@ -2156,6 +2172,7 @@ select_stmt_nake
limit: l,
locking_read: lr && lr,
window: win,
collate: ce,
...getLocationObject(),
};
}
Expand Down Expand Up @@ -2458,8 +2475,7 @@ on_clause
= KW_ON __ e:or_and_expr { return e; }

where_clause
= KW_WHERE __ e:or_and_where_expr __ ca:collate_expr? {
if (ca) e.suffix = [ca]
= KW_WHERE __ e:or_and_where_expr {
return e;
}

Expand Down Expand Up @@ -2992,9 +3008,8 @@ regexp_op_right
}

like_op_right
= op:like_op __ right:(literal / param / comparison_expr ) __ ca:(__ collate_expr)? __ es:escape_op? {
= op:like_op __ right:(literal / param / comparison_expr ) __ es:escape_op? {
if (es) right.escape = es
if (ca) right.suffix = { collate: ca[1] }
return { op: op, right: right };
}

Expand Down Expand Up @@ -3062,14 +3077,13 @@ primary
}

column_ref
= tbl:(ident __ DOT __)? col:column __ a:((DOUBLE_ARROW / SINGLE_ARROW) __ (literal_string / literal_numeric))+ __ ca:collate_expr? {
= tbl:(ident __ DOT __)? col:column __ a:((DOUBLE_ARROW / SINGLE_ARROW) __ literal)+ {
const tableName = tbl && tbl[0] || null
columnList.add(`select::${tableName}::${col}`);
return {
type: 'column_ref',
table: tableName,
column: col,
collate: ca,
arrows: a.map(item => item[0]),
properties: a.map(item => item[2]),
...getLocationObject(),
Expand Down Expand Up @@ -3487,12 +3501,11 @@ trim_func_clause

func_call
= extract_func / trim_func_clause
/ 'convert'i __ LPAREN __ l:convert_args __ RPAREN __ ca:collate_expr? {
/ 'convert'i __ LPAREN __ l:convert_args __ RPAREN {
return {
type: 'function',
name: { name: [{ type: 'origin', value: 'convert' }] },
args: l,
collate: ca,
};
}
/ name:scalar_func __ LPAREN __ l:expr_list? __ RPAREN __ bc:over_partition? {
Expand Down Expand Up @@ -3532,7 +3545,7 @@ scalar_func
/ KW_SYSTEM_USER

cast_expr
= c:KW_CAST __ LPAREN __ e:expr __ KW_AS __ ch:character_string_type __ cs:create_option_character_set_kw __ v:ident_without_kw_type __ RPAREN __ ca:collate_expr? {
= c:KW_CAST __ LPAREN __ e:expr __ KW_AS __ ch:character_string_type __ cs:create_option_character_set_kw __ v:ident_without_kw_type __ RPAREN {
const { dataType, length } = ch
let dataTypeStr = dataType
if (length !== undefined) dataTypeStr = `${dataTypeStr}(${length})`
Expand All @@ -3545,7 +3558,6 @@ cast_expr
dataType: dataTypeStr,
suffix: [{ type: 'origin', value: cs }, v],
},
collate: ca,
};
}
/ c:KW_CAST __ LPAREN __ e:expr __ KW_AS __ t:data_type __ RPAREN {
Expand Down
Loading

0 comments on commit 63673f2

Please sign in to comment.