Skip to content

Commit 1038a3a

Browse files
authored
fix: trino validation (#248)
* fix: #246 program does not match standaloneClause * test: patch unit tests
1 parent 30b7f27 commit 1038a3a

13 files changed

Lines changed: 3729 additions & 3514 deletions

src/grammar/trinosql/TrinoSql.g4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* Reference: https://github.com/trinodb/trino/blob/385/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4
1818
*/
1919

20-
2120
// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
2221
// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging
2322
// $antlr-format spaceBeforeAssignmentOperators false, keepEmptyLinesAtTheStartOfBlocks true
@@ -35,7 +34,10 @@ program
3534

3635
statements
3736
: singleStatement
38-
| standaloneExpression
37+
;
38+
39+
standaloneClause
40+
: standaloneExpression
3941
| standalonePathSpecification
4042
| standaloneType
4143
| standaloneRowPattern

src/lib/trinosql/TrinoSql.interp

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

src/lib/trinosql/TrinoSqlListener.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ import { LogicalNotContext } from "./TrinoSqlParser";
203203
import { LogicalBinaryContext } from "./TrinoSqlParser";
204204
import { ProgramContext } from "./TrinoSqlParser";
205205
import { StatementsContext } from "./TrinoSqlParser";
206+
import { StandaloneClauseContext } from "./TrinoSqlParser";
206207
import { SingleStatementContext } from "./TrinoSqlParser";
207208
import { StandaloneExpressionContext } from "./TrinoSqlParser";
208209
import { StandalonePathSpecificationContext } from "./TrinoSqlParser";
@@ -2912,6 +2913,17 @@ export interface TrinoSqlListener extends ParseTreeListener {
29122913
*/
29132914
exitStatements?: (ctx: StatementsContext) => void;
29142915

2916+
/**
2917+
* Enter a parse tree produced by `TrinoSqlParser.standaloneClause`.
2918+
* @param ctx the parse tree
2919+
*/
2920+
enterStandaloneClause?: (ctx: StandaloneClauseContext) => void;
2921+
/**
2922+
* Exit a parse tree produced by `TrinoSqlParser.standaloneClause`.
2923+
* @param ctx the parse tree
2924+
*/
2925+
exitStandaloneClause?: (ctx: StandaloneClauseContext) => void;
2926+
29152927
/**
29162928
* Enter a parse tree produced by `TrinoSqlParser.singleStatement`.
29172929
* @param ctx the parse tree

src/lib/trinosql/TrinoSqlParser.ts

Lines changed: 3591 additions & 3505 deletions
Large diffs are not rendered by default.

src/lib/trinosql/TrinoSqlVisitor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ import { LogicalNotContext } from "./TrinoSqlParser";
203203
import { LogicalBinaryContext } from "./TrinoSqlParser";
204204
import { ProgramContext } from "./TrinoSqlParser";
205205
import { StatementsContext } from "./TrinoSqlParser";
206+
import { StandaloneClauseContext } from "./TrinoSqlParser";
206207
import { SingleStatementContext } from "./TrinoSqlParser";
207208
import { StandaloneExpressionContext } from "./TrinoSqlParser";
208209
import { StandalonePathSpecificationContext } from "./TrinoSqlParser";
@@ -1917,6 +1918,13 @@ export interface TrinoSqlVisitor<Result> extends ParseTreeVisitor<Result> {
19171918
*/
19181919
visitStatements?: (ctx: StatementsContext) => Result;
19191920

1921+
/**
1922+
* Visit a parse tree produced by `TrinoSqlParser.standaloneClause`.
1923+
* @param ctx the parse tree
1924+
* @return the visitor result
1925+
*/
1926+
visitStandaloneClause?: (ctx: StandaloneClauseContext) => Result;
1927+
19201928
/**
19211929
* Visit a parse tree produced by `TrinoSqlParser.singleStatement`.
19221930
* @param ctx the parse tree
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { FlinkSQL } from '../../filters';
2+
3+
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
4+
const unCompleteSQL = `CREATE TABLE`;
5+
6+
describe('Flink SQL validate invalid sql', () => {
7+
const parser = new FlinkSQL();
8+
9+
test('validate random text', () => {
10+
expect(parser.validate(randomText).length).not.toBe(0);
11+
});
12+
13+
test('validate unComplete sql', () => {
14+
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { HiveSQL } from '../../filters';
2+
3+
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
4+
const unCompleteSQL = `CREATE TABLE`;
5+
6+
describe('Hive SQL validate invalid sql', () => {
7+
const parser = new HiveSQL();
8+
9+
test('validate random text', () => {
10+
expect(parser.validate(randomText).length).not.toBe(0);
11+
});
12+
13+
test('validate unComplete sql', () => {
14+
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ImpalaSQL } from '../../filters';
2+
3+
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
4+
const unCompleteSQL = `CREATE TABLE`;
5+
6+
describe('Impala SQL validate invalid sql', () => {
7+
const parser = new ImpalaSQL();
8+
9+
test('validate random text', () => {
10+
expect(parser.validate(randomText).length).not.toBe(0);
11+
});
12+
13+
test('validate unComplete sql', () => {
14+
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { MySQL } from '../../filters';
2+
3+
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
4+
const unCompleteSQL = `CREATE TABLE`;
5+
6+
describe('MySQL validate invalid sql', () => {
7+
const parser = new MySQL();
8+
9+
test('validate random text', () => {
10+
expect(parser.validate(randomText).length).not.toBe(0);
11+
});
12+
13+
test('validate unComplete sql', () => {
14+
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { PostgresSQL } from '../../filters';
2+
3+
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
4+
const unCompleteSQL = `CREATE TABLE`;
5+
6+
describe('Postgres SQL validate invalid sql', () => {
7+
const parser = new PostgresSQL();
8+
9+
test('validate random text', () => {
10+
expect(parser.validate(randomText).length).not.toBe(0);
11+
});
12+
13+
test('validate unComplete sql', () => {
14+
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
15+
});
16+
});

0 commit comments

Comments
 (0)