lava-oushudb-dt-sql-parser/test/parser/hive/visitor.test.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
import { HiveSqlParserVisitor } from '../../../src/lib/hive/HiveSqlParserVisitor';
2023-05-04 10:13:05 +08:00
import HiveSQL from '../../../src/parser/hive';
import { ProgramContext } from '../../../src/lib/hive/HiveSqlParser';
describe('HiveSQL Visitor Tests', () => {
2020-11-25 17:04:55 +08:00
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 parserTree = 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();
}
}
2020-11-25 17:04:55 +08:00
2023-05-04 10:13:05 +08:00
const visitor = new MyVisitor();
visitor.visit(parserTree as ProgramContext);
expect(result).toBe(expectTableName);
});
});