feat: improve flinksql insertStatement
* feat: feat: improve flinksql insertStatement * feat: complete insertFromSelectQueries syntax unit tests * feat: complete insertValuesIntoTable syntax unit tests * feat: improve insertValuesIntoTable sql case data * feat: complete insertMultipeTables unit cases * feat: depracate insertMulStatement grammar for 1.1.4 * fix: depracate unless files * test: recover jest.config info * feat: improve insertMultipleTable.sql test case * feat: build new flinksql parser and lexer * feat: generator new flink parser and lexer file * test: improve readSQL logic * test: fix insertMultipleTable sql error * test: recover jest.config.js info
This commit is contained in:
@ -0,0 +1,47 @@
|
||||
INSERT INTO country_page_view
|
||||
SELECT user,
|
||||
cnt
|
||||
FROM page_view_source;
|
||||
|
||||
INSERT INTO catalog1.db1.country_page_view
|
||||
SELECT user,
|
||||
cnt
|
||||
FROM page_view_source;
|
||||
|
||||
|
||||
--- Execute InsertStatement
|
||||
EXECUTE
|
||||
INSERT INTO country_page_view PARTITION (date = '2019-8-30', country = 'China')
|
||||
SELECT user,
|
||||
cnt
|
||||
FROM page_view_source;
|
||||
|
||||
--- Partition Clause: Static Partition
|
||||
INSERT INTO country_page_view PARTITION (date = '2019-8-30', country = 'China')
|
||||
SELECT user,
|
||||
cnt
|
||||
FROM page_view_source;
|
||||
|
||||
--- Partition Clause: Dynamic Partition
|
||||
INSERT INTO country_page_view PARTITION (date = '2019-8-30')
|
||||
SELECT user,
|
||||
cnt,
|
||||
country
|
||||
FROM page_view_source;
|
||||
|
||||
--- Column List Statement
|
||||
INSERT INTO country_page_view PARTITION (date = '2019-8-30', country = 'China') (date, country)
|
||||
SELECT user,
|
||||
cnt
|
||||
FROM page_view_source;
|
||||
|
||||
--- Insert Method: OverWrite
|
||||
INSERT OVERWRITE country_page_view PARTITION (date = '2019-8-30')
|
||||
SELECT user,
|
||||
cnt,
|
||||
country
|
||||
FROM page_view_source;
|
||||
|
||||
|
||||
|
||||
|
11
test/parser/flinksql/syntax/fixtures/insertMultipleTable.sql
Normal file
11
test/parser/flinksql/syntax/fixtures/insertMultipleTable.sql
Normal file
@ -0,0 +1,11 @@
|
||||
EXECUTE STATEMENT SET
|
||||
BEGIN
|
||||
INSERT INTO country_page_view
|
||||
VALUES ('Chinese', 'mumiao', 18),
|
||||
('Amercian', 'georage', 22);
|
||||
INSERT INTO country_page_view
|
||||
VALUES ('Chinese', 'mumiao', 18),
|
||||
('Amercian', 'georage', 22);
|
||||
END;
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
INSERT INTO country_page_view
|
||||
VALUES ('Chinese', 'mumiao', 18),
|
||||
('Amercian', 'georage', 22);
|
||||
|
||||
EXECUTE
|
||||
INSERT INTO country_page_view
|
||||
VALUES ('Chinese', 'mumiao', 18),
|
||||
('Amercian', 'georage', 22);
|
||||
|
||||
EXECUTE
|
||||
INSERT OverWrite country_page_view
|
||||
VALUES ('Chinese', 'mumiao', 18),
|
||||
('Amercian', 'georage', 22);
|
||||
|
||||
EXECUTE
|
||||
INSERT INTO country_page_view
|
||||
VALUES ('Chinese', 'mumiao', 18),
|
||||
('Amercian', 'georage', 22);
|
||||
|
||||
INSERT INTO catalog1.db1.country_page_view
|
||||
VALUES ('Chinese', 'mumiao', 18),
|
||||
('Amercian', 'georage', 22);
|
@ -1,83 +1,29 @@
|
||||
import FlinkSQL from "../../../../src/parser/flinksql";
|
||||
import FlinkSQL from '../../../../src/parser/flinksql';
|
||||
import { readSQL } from '../../../helper';
|
||||
|
||||
describe('FlinkSQL Create Table Syntax Tests', () => {
|
||||
const parser = new FlinkSQL();
|
||||
// insert statements
|
||||
test('Test one simple Insert Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO country_page_view
|
||||
SELECT user, cnt FROM page_view_source;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Insert Overwrite Statement', () => {
|
||||
const sql = `
|
||||
INSERT OVERWRITE country_page_view PARTITION (date='2019-8-30', country='China')
|
||||
SELECT user, cnt FROM page_view_source;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test execute Statement', () => {
|
||||
const sql = `
|
||||
EXECUTE INSERT INTO country_page_view PARTITION (date='2019-8-30', country='China')
|
||||
SELECT user, cnt FROM page_view_source;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Partition Clause Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO country_page_view PARTITION (date='2019-8-30', country='China')
|
||||
SELECT user, cnt FROM page_view_source;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Column List Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO emps PARTITION (x='ab', y='bc') (x, y) SELECT * FROM emps;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test Insert Values Statement', () => {
|
||||
const sql = `
|
||||
INSERT INTO students
|
||||
VALUES ('fred flintstone', 35, 1.28), ('barney rubble', 32, 2.32);
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
test('Test insert into multiple tables Statement for 1.14', () => {
|
||||
const sql = `
|
||||
BEGIN STATEMENT SET;
|
||||
|
||||
INSERT INTO pageviews
|
||||
SELECT page_id, count(1)
|
||||
FROM pageviews
|
||||
GROUP BY page_id;
|
||||
|
||||
INSERT INTO uniqueview
|
||||
SELECT page_id, count(distinct user_id)
|
||||
FROM pageviews
|
||||
GROUP BY page_id;
|
||||
|
||||
END;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
const parser = new FlinkSQL();
|
||||
|
||||
const features = {
|
||||
InsertFromSelectQueries: readSQL(__dirname, 'insertFromSelectQueries.sql'),
|
||||
InsertValuesIntoTable: readSQL(__dirname, 'insertValuesIntoTable.sql'),
|
||||
InsertMultipleTable: readSQL(__dirname, 'insertMultipleTable.sql')
|
||||
};
|
||||
|
||||
describe('FlinkSQL Insert Syntax Tests', () => {
|
||||
features.InsertFromSelectQueries.forEach((insertFromSelectQueries) => {
|
||||
it(insertFromSelectQueries, () => {
|
||||
expect(parser.validate(insertFromSelectQueries).length).toBe(0);
|
||||
});
|
||||
});
|
||||
test('Test insert into multiple tables Statement for 1.15', () => {
|
||||
const sql = `
|
||||
EXECUTE STATEMENT SET
|
||||
BEGIN
|
||||
INSERT INTO students VALUES ('fred flintstone', 35, 1.28), ('barney rubble', 32, 2.32);
|
||||
INSERT INTO students VALUES ('fred flintstone', 35, 1.28), ('barney rubble', 32, 2.32);
|
||||
END;
|
||||
`;
|
||||
const result = parser.validate(sql);
|
||||
expect(result.length).toBe(0);
|
||||
features.InsertValuesIntoTable.forEach((insertValuesIntoTable) => {
|
||||
it(insertValuesIntoTable, () => {
|
||||
expect(parser.validate(insertValuesIntoTable).length).toBe(0);
|
||||
});
|
||||
});
|
||||
features.InsertMultipleTable.forEach((insertMultipleTable) => {
|
||||
it(insertMultipleTable, () => {
|
||||
expect(parser.validate(insertMultipleTable).length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user