f9dbd9fc23
* feat: replace errorCollector with ParserErrorListener to collect lexer error * refactor: remove useless method in basicParser * feat: correct splitSQLByStatement method * feat: rename parse to parseWithCache and add new parse method * refactor: rename parserTree to parseTree * test: rename parserTree to parseTree * refactor: rename parserError to parseError * feat: export ErrorHandler type * feat: use errorhandler form params * test: basic parser unit tests * style: lint via prettier
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
|
|
import { HiveSqlParserVisitor } from '../../../src/lib/hive/HiveSqlParserVisitor';
|
|
import HiveSQL from '../../../src/parser/hive';
|
|
import { ProgramContext } from '../../../src/lib/hive/HiveSqlParser';
|
|
|
|
describe('HiveSQL 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 HiveSQL();
|
|
|
|
const parseTree = parser.parse(sql, (error) => {
|
|
console.log('Parse error:', error);
|
|
});
|
|
|
|
test('Visitor visitTableName', () => {
|
|
let result = '';
|
|
class MyVisitor extends AbstractParseTreeVisitor<any> implements HiveSqlParserVisitor<any> {
|
|
defaultResult() {
|
|
return result;
|
|
}
|
|
|
|
visitTableName(ctx) {
|
|
result = ctx.text.toLowerCase();
|
|
}
|
|
}
|
|
|
|
const visitor = new MyVisitor();
|
|
visitor.visit(parseTree as ProgramContext);
|
|
|
|
expect(result).toBe(expectTableName);
|
|
});
|
|
});
|