Skip to content

Commit

Permalink
Merge pull request #2243 from taozhi8833998/fix-double-quoted-table
Browse files Browse the repository at this point in the history
fix: double quoted table mentions in athena and tsql
  • Loading branch information
taozhi8833998 authored Nov 29, 2024
2 parents ac394b1 + 598a604 commit 3d1d73d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pegjs/athena.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,7 @@ literal_string
value: ca[1].join('')
};
}
/ ca:("\"" single_quote_char* "\"") {
/ ca:("\"" single_quote_char* "\"") !DOT {
return {
type: 'double_quote_string',
value: ca[1].join('')
Expand Down
2 changes: 1 addition & 1 deletion pegjs/transactsql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,7 @@ literal_string
value: ca[1].join(''),
};
}
/ ca:("\"" single_quote_char* "\"") {
/ ca:("\"" single_quote_char* "\"") !DOT {
return {
type: 'double_quote_string',
value: ca[1].join('')
Expand Down
7 changes: 7 additions & 0 deletions test/athena.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,11 @@ describe('athena', () => {
GROUP BY id`
expect(getParsedSql(sql)).to.be.equal("SELECT `id`, array_agg(json_extract_scalar(`elem`, '$.value')) AS `er_teams` FROM `bronze_prod`.`jira_issues` CROSS JOIN UNNEST(CAST(json_extract(json_parse(`fields`), '$.customfield_10100') AS ARRAY(JSON))) AS t(`elem`) GROUP BY `id`")
})
it('should support double quoted table mentions', () => {
const sql = `SELECT
"my_table"."my_column"
FROM
"my_table"`
expect(getParsedSql(sql)).to.be.equal('SELECT `my_table`.`my_column` FROM `my_table`')
})
})
7 changes: 7 additions & 0 deletions test/transactsql.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ describe('transactsql', () => {
'SELECT [a].[username] AS [姓名] FROM [users] AS [a]'
]
},
{
title: 'double quoted table mentions',
sql: [
'SELECT a.username FROM "users" a',
'SELECT [a].[username] FROM [users] AS [a]'
]
},
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down

0 comments on commit 3d1d73d

Please sign in to comment.