Skip to content

Commit

Permalink
Merge pull request #2106 from taozhi8833998/fix-convert-chinese-trans…
Browse files Browse the repository at this point in the history
…actsql

fix: convert function and as chinese chars in transactsql
  • Loading branch information
taozhi8833998 authored Sep 8, 2024
2 parents 305de82 + cc75c88 commit 3a9f18b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pegjs/db2.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1936,9 +1936,9 @@ column_name
ident_name
= start:ident_start parts:ident_part* { return start + parts.join(''); }

ident_start = [A-Za-z_]
ident_start = [A-Za-z_\u4e00-\u9fa5]

ident_part = [A-Za-z0-9_]
ident_part = [A-Za-z0-9_$\u4e00-\u9fa5\u00C0-\u017F]

// to support column name like `cf1:name` in hbase
column_part = [A-Za-z0-9_:]
Expand Down
4 changes: 2 additions & 2 deletions pegjs/flinksql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2796,9 +2796,9 @@ ident_name
return start + parts.join('');
}

ident_start = [A-Za-z_]
ident_start = [A-Za-z_\u4e00-\u9fa5]

ident_part = [A-Za-z0-9_\-]
ident_part = [A-Za-z0-9_\-$\u4e00-\u9fa5\u00C0-\u017F]

// to support column name like `cf1:name` in hbase
column_part = [A-Za-z0-9_]
Expand Down
4 changes: 2 additions & 2 deletions pegjs/hive.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,9 +1921,9 @@ column_name
ident_name
= start:ident_start parts:ident_part* { return start + parts.join(''); }

ident_start = [A-Za-z_]
ident_start = [A-Za-z_\u4e00-\u9fa5]

ident_part = [A-Za-z0-9_]
ident_part = [A-Za-z0-9_$\u4e00-\u9fa5\u00C0-\u017F]

// to support column name like `cf1:name` in hbase
column_part = [A-Za-z0-9_:]
Expand Down
4 changes: 2 additions & 2 deletions pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2940,9 +2940,9 @@ column_name
ident_name
= start:ident_start parts:ident_part* { return start + parts.join(''); }

ident_start = [A-Za-z_]
ident_start = [A-Za-z_\u4e00-\u9fa5]

ident_part = [A-Za-z0-9_$]
ident_part = [A-Za-z0-9_$$\u4e00-\u9fa5\u00C0-\u017F]

// to support column name like `cf1:name` in hbase
column_part = [A-Za-z0-9_:]
Expand Down
2 changes: 1 addition & 1 deletion pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3231,7 +3231,7 @@ column_name
ident_name
= start:ident_start parts:ident_part* { return start + parts.join(''); }

ident_start = [A-Za-z_]
ident_start = [A-Za-z_\u4e00-\u9fa5]

ident_part = [A-Za-z0-9_$\u0080-\uffff]

Expand Down
7 changes: 4 additions & 3 deletions pegjs/transactsql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,8 @@ column_ref
obj.db = db[0]
obj.schema = schema[0]
}
columnList.add(`select::${[obj.db, obj.schema, obj.table].join('.')}::${col}`);
const fullTableName = [obj.db, obj.schema, obj.table].filter(Boolean).join('.') || 'null'
columnList.add(`select::${fullTableName}::${col}`);
return {
type: 'column_ref',
...obj,
Expand Down Expand Up @@ -2524,9 +2525,9 @@ ident_name_list
return createList(head, tail)
}

ident_start = [A-Za-z_@#]
ident_start = [A-Za-z_@#\u4e00-\u9fa5]

ident_part = [A-Za-z0-9_\-@$]
ident_part = [A-Za-z0-9_\-@$$\u4e00-\u9fa5\u00C0-\u017F]

// to support column name like `cf1:name` in hbase
column_part = [A-Za-z0-9_:]
Expand Down
2 changes: 1 addition & 1 deletion pegjs/trino.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3551,7 +3551,7 @@ ident_name
return start + parts.join('');
}

ident_start = [A-Za-z_]
ident_start = [A-Za-z_\u4e00-\u9fa5]

ident_part = [A-Za-z0-9_$\u0080-\uffff]

Expand Down
16 changes: 15 additions & 1 deletion test/transactsql.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,21 @@ describe('transactsql', () => {
'SELECT * INTO #temp_table FROM tableName',
'SELECT * INTO [#temp_table] FROM [tableName]'
]
}
},
{
title: 'convert function',
sql: [
'SELECT a.username FROM users a WHERE a.end_time = CONVERT(VARCHAR,getdate(),23)',
'SELECT [a].[username] FROM [users] AS [a] WHERE [a].[end_time] = CONVERT([VARCHAR], getdate(), 23)',
]
},
{
title: 'column as chinese name',
sql: [
'SELECT a.username 姓名 FROM users a',
'SELECT [a].[username] AS [姓名] FROM [users] AS [a]'
]
},
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down

0 comments on commit 3a9f18b

Please sign in to comment.