lava-oushudb-dt-sql-parser/test/parser/flinksql/syntax.test.ts

79 lines
2.6 KiB
TypeScript
Raw Normal View History

2020-10-22 19:57:13 +08:00
import SQLParser from '../../../src/parser/flinksql';
describe('FlinkSQL Syntax Tests', () => {
const parser = new SQLParser();
// Create statements
2020-10-22 19:57:13 +08:00
test('Test simple CreateTable Statement', () => {
const sql = `
CREATE TABLE Orders (
2020-10-23 17:52:43 +08:00
user BIGINT
2020-10-22 19:57:13 +08:00
) WITH (
"connector" = "kafka",
"scan.startup.mode" = "earliest-offset"
);
`;
const result = parser.validate(sql);
// TODO find parser error
expect(result.length).toBe(1);
});
test('Test simple CreateDatabase Statement', () => {
const sql = `
CREATE DATABASE IF NOT EXISTS dataApi
WITH (
"owner" = "admin"
);
`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
});
// test('Test simple CreateView Statement', () => {
// const sql = `
// CREATE TEMPORARY VIEW IF NOT EXISTS tempView
// AS ;
// `;
// const result = parser.validate(sql);
// expect(result.length).toBe(0);
// });
// Alter statements
test('Test simple AlterTable Statement', () => {
const sql = `ALTER TABLE Orders RENAME TO NewOrders;`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
});
test('Test simple AlterDatabase Statement', () => {
const sql = `ALTER DATABASE DataBase SET ("key1"="value1");`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
});
// Drop statements
test('Test simple DropTable Statement', () => {
const sql = `DROP TABLE IF EXISTS Orders;`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
});
test('Test simple DropDatabase Statement', () => {
const sql = `DROP DATABASE IF EXISTS Orders RESTRICT;`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
});
test('Test simple DropView Statement', () => {
const sql = `DROP TEMPORARY VIEW IF EXISTS Orders;`;
const result = parser.validate(sql);
expect(result.length).toBe(0);
});
test('Test simple DropFunction Statement', () => {
const sql = `DROP TEMPORARY FUNCTION IF EXISTS Orders;`;
const result = parser.validate(sql);
2020-10-22 19:57:13 +08:00
expect(result.length).toBe(0);
});
2020-11-11 19:58:14 +08:00
test('Test simple Select Statement', () => {
const sql = ` SELECT product, amount FROM Orders;`;
const result = parser.validate(sql);
console.log(result);
expect(result.length).toBe(0);
});
2020-10-22 19:57:13 +08:00
});