fix: add missing expression predicate to impala parser(#225)

* fix(impala): add select supprt is true/false/unknown and support more SEMICOLON

* fix(impala): not use emptyStatement replace SEMICOLON

* test(impala): add select unit test sql and test splitSQLByStatement
This commit is contained in:
霜序
2023-11-30 19:56:07 +08:00
committed by GitHub
parent f93ffb93bf
commit 484c881583
14 changed files with 6957 additions and 6245 deletions

View File

@ -9,7 +9,7 @@ describe('impala SQL Listener Tests', () => {
const parseTree = parser.parse(sql);
test('Listener enterTableName', async () => {
test('Listener enterTableNamePath', async () => {
let result = '';
class MyListener implements ImpalaSqlParserListener {
enterTableNamePath = (ctx): void => {
@ -21,4 +21,24 @@ describe('impala SQL Listener Tests', () => {
await parser.listen(listenTableName as ParseTreeListener, parseTree);
expect(result).toBe(expectTableName);
});
test('Listener sql', async () => {
const sql = `SELECT id FROM games ORDER BY score DESC;\nSHOW SCHEMAS LIKE 'xxx';`;
const sqlSlices = parser.splitSQLByStatement(sql);
expect(sqlSlices.length).toBe(2);
expect(sqlSlices[0].text).toBe('SELECT id FROM games ORDER BY score DESC;');
expect(sql.slice(sqlSlices[0].startIndex, sqlSlices[0].endIndex + 1)).toBe(
sqlSlices[0].text
);
expect(sqlSlices[0].startLine).toBe(1);
expect(sqlSlices[0].endLine).toBe(1);
expect(sqlSlices[1].text).toBe(`SHOW SCHEMAS LIKE 'xxx';`);
expect(sql.slice(sqlSlices[1].startIndex, sqlSlices[1].endIndex + 1)).toBe(
sqlSlices[1].text
);
expect(sqlSlices[1].startLine).toBe(2);
expect(sqlSlices[1].endLine).toBe(2);
});
});

View File

@ -188,4 +188,29 @@ select appx_median(x) from million_numbers;
select count(x) as higher from million_numbers where x > (select appx_median(x) from million_numbers);
select avg(length(s)) from t1;
select avg(length(s)) from t1;
select 'fooBar' ilike 'FOOBAR';
select 'ABCXYZ' not ilike 'ab_xyz';
select 1 not in (1,null,2,3);
SELECT c1 AS "starts with vowel" FROM t2 WHERE upper(substr(c1,1,1)) IN ('A','E','I','O','U');
select 'abcABCaabbcc' iregexp '^[a-c]+$';
select null is distinct from null, null != null;
select
'x' is distinct from 'x ' as string_with_trailing_spaces,
cast('x' as char(5)) is distinct from cast('x ' as char(5)) as char_with_trailing_spaces;
select assertion, b, b is true, b is false, b is unknown
from boolean_test;
select true and null;
select c_first_name, c_last_name from customer where lower(trim(c_last_name)) regexp '^de.*';
select c_first_name, c_last_name from customer where lower(trim(c_last_name)) rlike '^de.*';

View File

@ -11,7 +11,7 @@ describe('impala SQL Visitor Tests', () => {
console.log('Parse error:', error);
});
test('Visitor visitTableName', () => {
test('Visitor visitTableNamePath', () => {
let result = '';
class MyVisitor
extends AbstractParseTreeVisitor<any>