fix: trino validation (#248)
* fix: #246 program does not match standaloneClause * test: patch unit tests
This commit is contained in:
parent
30b7f27486
commit
1038a3a828
@ -17,7 +17,6 @@
|
||||
* Reference: https://github.com/trinodb/trino/blob/385/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4
|
||||
*/
|
||||
|
||||
|
||||
// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
|
||||
// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging
|
||||
// $antlr-format spaceBeforeAssignmentOperators false, keepEmptyLinesAtTheStartOfBlocks true
|
||||
@ -35,7 +34,10 @@ program
|
||||
|
||||
statements
|
||||
: singleStatement
|
||||
| standaloneExpression
|
||||
;
|
||||
|
||||
standaloneClause
|
||||
: standaloneExpression
|
||||
| standalonePathSpecification
|
||||
| standaloneType
|
||||
| standaloneRowPattern
|
||||
|
File diff suppressed because one or more lines are too long
@ -203,6 +203,7 @@ import { LogicalNotContext } from "./TrinoSqlParser";
|
||||
import { LogicalBinaryContext } from "./TrinoSqlParser";
|
||||
import { ProgramContext } from "./TrinoSqlParser";
|
||||
import { StatementsContext } from "./TrinoSqlParser";
|
||||
import { StandaloneClauseContext } from "./TrinoSqlParser";
|
||||
import { SingleStatementContext } from "./TrinoSqlParser";
|
||||
import { StandaloneExpressionContext } from "./TrinoSqlParser";
|
||||
import { StandalonePathSpecificationContext } from "./TrinoSqlParser";
|
||||
@ -2912,6 +2913,17 @@ export interface TrinoSqlListener extends ParseTreeListener {
|
||||
*/
|
||||
exitStatements?: (ctx: StatementsContext) => void;
|
||||
|
||||
/**
|
||||
* Enter a parse tree produced by `TrinoSqlParser.standaloneClause`.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
enterStandaloneClause?: (ctx: StandaloneClauseContext) => void;
|
||||
/**
|
||||
* Exit a parse tree produced by `TrinoSqlParser.standaloneClause`.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
exitStandaloneClause?: (ctx: StandaloneClauseContext) => void;
|
||||
|
||||
/**
|
||||
* Enter a parse tree produced by `TrinoSqlParser.singleStatement`.
|
||||
* @param ctx the parse tree
|
||||
|
File diff suppressed because one or more lines are too long
@ -203,6 +203,7 @@ import { LogicalNotContext } from "./TrinoSqlParser";
|
||||
import { LogicalBinaryContext } from "./TrinoSqlParser";
|
||||
import { ProgramContext } from "./TrinoSqlParser";
|
||||
import { StatementsContext } from "./TrinoSqlParser";
|
||||
import { StandaloneClauseContext } from "./TrinoSqlParser";
|
||||
import { SingleStatementContext } from "./TrinoSqlParser";
|
||||
import { StandaloneExpressionContext } from "./TrinoSqlParser";
|
||||
import { StandalonePathSpecificationContext } from "./TrinoSqlParser";
|
||||
@ -1917,6 +1918,13 @@ export interface TrinoSqlVisitor<Result> extends ParseTreeVisitor<Result> {
|
||||
*/
|
||||
visitStatements?: (ctx: StatementsContext) => Result;
|
||||
|
||||
/**
|
||||
* Visit a parse tree produced by `TrinoSqlParser.standaloneClause`.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
visitStandaloneClause?: (ctx: StandaloneClauseContext) => Result;
|
||||
|
||||
/**
|
||||
* Visit a parse tree produced by `TrinoSqlParser.singleStatement`.
|
||||
* @param ctx the parse tree
|
||||
|
16
test/parser/flinksql/validateInvalidSql.test.ts
Normal file
16
test/parser/flinksql/validateInvalidSql.test.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { FlinkSQL } from '../../filters';
|
||||
|
||||
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
|
||||
const unCompleteSQL = `CREATE TABLE`;
|
||||
|
||||
describe('Flink SQL validate invalid sql', () => {
|
||||
const parser = new FlinkSQL();
|
||||
|
||||
test('validate random text', () => {
|
||||
expect(parser.validate(randomText).length).not.toBe(0);
|
||||
});
|
||||
|
||||
test('validate unComplete sql', () => {
|
||||
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
|
||||
});
|
||||
});
|
16
test/parser/hive/validateInvalidSql.test.ts
Normal file
16
test/parser/hive/validateInvalidSql.test.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { HiveSQL } from '../../filters';
|
||||
|
||||
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
|
||||
const unCompleteSQL = `CREATE TABLE`;
|
||||
|
||||
describe('Hive SQL validate invalid sql', () => {
|
||||
const parser = new HiveSQL();
|
||||
|
||||
test('validate random text', () => {
|
||||
expect(parser.validate(randomText).length).not.toBe(0);
|
||||
});
|
||||
|
||||
test('validate unComplete sql', () => {
|
||||
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
|
||||
});
|
||||
});
|
16
test/parser/impala/validateInvalidSql.test.ts
Normal file
16
test/parser/impala/validateInvalidSql.test.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { ImpalaSQL } from '../../filters';
|
||||
|
||||
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
|
||||
const unCompleteSQL = `CREATE TABLE`;
|
||||
|
||||
describe('Impala SQL validate invalid sql', () => {
|
||||
const parser = new ImpalaSQL();
|
||||
|
||||
test('validate random text', () => {
|
||||
expect(parser.validate(randomText).length).not.toBe(0);
|
||||
});
|
||||
|
||||
test('validate unComplete sql', () => {
|
||||
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
|
||||
});
|
||||
});
|
16
test/parser/mysql/validateInvalidSql.test.ts
Normal file
16
test/parser/mysql/validateInvalidSql.test.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { MySQL } from '../../filters';
|
||||
|
||||
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
|
||||
const unCompleteSQL = `CREATE TABLE`;
|
||||
|
||||
describe('MySQL validate invalid sql', () => {
|
||||
const parser = new MySQL();
|
||||
|
||||
test('validate random text', () => {
|
||||
expect(parser.validate(randomText).length).not.toBe(0);
|
||||
});
|
||||
|
||||
test('validate unComplete sql', () => {
|
||||
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
|
||||
});
|
||||
});
|
16
test/parser/pgsql/validateInvalidSql.test.ts
Normal file
16
test/parser/pgsql/validateInvalidSql.test.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { PostgresSQL } from '../../filters';
|
||||
|
||||
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
|
||||
const unCompleteSQL = `CREATE TABLE`;
|
||||
|
||||
describe('Postgres SQL validate invalid sql', () => {
|
||||
const parser = new PostgresSQL();
|
||||
|
||||
test('validate random text', () => {
|
||||
expect(parser.validate(randomText).length).not.toBe(0);
|
||||
});
|
||||
|
||||
test('validate unComplete sql', () => {
|
||||
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
|
||||
});
|
||||
});
|
16
test/parser/spark/validateInvalidSql.test.ts
Normal file
16
test/parser/spark/validateInvalidSql.test.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { SparkSQL } from '../../filters';
|
||||
|
||||
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
|
||||
const unCompleteSQL = `CREATE TABLE`;
|
||||
|
||||
describe('Spark SQL validate invalid sql', () => {
|
||||
const parser = new SparkSQL();
|
||||
|
||||
test('validate random text', () => {
|
||||
expect(parser.validate(randomText).length).not.toBe(0);
|
||||
});
|
||||
|
||||
test('validate unComplete sql', () => {
|
||||
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
|
||||
});
|
||||
});
|
@ -50,9 +50,6 @@ describe('Trino SQL Syntax Suggestion', () => {
|
||||
expect(
|
||||
syntaxes.some((item) => item.syntaxContextType === SyntaxContextType.VIEW)
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
syntaxes.some((item) => item.syntaxContextType === SyntaxContextType.FUNCTION)
|
||||
).toBeTruthy();
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['db', '.']);
|
||||
});
|
||||
@ -191,9 +188,6 @@ describe('Trino SQL Syntax Suggestion', () => {
|
||||
expect(
|
||||
syntaxes.some((item) => item.syntaxContextType === SyntaxContextType.VIEW)
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
syntaxes.some((item) => item.syntaxContextType === SyntaxContextType.FUNCTION)
|
||||
).toBeTruthy();
|
||||
expect(suggestion).not.toBeUndefined();
|
||||
expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['tb']);
|
||||
});
|
||||
|
16
test/parser/trinosql/validateInvalidSql.test.ts
Normal file
16
test/parser/trinosql/validateInvalidSql.test.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { TrinoSQL } from '../../filters';
|
||||
|
||||
const randomText = `dhsdansdnkla ndjnsla ndnalks`;
|
||||
const unCompleteSQL = `CREATE TABLE`;
|
||||
|
||||
describe('Trino SQL validate invalid sql', () => {
|
||||
const parser = new TrinoSQL();
|
||||
|
||||
test('validate random text', () => {
|
||||
expect(parser.validate(randomText).length).not.toBe(0);
|
||||
});
|
||||
|
||||
test('validate unComplete sql', () => {
|
||||
expect(parser.validate(unCompleteSQL).length).not.toBe(0);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user