lava-oushudb-dt-sql-parser/test/parser/flinksql/syntax/insertStatement.test.ts
nankaNULL 4f02f9aca0
Feat/flink grammar (#73)
* feat: complete flink sql insert statement

* feat: complete flink sql drop statement

* feat: complete flink sql alert statement

* feat: complete flink sql create statement, remove console log

* feat: complete flink sql describe, show, explain, use statement

* feat(flinksql): add statement, such as set, load

* fix(flinksql): fix insert, add temporary table
2023-02-27 19:03:32 +08:00

84 lines
2.9 KiB
TypeScript

import { FlinkSQL } from '../../../../src';
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);
});
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);
});
});