From 394e5cc0d6aa255776214459314dc171a5bada0c Mon Sep 17 00:00:00 2001 From: Albin Zeng Date: Thu, 2 Apr 2020 15:08:21 +0800 Subject: [PATCH] fix: #34 --- src/sqlParser.jison | 2 +- test/main.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/sqlParser.jison b/src/sqlParser.jison index ee5b329..7cff3e8 100644 --- a/src/sqlParser.jison +++ b/src/sqlParser.jison @@ -585,6 +585,6 @@ index_hint ; table_factor : identifier partitionOpt aliasOpt index_hint_list_opt { $$ = { type: 'TableFactor', value: $1, partition: $2, alias: $3.alias, hasAs: $3.hasAs, indexHintOpt: $4 } } - | '(' selectClause ')' aliasOpt { $$ = { type: 'SubQuery', value: $2, alias: $4.alias, hasAs: $4.hasAs } } + | '(' selectClause ')' aliasOpt { $$ = { type: 'TableFactor', value: { type: 'SubQuery', value: $2 }, alias: $4.alias, hasAs: $4.hasAs} } | '(' table_references ')' { $$ = $2; $$.hasParentheses = true } ; diff --git a/test/main.test.js b/test/main.test.js index 558d133..834d3f1 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -397,4 +397,18 @@ describe('select grammar support', function() { testParser('select a as `A|A` from b limit 2;'); testParser('select a as `A A` from b limit 2;'); }); + + it('bugfix table alias', function() { + testParser(` + SELECT stime, A.names, B.names FROM ( + SELECT stime, names FROM iaas_data.iaas_d3c0d0681cc1900 + ) AS A LEFT JOIN ( + SELECT stime, names FROM iaas_data.iaas_1071f89feaa0e100 + ) AS B ON A.stime = B.stime + `); + }); + + it('bugfix table alias2', function() { + testParser('select a.* from a t1 join b t2 on t1.a = t2.a') + }) });