2023-05-04 10:13:05 +08:00
|
|
|
import HiveSqlVisitor from '../../../src/lib/hive/HiveSqlVisitor';
|
|
|
|
import HiveSQL from '../../../src/parser/hive';
|
2020-09-11 17:39:10 +08:00
|
|
|
|
|
|
|
describe('Generic 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-04 10:13:05 +08:00
|
|
|
class MyVisitor extends HiveSqlVisitor<any> {
|
|
|
|
visitTable_name = (ctx): void => {
|
2020-09-11 17:39:10 +08:00
|
|
|
result = ctx.getText().toLowerCase();
|
2023-05-04 10:13:05 +08:00
|
|
|
super.visitTable_name?.(ctx);
|
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);
|
|
|
|
});
|
|
|
|
});
|