add flinksql
This commit is contained in:
@ -1,19 +1,21 @@
|
||||
const dtSqlParser = require('../lib/index');
|
||||
import * as dtSqlParser from '../src';
|
||||
import { SyntaxResult } from '../src/core/sqlSyntaxParser';
|
||||
const parser = dtSqlParser.parser;
|
||||
const filter = dtSqlParser.filter;
|
||||
const flinksqlParser = dtSqlParser.flinksqlParser;
|
||||
|
||||
|
||||
describe('complete test', () => {
|
||||
describe('hive', () => {
|
||||
test('complete result', () => {
|
||||
const sql = 'select id,name from user ';
|
||||
const result = parser.parserSql([sql, ''], 'hive');
|
||||
const result = parser.parserSql([sql, ''], dtSqlParser.parser.sqlType.Hive);
|
||||
expect(result.locations).toBeInstanceOf(Array);
|
||||
expect(result.suggestKeywords).toBeInstanceOf(Array);
|
||||
});
|
||||
test('empty result', () => {
|
||||
const sql = 'i';
|
||||
const result = parser.parserSql([sql, ''], 'hive');
|
||||
const result = parser.parserSql([sql, ''], dtSqlParser.parser.sqlType.Hive);
|
||||
expect(result.locations).toBeInstanceOf(Array);
|
||||
expect(result.locations).toHaveLength(0);
|
||||
expect(result.suggestKeywords).toBeInstanceOf(Array);
|
||||
@ -25,12 +27,12 @@ describe('syntax test', () => {
|
||||
describe('hive', () => {
|
||||
test('no error', () => {
|
||||
const sql = 'select id,name from user ';
|
||||
const result = parser.parseSyntax([sql, ''], 'hive');
|
||||
const result = parser.parseSyntax([sql, ''], dtSqlParser.parser.sqlType.Hive);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
test('select table should not be null', () => {
|
||||
const sql = 'select id,name from ';
|
||||
const result = parser.parseSyntax([sql, ''], 'hive');
|
||||
const result = parser.parseSyntax([sql, ''], dtSqlParser.parser.sqlType.Hive) as SyntaxResult;
|
||||
expect(result.loc).toEqual({
|
||||
first_line: 1,
|
||||
last_line: 1,
|
||||
@ -44,7 +46,7 @@ describe('syntax test', () => {
|
||||
,order_date bigint comment 'order date'
|
||||
)comment 'order table'
|
||||
PARTITIONED BY (ds string);`;
|
||||
const result = parser.parseSyntax([sql, ''], 'hive');
|
||||
const result = parser.parseSyntax([sql, ''], dtSqlParser.parser.sqlType.Hive) as SyntaxResult;
|
||||
expect(result.text).toBe('1exists');
|
||||
expect(result.loc).toEqual({
|
||||
first_line: 1,
|
||||
@ -54,4 +56,26 @@ describe('syntax test', () => {
|
||||
})
|
||||
});
|
||||
})
|
||||
describe('flinksql', () => {
|
||||
test('no error', () => {
|
||||
const sql = `select id from user.id;`;
|
||||
const result = flinksqlParser(sql);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
test('empty sql', () => {
|
||||
const sql = ``;
|
||||
const result = flinksqlParser(sql);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
test('syntax error', () => {
|
||||
const sql = 'select id from user.id; \nselect id from us*er.id; \nselect id from *user.id;';
|
||||
const result = flinksqlParser(sql);
|
||||
expect(result).toMatchObject({
|
||||
line: 2,
|
||||
column: 17,
|
||||
});
|
||||
expect(result.token.start).toBe(42);
|
||||
expect(result.token.stop).toBe(42);
|
||||
})
|
||||
})
|
||||
})
|
37
test/t.js
37
test/t.js
@ -0,0 +1,37 @@
|
||||
const dtSqlParser = require('../lib/index');
|
||||
const flinkParser = require('../lib/lib/flinkParser').default;
|
||||
const parser = dtSqlParser.parser;
|
||||
|
||||
console.log(flinkParser(`select * from user
|
||||
wh1ere a`))
|
||||
console.time('t')
|
||||
const sql = `INSERT INTO TABLE STUDENT_SCORES VALUES
|
||||
('1','111','68','69','90','CLASS1','DEPARTMENT1'),
|
||||
('2','112','73','80','96','CLASS1','DEPARTMENT1'),
|
||||
('3','113','90','74','75','CLASS1','DEPARTMENT1'),
|
||||
('4','114','89','94','93','CLASS1','DEPARTMENT2'),
|
||||
('5','115','99','93','89','CLASS1','DEPARTMENT1'),
|
||||
('6','121','96','74','79','CLASS2','DEPARTMENT1'),
|
||||
('7','122','89','86','85','CLASS2','DEPARTMENT1'),
|
||||
('8','123','70','78','61','CLASS2','DEPARTMENT1'),
|
||||
('9','124','76','70','76','CLASS2','DEPARTMENT1'),
|
||||
('10','211','89','93','60','CLASS1','DEPARTMENT2'),
|
||||
('11','212','76','83','75','CLASS1','DEPARTMENT2'),
|
||||
('12','213','71','94','90','CLASS2','DEPARTMENT2'),
|
||||
('13','214','94','94','66','CLASS1','DEPARTMENT2'),
|
||||
('14','215','84','82','73','CLASS1','DEPARTMENT2'),
|
||||
('15','216','85','74','93','CLASS1','DEPARTMENT2'),
|
||||
('16','221','77','99','61','CLASS2','DEPARTMENT2'),
|
||||
('17','222','80','78','96','CLASS2','DEPARTMENT2'),
|
||||
('18','223','79','74','96','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('19','224','75','80','78','CLASS2','DEPARTMENT2'),
|
||||
('20','225','82','85','63','CLASS2','DEPARTMENT2')`;
|
||||
const result = parser.parserSql([sql, ''], 'hive');
|
||||
console.timeEnd('t')
|
20
test/utils/index.test.ts
Normal file
20
test/utils/index.test.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import * as utils from '../../src/utils';
|
||||
describe('utils', () => {
|
||||
describe('split sql', () => {
|
||||
test('single', () => {
|
||||
let sql = 'select id,name from user';
|
||||
let result = utils.splitSql(sql);
|
||||
expect(result).toEqual([sql.length - 1])
|
||||
sql += ';';
|
||||
result = utils.splitSql(sql);
|
||||
expect(result).toEqual([sql.length - 1])
|
||||
});
|
||||
test('multiple', () => {
|
||||
const sql = `-- a ;
|
||||
select * from a;
|
||||
select user from b`;
|
||||
const result = utils.splitSql(sql);
|
||||
expect(result).toEqual([34, 65])
|
||||
});
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user