2024-03-26 14:28:27 +08:00
|
|
|
import TrinoSQL from 'src/parser/trino';
|
2024-01-19 21:10:00 +08:00
|
|
|
import { readSQL } from 'test/helper';
|
2023-05-24 15:07:02 +08:00
|
|
|
|
|
|
|
const features = {
|
|
|
|
select: readSQL(__dirname, 'select.sql'),
|
|
|
|
selectWithClause: readSQL(__dirname, 'select_with_clause.sql'),
|
|
|
|
selectWithSetOperations: readSQL(__dirname, 'select_with_set_operations.sql'),
|
|
|
|
selectWithSubQueries: readSQL(__dirname, 'select_with_sub_queries.sql'),
|
|
|
|
selectWithTableSample: readSQL(__dirname, 'select_with_table_sample.sql'),
|
|
|
|
selectWithRowType: readSQL(__dirname, 'select_with_row_type.sql'),
|
|
|
|
selectWithOffset: readSQL(__dirname, 'select_with_offset.sql'),
|
|
|
|
selectWithJoin: readSQL(__dirname, 'select_with_join.sql'),
|
|
|
|
selectWithFetch: readSQL(__dirname, 'select_with_fetch.sql'),
|
|
|
|
selectWithUNNEST: readSQL(__dirname, 'select_with_ unnest.sql'),
|
|
|
|
selectWithExists: readSQL(__dirname, 'select_with_exists.sql'),
|
2023-10-13 11:16:36 +08:00
|
|
|
selectWithUnion: readSQL(__dirname, 'select_with_union.sql'),
|
2023-05-24 15:07:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('TrinoSQL Select Statements Syntax Tests', () => {
|
|
|
|
const parser = new TrinoSQL();
|
2023-10-13 11:16:36 +08:00
|
|
|
features.select.forEach((sql) => {
|
2023-05-24 15:07:02 +08:00
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
features.selectWithClause.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
features.selectWithSetOperations.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
|
|
|
|
features.selectWithSubQueries.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
features.selectWithTableSample.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
features.selectWithRowType.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
features.selectWithOffset.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
features.selectWithJoin.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
features.selectWithFetch.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
features.selectWithUNNEST.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
|
|
|
features.selectWithExists.forEach((sql) => {
|
2023-05-24 15:07:02 +08:00
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
features.selectWithUnion.forEach((sql) => {
|
|
|
|
it(sql, () => {
|
|
|
|
expect(parser.validate(sql).length).toBe(0);
|
|
|
|
});
|
2023-10-13 11:16:36 +08:00
|
|
|
});
|
2023-05-24 15:07:02 +08:00
|
|
|
});
|