From 57aba357abdf18bb5540c0fa31b755d7ce8f448b Mon Sep 17 00:00:00 2001 From: xiaowei Date: Tue, 5 Jan 2021 17:45:54 +0800 Subject: [PATCH] refactor(hive): extract hive export into src index --- src/index.ts | 2 ++ src/parser/hive.ts | 3 --- test/parser/hive/lexer.test.ts | 4 ++-- test/parser/hive/listener.test.ts | 4 ++-- test/parser/hive/syntax.test.ts | 12 ++++++------ test/parser/hive/visitor.test.ts | 4 ++-- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index 12a5ed6..2ce2058 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,3 +4,5 @@ export * from './lib/flinksql/FlinkSqlParserListener'; export * from './lib/flinksql/FlinkSqlParserVisitor'; export * from './lib/generic/SqlParserVisitor'; export * from './lib/generic/SqlParserListener'; +export * from './lib/hive/HiveSqlListener'; +export * from './lib/hive/HiveSqlVisitor'; diff --git a/src/parser/hive.ts b/src/parser/hive.ts index aa9d9a0..6855f23 100644 --- a/src/parser/hive.ts +++ b/src/parser/hive.ts @@ -1,9 +1,6 @@ import { InputStream, CommonTokenStream, Lexer } from 'antlr4'; import { HiveSqlLexer } from '../lib/hive/HiveSqlLexer'; import { HiveSql } from '../lib/hive/HiveSql'; -export * from '../lib/hive/HiveSqlListener'; -export * from '../lib/hive/HiveSqlVisitor'; - import BasicParser from './common/basicParser'; export default class HiveSQL extends BasicParser { diff --git a/test/parser/hive/lexer.test.ts b/test/parser/hive/lexer.test.ts index 78a002d..59847e4 100644 --- a/test/parser/hive/lexer.test.ts +++ b/test/parser/hive/lexer.test.ts @@ -1,7 +1,7 @@ -import SQLParser from '../../../src/parser/hive'; +import { HiveSQL } from '../../../src'; describe('HiveSQL Lexer tests', () => { - const parser = new SQLParser(); + const parser = new HiveSQL(); test('select token counts', () => { const sql = 'SELECT * FROM t1'; const tokens = parser.getAllTokens(sql); diff --git a/test/parser/hive/listener.test.ts b/test/parser/hive/listener.test.ts index ac92674..6d7705d 100644 --- a/test/parser/hive/listener.test.ts +++ b/test/parser/hive/listener.test.ts @@ -1,7 +1,7 @@ -import SQLParser, { HiveSqlListener } from '../../../src/parser/hive'; +import { HiveSQL, HiveSqlListener } from '../../../src'; describe('Hive SQL Listener Tests', () => { - const parser = new SQLParser(); + const parser = new HiveSQL(); test('Listener enterSelectList', async () => { const expectTableName = 'userName'; const sql = `select ${expectTableName} from user1 where inc_day='20190601' limit 1000;`; diff --git a/test/parser/hive/syntax.test.ts b/test/parser/hive/syntax.test.ts index 3df530b..4e5aad9 100644 --- a/test/parser/hive/syntax.test.ts +++ b/test/parser/hive/syntax.test.ts @@ -1,7 +1,7 @@ -import SQLParser from '../../../src/parser/hive'; +import { HiveSQL } from '../../../src'; describe('Hive SQL Syntax Tests', () => { - const parser = new SQLParser(); + const parser = new HiveSQL(); test('Create Table Statement', () => { const sql = 'CREATE TABLE person(name STRING,age INT);'; const result = parser.validate(sql); @@ -13,10 +13,10 @@ describe('Hive SQL Syntax Tests', () => { expect(result.length).toBe(0); }); test('Wrong Select Statement', () => { - const sql = 'SELECT add ABC from Where ;' + const sql = 'SELECT add ABC from Where ;'; const result = parser.validate(sql); expect(result.length).toBe(2); - expect(result[0].message).toBe(`no viable alternative at input 'SELECTaddABCfromWhere'`) - expect(result[1].message).toBe(`mismatched input 'Where' expecting `) + expect(result[0].message).toBe(`no viable alternative at input 'SELECTaddABCfromWhere'`); + expect(result[1].message).toBe(`mismatched input 'Where' expecting `); }); -}); \ No newline at end of file +}); diff --git a/test/parser/hive/visitor.test.ts b/test/parser/hive/visitor.test.ts index 57ecf9b..a8a6b3a 100644 --- a/test/parser/hive/visitor.test.ts +++ b/test/parser/hive/visitor.test.ts @@ -1,9 +1,9 @@ -import SQLParser, { HiveSqlVisitor } from '../../../src/parser/hive'; +import { HiveSQL, HiveSqlVisitor } from '../../../src'; describe('Generic SQL Visitor Tests', () => { const expectTableName = 'dm_gis.dlv_addr_tc_count'; const sql = `select citycode,tc,inc_day from ${expectTableName} where inc_day='20190501' limit 100;`; - const parser = new SQLParser(); + const parser = new HiveSQL(); const parserTree = parser.parse(sql, (error) => { console.log('Parse error:', error);