From 1339522d5a0279aa1099963600b9e930763d6277 Mon Sep 17 00:00:00 2001 From: taozhi8833998 Date: Tue, 27 Aug 2024 14:10:46 +0800 Subject: [PATCH] refactor: fix location different for same sql in different dialect --- pegjs/mysql.pegjs | 18 ++++++++++++++++-- pegjs/trino.pegjs | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pegjs/mysql.pegjs b/pegjs/mysql.pegjs index 1f3e2624..98d8f7cf 100644 --- a/pegjs/mysql.pegjs +++ b/pegjs/mysql.pegjs @@ -2274,12 +2274,13 @@ column_list_item ...getLocationObject(), }; } - / table:(ident __ DOT)? __ STAR { + / tbl:(ident __ DOT)? __ STAR { + const table = tbl && tbl[0] || null columnList.add(`select::${table}::(.*)`); return { expr: { type: 'column_ref', - table: table && table[0] || null, + table, column: '*' }, as: null, @@ -3119,6 +3120,19 @@ column_ref ...getLocationObject(), }; } + / tbl:(ident __ DOT)? __ STAR { + const table = tbl && tbl[0] || null + columnList.add(`select::${table}::(.*)`); + return { + expr: { + type: 'column_ref', + table, + column: '*' + }, + as: null, + ...getLocationObject(), + }; + } / col:column { columnList.add(`select::null::${col}`); return { diff --git a/pegjs/trino.pegjs b/pegjs/trino.pegjs index 4c9c6c69..dc998e79 100644 --- a/pegjs/trino.pegjs +++ b/pegjs/trino.pegjs @@ -4027,7 +4027,7 @@ cast_expr ...c, } } - / e:(func_call/ aggr_func / window_func / case_expr / interval_expr / literal / column_ref_array_index / param) __ c:cast_double_colon? { + / e:(func_call/ aggr_func / window_func / case_expr / interval_expr / literal / column_ref_array_index / param) __ c:cast_double_colon? { /* => { type: 'cast'; expr: literal | aggr_func | func_call | case_expr | interval_expr | column_ref | param