From 65a754e533539df92917fcd35383988765bbcb7e Mon Sep 17 00:00:00 2001 From: wewoor Date: Thu, 11 May 2023 18:54:56 +0800 Subject: [PATCH] test: update tests of alter statemnts --- .../flinksql/syntax/alterStatement.test.ts | 54 +++++++++---------- .../syntax/fixtures/alterDatabase.sql | 1 + .../syntax/fixtures/alterFunction.sql | 7 +++ .../flinksql/syntax/fixtures/alterTable.sql | 7 +++ .../flinksql/syntax/fixtures/alterView.sql | 8 +++ 5 files changed, 49 insertions(+), 28 deletions(-) create mode 100644 test/parser/flinksql/syntax/fixtures/alterDatabase.sql create mode 100644 test/parser/flinksql/syntax/fixtures/alterFunction.sql create mode 100644 test/parser/flinksql/syntax/fixtures/alterTable.sql create mode 100644 test/parser/flinksql/syntax/fixtures/alterView.sql diff --git a/test/parser/flinksql/syntax/alterStatement.test.ts b/test/parser/flinksql/syntax/alterStatement.test.ts index aeb00ff..784727b 100644 --- a/test/parser/flinksql/syntax/alterStatement.test.ts +++ b/test/parser/flinksql/syntax/alterStatement.test.ts @@ -1,38 +1,36 @@ 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(); // Alter statements - test('Test simple alter table Statement', () => { - const sql = ` - ALTER TABLE Orders RENAME TO NewOrders; - ALTER TABLE sample_table SET ('key1'='value2'); - `; - const result = parser.validate(sql); - expect(result.length).toBe(0); + features.table.forEach((sql) => { + it(sql, () => { + expect(parser.validate(sql).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); + features.view.forEach((sql) => { + it(sql, () => { + expect(parser.validate(sql).length).toBe(0); + }); }); - test('Test simple alter database Statement', () => { - const sql = `ALTER DATABASE tempDB SET ("key1"="value1");`; - const result = parser.validate(sql); - expect(result.length).toBe(0); + features.database.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); + + features.function.forEach((sql) => { + it(sql, () => { + expect(parser.validate(sql).length).toBe(0); + }); }); }); diff --git a/test/parser/flinksql/syntax/fixtures/alterDatabase.sql b/test/parser/flinksql/syntax/fixtures/alterDatabase.sql new file mode 100644 index 0000000..4e8f58d --- /dev/null +++ b/test/parser/flinksql/syntax/fixtures/alterDatabase.sql @@ -0,0 +1 @@ +ALTER DATABASE tempDB SET ("key1"="value1"); \ No newline at end of file diff --git a/test/parser/flinksql/syntax/fixtures/alterFunction.sql b/test/parser/flinksql/syntax/fixtures/alterFunction.sql new file mode 100644 index 0000000..2360efe --- /dev/null +++ b/test/parser/flinksql/syntax/fixtures/alterFunction.sql @@ -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; \ No newline at end of file diff --git a/test/parser/flinksql/syntax/fixtures/alterTable.sql b/test/parser/flinksql/syntax/fixtures/alterTable.sql new file mode 100644 index 0000000..aca4348 --- /dev/null +++ b/test/parser/flinksql/syntax/fixtures/alterTable.sql @@ -0,0 +1,7 @@ +ALTER TABLE + Orders RENAME TO NewOrders; + +ALTER TABLE + sample_table +SET + ('key1' = 'value2'); \ No newline at end of file diff --git a/test/parser/flinksql/syntax/fixtures/alterView.sql b/test/parser/flinksql/syntax/fixtures/alterView.sql new file mode 100644 index 0000000..e04d15c --- /dev/null +++ b/test/parser/flinksql/syntax/fixtures/alterView.sql @@ -0,0 +1,8 @@ +ALTER VIEW v1 RENAME TO v2; + +ALTER VIEW v1 AS +SELECT + c1, + c2 +FROM + tbl; \ No newline at end of file