lava-oushudb-dt-sql-parser/test/parser/hive/visitor.test.ts
Hayden 885b85e842
Test/hive dml (#155)
* feat: add showIndex parser rule

* test: uncomment show index test cases

* test: add unit tests about DML syntax to HiveSQL

* test: add unit tests about export and import syntax to HiveSQL

* refactor: recompile hive grammar

* test: correct description of HiveSQL unit tests
2023-09-06 15:15:04 +08:00

34 lines
1.1 KiB
TypeScript

import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
import { HiveSqlParserVisitor } from '../../../src/lib/hive/HiveSqlParserVisitor';
import HiveSQL from '../../../src/parser/hive';
import { ProgramContext } 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 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();
}
}
const visitor = new MyVisitor();
visitor.visit(parserTree as ProgramContext);
expect(result).toBe(expectTableName);
});
});