Skip to content

Commit ba98ec2

Browse files
Merge pull request #2287 from taozhi8833998/fix-column-wrapped-bigquery
fix: wrapped column_ref in bigquery
2 parents 4e1eccb + 99b126c commit ba98ec2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

pegjs/bigquery.pegjs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,8 @@ create_fulltext_spatial_index_definition
11771177
= p: (KW_FULLTEXT / KW_SPATIAL) __
11781178
kc:(KW_INDEX / KW_KEY)? __
11791179
c:column? __
1180-
de: cte_column_definition __
1181-
id: index_options? __
1182-
{
1180+
de:cte_column_definition __
1181+
id:index_options? {
11831182
return {
11841183
index: c,
11851184
definition: de,
@@ -2141,7 +2140,7 @@ array_expr
21412140
brackets: true,
21422141
}
21432142
}
2144-
/ s:(array_type / KW_ARRAY)? __ l:(LBRAKE) __ c:(parentheses_list_expr / expr) __ r:(RBRAKE) {
2143+
/ s:(array_type / KW_ARRAY)? __ l:(LBRAKE) __ c:(parentheses_list_expr / expr) __ r:(RBRAKE) {
21452144
return {
21462145
definition: s,
21472146
expr_list: c,
@@ -2449,12 +2448,13 @@ column_ref
24492448
...getLocationObject(),
24502449
};
24512450
}
2452-
/ col:column ce:(__ collate_expr)? {
2453-
columnList.add(`select::null::${col}`);
2451+
/ col:(quoted_ident_type / column) ce:(__ collate_expr)? {
2452+
const column = typeof col === 'string' ? col : col.value;
2453+
columnList.add(`select::null::${column}`);
24542454
return {
24552455
type: 'column_ref',
24562456
table: null,
2457-
column: col,
2457+
column: typeof col === 'string' ? col : { expr: col },
24582458
collate: ce && ce[1],
24592459
...getLocationObject()
24602460
};

test/bigquery.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,13 @@ describe('BigQuery', () => {
870870
'CREATE OR REPLACE VIEW project.database.schema AS (SELECT employee_id, first_name, last_name, salary, hire_date, modified FROM database.table WHERE salary > 50000)'
871871
]
872872
},
873+
{
874+
title: 'quoted column',
875+
sql: [
876+
'SELECT `Customer id` FROM transactions',
877+
'SELECT `Customer id` FROM transactions'
878+
]
879+
},
873880
]
874881

875882
SQL_LIST.forEach(sqlInfo => {

0 commit comments

Comments
 (0)