2023-05-30 14:44:03 +08:00
|
|
|
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
|
|
|
|
import { HiveSqlVisitor } from '../../../src/lib/hive/HiveSqlVisitor';
|
2023-05-04 10:13:05 +08:00
|
|
|
import HiveSQL from '../../../src/parser/hive';
|
2020-09-11 17:39:10 +08:00
|
|
|
|
2023-05-30 14:44:03 +08:00
|
|
|
describe('Hive SQL 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;`;
|
2021-01-05 17:45:54 +08:00
|
|
|
const parser = new HiveSQL();
|
2020-09-11 17:39:10 +08:00
|
|
|
|
|
|
|
const parserTree = parser.parse(sql, (error) => {
|
|
|
|
console.log('Parse error:', error);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Visitor visitTableName', () => {
|
|
|
|
let result = '';
|
2023-05-30 14:44:03 +08:00
|
|
|
class MyVisitor extends AbstractParseTreeVisitor<any> implements HiveSqlVisitor<any> {
|
|
|
|
|
|
|
|
defaultResult() {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
visitTableName(ctx) {
|
|
|
|
result = ctx.text.toLowerCase();
|
2020-09-11 17:39:10 +08:00
|
|
|
}
|
|
|
|
}
|
2020-11-25 17:04:55 +08:00
|
|
|
|
2023-05-04 10:13:05 +08:00
|
|
|
const visitor = new MyVisitor();
|
2020-09-11 17:39:10 +08:00
|
|
|
visitor.visit(parserTree);
|
|
|
|
|
|
|
|
expect(result).toBe(expectTableName);
|
|
|
|
});
|
|
|
|
});
|