195878da9b
* feat: replace antlr4ts with antlr4ng * feat: switch caseInsensitive option on * feat: recompile all g4 file * feat: update parser to fit antlr4ng * test: update test to fit antlr4ng
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { AbstractParseTreeVisitor } from 'antlr4ng';
|
|
|
|
import HiveSQL from 'src/parser/hive';
|
|
import { HiveSqlParserVisitor } from 'src/lib/hive/HiveSqlParserVisitor';
|
|
import { ProgramContext, TableNameContext } 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.error('Parse error:', error);
|
|
});
|
|
|
|
test('Visitor visitTableName', () => {
|
|
let result = '';
|
|
class MyVisitor extends AbstractParseTreeVisitor<any> implements HiveSqlParserVisitor<any> {
|
|
defaultResult() {
|
|
return result;
|
|
}
|
|
|
|
visitTableName(ctx: TableNameContext) {
|
|
result = ctx.getText().toLowerCase();
|
|
}
|
|
}
|
|
|
|
const visitor = new MyVisitor();
|
|
visitor.visit(parseTree as ProgramContext);
|
|
|
|
expect(result).toBe(expectTableName);
|
|
});
|
|
});
|