lava-oushudb-dt-sql-parser/test/parser/hive/visitor.test.ts
Hayden bb0fad1dbe
refactor: standard naming (#278)
* refactor: rename flinksql to flink

* refactor: rename pgsql to postgresql

* refactor: rename trinosql to trino

* refactor: replace all default exports with named export

* refactor: rename basicParser to basicSQL

* refactor: rename basic-parser-types to types

* refactor: replace arrow func with plain func
2024-03-27 10:33:25 +08:00

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 hive = new HiveSQL();
const parseTree = hive.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);
});
});