lava-oushudb-dt-sql-parser/test/parser/hive/visitor.test.ts
2020-11-25 17:04:55 +08:00

29 lines
917 B
TypeScript

import SQLParser, { HiveSqlVisitor } from '../../../src/parser/hive';
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 parserTree = parser.parse(sql, (error) => {
console.log('Parse error:', error);
});
// console.log('Parser tree string:', parser.toString(parserTree));
test('Visitor visitTableName', () => {
let result = '';
class MyVisitor extends HiveSqlVisitor {
visitTable_name(ctx): void {
result = ctx.getText().toLowerCase();
super.visitTable_name(ctx);
}
}
const visitor: any = new MyVisitor();
visitor.visit(parserTree);
expect(result).toBe(expectTableName);
});
});