test: update tests of alter statemnts

This commit is contained in:
wewoor 2023-05-11 18:54:56 +08:00
parent 34590a5e9b
commit 65a754e533
5 changed files with 49 additions and 28 deletions

View File

@ -1,38 +1,36 @@
import FlinkSQL from "../../../../src/parser/flinksql"; import FlinkSQL from "../../../../src/parser/flinksql";
import { readSQL } from "../../../helper";
describe('FlinkSQL Create Table Syntax Tests', () => { const features = {
table: readSQL(__dirname, 'alterTable.sql'),
view: readSQL(__dirname, 'alterView.sql'),
function: readSQL(__dirname, 'alterFunction.sql'),
database: readSQL(__dirname, 'alterDatabase.sql'),
};
describe('FlinkSQL Alter Statements Syntax Tests', () => {
const parser = new FlinkSQL(); const parser = new FlinkSQL();
// Alter statements // Alter statements
test('Test simple alter table Statement', () => { features.table.forEach((sql) => {
const sql = ` it(sql, () => {
ALTER TABLE Orders RENAME TO NewOrders; expect(parser.validate(sql).length).toBe(0);
ALTER TABLE sample_table SET ('key1'='value2');
`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
}); });
test('Test simple alter view Statement', () => {
const sql = `
ALTER VIEW v1 RENAME TO v2;
ALTER VIEW v1 AS SELECT c1, c2 FROM tbl;
`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
}); });
test('Test simple alter database Statement', () => { features.view.forEach((sql) => {
const sql = `ALTER DATABASE tempDB SET ("key1"="value1");`; it(sql, () => {
const result = parser.validate(sql); expect(parser.validate(sql).length).toBe(0);
expect(result.length).toBe(0); });
});
features.database.forEach((sql) => {
it(sql, () => {
expect(parser.validate(sql).length).toBe(0);
});
});
features.function.forEach((sql) => {
it(sql, () => {
expect(parser.validate(sql).length).toBe(0);
}); });
test('Test simple alter function Statement', () => {
const sql = `
ALTER FUNCTION tempFunction AS 'SimpleUdf';
ALTER TEMPORARY FUNCTION IF EXISTS tempFunction AS 'SimpleUdf';
ALTER TEMPORARY SYSTEM FUNCTION IF EXISTS tempFunction AS 'SimpleUdf';
ALTER FUNCTION myudf AS 'com.example.MyUdf' LANGUAGE PYTHON;
`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
}); });
}); });

View File

@ -0,0 +1 @@
ALTER DATABASE tempDB SET ("key1"="value1");

View File

@ -0,0 +1,7 @@
ALTER FUNCTION tempFunction AS 'SimpleUdf';
ALTER TEMPORARY FUNCTION IF EXISTS tempFunction AS 'SimpleUdf';
ALTER TEMPORARY SYSTEM FUNCTION IF EXISTS tempFunction AS 'SimpleUdf';
ALTER FUNCTION myudf AS 'com.example.MyUdf' LANGUAGE PYTHON;

View File

@ -0,0 +1,7 @@
ALTER TABLE
Orders RENAME TO NewOrders;
ALTER TABLE
sample_table
SET
('key1' = 'value2');

View File

@ -0,0 +1,8 @@
ALTER VIEW v1 RENAME TO v2;
ALTER VIEW v1 AS
SELECT
c1,
c2
FROM
tbl;