From 99b126cf0bb9e76da08f624cdcf19f713f960e0e Mon Sep 17 00:00:00 2001 From: taozhi8833998 Date: Wed, 1 Jan 2025 10:13:55 +0800 Subject: [PATCH] fix: wrapped column_ref in bigquery --- pegjs/bigquery.pegjs | 14 +++++++------- test/bigquery.spec.js | 7 +++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pegjs/bigquery.pegjs b/pegjs/bigquery.pegjs index 5954c558..a2a4abe9 100644 --- a/pegjs/bigquery.pegjs +++ b/pegjs/bigquery.pegjs @@ -1177,9 +1177,8 @@ create_fulltext_spatial_index_definition = p: (KW_FULLTEXT / KW_SPATIAL) __ kc:(KW_INDEX / KW_KEY)? __ c:column? __ - de: cte_column_definition __ - id: index_options? __ - { + de:cte_column_definition __ + id:index_options? { return { index: c, definition: de, @@ -2141,7 +2140,7 @@ array_expr brackets: true, } } - / s:(array_type / KW_ARRAY)? __ l:(LBRAKE) __ c:(parentheses_list_expr / expr) __ r:(RBRAKE) { + / s:(array_type / KW_ARRAY)? __ l:(LBRAKE) __ c:(parentheses_list_expr / expr) __ r:(RBRAKE) { return { definition: s, expr_list: c, @@ -2449,12 +2448,13 @@ column_ref ...getLocationObject(), }; } - / col:column ce:(__ collate_expr)? { - columnList.add(`select::null::${col}`); + / col:(quoted_ident_type / column) ce:(__ collate_expr)? { + const column = typeof col === 'string' ? col : col.value; + columnList.add(`select::null::${column}`); return { type: 'column_ref', table: null, - column: col, + column: typeof col === 'string' ? col : { expr: col }, collate: ce && ce[1], ...getLocationObject() }; diff --git a/test/bigquery.spec.js b/test/bigquery.spec.js index 0b3bca37..b09a51dd 100644 --- a/test/bigquery.spec.js +++ b/test/bigquery.spec.js @@ -870,6 +870,13 @@ describe('BigQuery', () => { '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)' ] }, + { + title: 'quoted column', + sql: [ + 'SELECT `Customer id` FROM transactions', + 'SELECT `Customer id` FROM transactions' + ] + }, ] SQL_LIST.forEach(sqlInfo => {