2020-09-11 17:39:10 +08:00
|
|
|
import SQLParser from '../../../src/parser/hive';
|
|
|
|
|
|
|
|
describe('Hive SQL Syntax Tests', () => {
|
|
|
|
const parser = new SQLParser();
|
2020-11-25 15:04:22 +08:00
|
|
|
test('Create Table Statement', () => {
|
|
|
|
const sql = 'CREATE TABLE person(name STRING,age INT);';
|
2020-09-11 17:39:10 +08:00
|
|
|
const result = parser.validate(sql);
|
|
|
|
expect(result.length).toBe(0);
|
|
|
|
});
|
2020-11-25 17:04:55 +08:00
|
|
|
test('Create Table Statement', () => {
|
|
|
|
const sql = `alter table dm_gis.table_name add if not exists partition (inc_day = '20190601');`;
|
|
|
|
const result = parser.validate(sql);
|
|
|
|
expect(result.length).toBe(0);
|
|
|
|
});
|
2020-11-25 15:04:22 +08:00
|
|
|
test('Wrong Select Statement', () => {
|
|
|
|
const sql = 'SELECT add ABC from Where ;'
|
2020-09-11 17:39:10 +08:00
|
|
|
const result = parser.validate(sql);
|
2020-11-25 15:04:22 +08:00
|
|
|
expect(result.length).toBe(2);
|
|
|
|
expect(result[0].message).toBe(`no viable alternative at input 'SELECTaddABCfromWhere'`)
|
|
|
|
expect(result[1].message).toBe(`mismatched input 'Where' expecting <EOF>`)
|
2020-09-11 17:39:10 +08:00
|
|
|
});
|
2020-11-25 15:04:22 +08:00
|
|
|
});
|