Optimize/auto complete (#178)
* feat: optimize hive function name auto complete * feat: optimize flink rules that c3 prefer to * feat: optimize flink autoComplete * test: flink auto complete unit tests
This commit is contained in:
parent
c4030929b2
commit
53ead45ff5
@ -63,9 +63,9 @@ useModuleStatement
|
|||||||
showStatememt
|
showStatememt
|
||||||
: KW_SHOW (KW_CATALOGS | KW_DATABASES | KW_VIEWS | KW_JARS)
|
: KW_SHOW (KW_CATALOGS | KW_DATABASES | KW_VIEWS | KW_JARS)
|
||||||
| KW_SHOW KW_CURRENT (KW_CATALOG | KW_DATABASE)
|
| KW_SHOW KW_CURRENT (KW_CATALOG | KW_DATABASE)
|
||||||
| KW_SHOW KW_TABLES (( KW_FROM | KW_IN ) tablePath)? likePredicate?
|
| KW_SHOW KW_TABLES (( KW_FROM | KW_IN ) databasePath)? likePredicate?
|
||||||
| KW_SHOW KW_COLUMNS ( KW_FROM | KW_IN ) uid likePredicate?
|
| KW_SHOW KW_COLUMNS ( KW_FROM | KW_IN ) (viewPath| tablePath) likePredicate?
|
||||||
| KW_SHOW KW_CREATE (KW_TABLE | KW_VIEW) uid
|
| KW_SHOW KW_CREATE (KW_TABLE tablePath | KW_VIEW viewPath)
|
||||||
| KW_SHOW KW_USER? KW_FUNCTIONS
|
| KW_SHOW KW_USER? KW_FUNCTIONS
|
||||||
| KW_SHOW KW_FULL? KW_MODULES
|
| KW_SHOW KW_FULL? KW_MODULES
|
||||||
;
|
;
|
||||||
@ -258,7 +258,7 @@ likeOption
|
|||||||
;
|
;
|
||||||
|
|
||||||
createCatalog
|
createCatalog
|
||||||
: KW_CREATE KW_CATALOG uid withOption
|
: KW_CREATE KW_CATALOG catalogPathCreate withOption
|
||||||
;
|
;
|
||||||
|
|
||||||
createDatabase
|
createDatabase
|
||||||
@ -266,11 +266,11 @@ createDatabase
|
|||||||
;
|
;
|
||||||
|
|
||||||
createView
|
createView
|
||||||
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? uid columnNameList? commentSpec? KW_AS queryStatement
|
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? viewPathCreate columnNameList? commentSpec? KW_AS queryStatement
|
||||||
;
|
;
|
||||||
|
|
||||||
createFunction
|
createFunction
|
||||||
: KW_CREATE (KW_TEMPORARY|KW_TEMPORARY KW_SYSTEM)? KW_FUNCTION ifNotExists? functionName KW_AS identifier (KW_LANGUAGE (KW_JAVA|KW_SCALA|KW_PYTHON))? usingClause?
|
: KW_CREATE (KW_TEMPORARY|KW_TEMPORARY KW_SYSTEM)? KW_FUNCTION ifNotExists? functionNameCreate KW_AS identifier (KW_LANGUAGE (KW_JAVA|KW_SCALA|KW_PYTHON))? usingClause?
|
||||||
;
|
;
|
||||||
|
|
||||||
usingClause
|
usingClause
|
||||||
@ -314,7 +314,7 @@ notForced
|
|||||||
;
|
;
|
||||||
|
|
||||||
alertView
|
alertView
|
||||||
: KW_ALTER KW_VIEW uid (renameDefinition | KW_AS queryStatement)
|
: KW_ALTER KW_VIEW viewPath (renameDefinition | KW_AS queryStatement)
|
||||||
;
|
;
|
||||||
|
|
||||||
alterDatabase
|
alterDatabase
|
||||||
@ -322,7 +322,7 @@ alterDatabase
|
|||||||
;
|
;
|
||||||
|
|
||||||
alterFunction
|
alterFunction
|
||||||
: KW_ALTER (KW_TEMPORARY|KW_TEMPORARY KW_SYSTEM)? KW_FUNCTION ifExists? uid KW_AS identifier (KW_LANGUAGE (KW_JAVA|KW_SCALA|KW_PYTHON))?
|
: KW_ALTER (KW_TEMPORARY|KW_TEMPORARY KW_SYSTEM)? KW_FUNCTION ifExists? functionName KW_AS identifier (KW_LANGUAGE (KW_JAVA|KW_SCALA|KW_PYTHON))? // TODO
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ dropDatabase
|
|||||||
;
|
;
|
||||||
|
|
||||||
dropView
|
dropView
|
||||||
: KW_DROP KW_TEMPORARY? KW_VIEW ifExists? uid
|
: KW_DROP KW_TEMPORARY? KW_VIEW ifExists? viewPath
|
||||||
;
|
;
|
||||||
|
|
||||||
dropFunction
|
dropFunction
|
||||||
@ -450,13 +450,12 @@ tableReference
|
|||||||
|
|
||||||
tablePrimary
|
tablePrimary
|
||||||
: KW_TABLE? tablePath systemTimePeriod? (KW_AS? correlationName)?
|
: KW_TABLE? tablePath systemTimePeriod? (KW_AS? correlationName)?
|
||||||
|
| viewPath systemTimePeriod? (KW_AS? correlationName)?
|
||||||
| KW_LATERAL KW_TABLE LR_BRACKET functionName LR_BRACKET functionParam (COMMA functionParam)* RR_BRACKET RR_BRACKET
|
| KW_LATERAL KW_TABLE LR_BRACKET functionName LR_BRACKET functionParam (COMMA functionParam)* RR_BRACKET RR_BRACKET
|
||||||
| KW_LATERAL? LR_BRACKET queryStatement RR_BRACKET
|
| KW_LATERAL? LR_BRACKET queryStatement RR_BRACKET
|
||||||
| KW_UNNEST LR_BRACKET expression RR_BRACKET
|
| KW_UNNEST LR_BRACKET expression RR_BRACKET
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
systemTimePeriod
|
systemTimePeriod
|
||||||
: KW_FOR KW_SYSTEM_TIME KW_AS KW_OF dateTimeExpression
|
: KW_FOR KW_SYSTEM_TIME KW_AS KW_OF dateTimeExpression
|
||||||
;
|
;
|
||||||
@ -731,6 +730,10 @@ primaryExpression
|
|||||||
// KW_FROM position=valueExpression (KW_FOR length=valueExpression)? ')' #overlay
|
// KW_FROM position=valueExpression (KW_FOR length=valueExpression)? ')' #overlay
|
||||||
;
|
;
|
||||||
|
|
||||||
|
functionNameCreate
|
||||||
|
: uid
|
||||||
|
;
|
||||||
|
|
||||||
functionName
|
functionName
|
||||||
: reservedKeywordsUsedAsFuncName
|
: reservedKeywordsUsedAsFuncName
|
||||||
| nonReservedKeywords
|
| nonReservedKeywords
|
||||||
@ -827,23 +830,39 @@ whenClause
|
|||||||
;
|
;
|
||||||
|
|
||||||
catalogPath
|
catalogPath
|
||||||
: uid
|
: identifier
|
||||||
|
;
|
||||||
|
|
||||||
|
catalogPathCreate
|
||||||
|
: identifier
|
||||||
;
|
;
|
||||||
|
|
||||||
databasePath
|
databasePath
|
||||||
: uid
|
: identifier (DOT identifier)?
|
||||||
;
|
;
|
||||||
|
|
||||||
databasePathCreate
|
databasePathCreate
|
||||||
: uid
|
: identifier (DOT identifier)?
|
||||||
;
|
;
|
||||||
|
|
||||||
tablePathCreate
|
tablePathCreate
|
||||||
: uid
|
: identifier (DOT identifier)?
|
||||||
|
| identifier DOT identifier (DOT identifier)?
|
||||||
;
|
;
|
||||||
|
|
||||||
tablePath
|
tablePath
|
||||||
: uid
|
: identifier (DOT identifier)?
|
||||||
|
| identifier DOT identifier (DOT identifier)?
|
||||||
|
;
|
||||||
|
|
||||||
|
viewPath
|
||||||
|
: identifier (DOT identifier)?
|
||||||
|
| identifier DOT identifier (DOT identifier)?
|
||||||
|
;
|
||||||
|
|
||||||
|
viewPathCreate
|
||||||
|
: identifier (DOT identifier)?
|
||||||
|
| identifier DOT identifier (DOT identifier)?
|
||||||
;
|
;
|
||||||
|
|
||||||
uid
|
uid
|
||||||
|
@ -2177,25 +2177,29 @@ null_treatment
|
|||||||
| KW_IGNORE KW_NULLS
|
| KW_IGNORE KW_NULLS
|
||||||
;
|
;
|
||||||
|
|
||||||
functionNameForDDL
|
functionNameCreate
|
||||||
: functionNameForInvoke
|
: functionIdentifier
|
||||||
|
;
|
||||||
|
|
||||||
|
functionNameForDDL // Function name use to DDL, such as drop function
|
||||||
|
: userDefinedFuncName
|
||||||
| StringLiteral
|
| StringLiteral
|
||||||
;
|
;
|
||||||
|
|
||||||
functionNameForInvoke
|
functionNameForInvoke // Function name used to invoke
|
||||||
: userDefinedFuncName
|
: userDefinedFuncName
|
||||||
| sql11ReservedKeywordsUsedAsFunctionName
|
| internalFunctionName
|
||||||
|
;
|
||||||
|
|
||||||
|
userDefinedFuncName // User Defined Function
|
||||||
|
: functionIdentifier
|
||||||
|
;
|
||||||
|
|
||||||
|
internalFunctionName // Hive Internal Function
|
||||||
|
: sql11ReservedKeywordsUsedAsFunctionName
|
||||||
| sysFuncNames
|
| sysFuncNames
|
||||||
;
|
;
|
||||||
|
|
||||||
userDefinedFuncName
|
|
||||||
: functionIdentifier
|
|
||||||
;
|
|
||||||
|
|
||||||
functionNameCreate
|
|
||||||
: functionIdentifier
|
|
||||||
;
|
|
||||||
|
|
||||||
castExpression
|
castExpression
|
||||||
: KW_CAST
|
: KW_CAST
|
||||||
LPAREN
|
LPAREN
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -169,6 +169,7 @@ import { PredicateContext } from "./FlinkSqlParser";
|
|||||||
import { LikePredicateContext } from "./FlinkSqlParser";
|
import { LikePredicateContext } from "./FlinkSqlParser";
|
||||||
import { ValueExpressionContext } from "./FlinkSqlParser";
|
import { ValueExpressionContext } from "./FlinkSqlParser";
|
||||||
import { PrimaryExpressionContext } from "./FlinkSqlParser";
|
import { PrimaryExpressionContext } from "./FlinkSqlParser";
|
||||||
|
import { FunctionNameCreateContext } from "./FlinkSqlParser";
|
||||||
import { FunctionNameContext } from "./FlinkSqlParser";
|
import { FunctionNameContext } from "./FlinkSqlParser";
|
||||||
import { FunctionParamContext } from "./FlinkSqlParser";
|
import { FunctionParamContext } from "./FlinkSqlParser";
|
||||||
import { DereferenceDefinitionContext } from "./FlinkSqlParser";
|
import { DereferenceDefinitionContext } from "./FlinkSqlParser";
|
||||||
@ -191,10 +192,13 @@ import { UnquotedIdentifierContext } from "./FlinkSqlParser";
|
|||||||
import { QuotedIdentifierContext } from "./FlinkSqlParser";
|
import { QuotedIdentifierContext } from "./FlinkSqlParser";
|
||||||
import { WhenClauseContext } from "./FlinkSqlParser";
|
import { WhenClauseContext } from "./FlinkSqlParser";
|
||||||
import { CatalogPathContext } from "./FlinkSqlParser";
|
import { CatalogPathContext } from "./FlinkSqlParser";
|
||||||
|
import { CatalogPathCreateContext } from "./FlinkSqlParser";
|
||||||
import { DatabasePathContext } from "./FlinkSqlParser";
|
import { DatabasePathContext } from "./FlinkSqlParser";
|
||||||
import { DatabasePathCreateContext } from "./FlinkSqlParser";
|
import { DatabasePathCreateContext } from "./FlinkSqlParser";
|
||||||
import { TablePathCreateContext } from "./FlinkSqlParser";
|
import { TablePathCreateContext } from "./FlinkSqlParser";
|
||||||
import { TablePathContext } from "./FlinkSqlParser";
|
import { TablePathContext } from "./FlinkSqlParser";
|
||||||
|
import { ViewPathContext } from "./FlinkSqlParser";
|
||||||
|
import { ViewPathCreateContext } from "./FlinkSqlParser";
|
||||||
import { UidContext } from "./FlinkSqlParser";
|
import { UidContext } from "./FlinkSqlParser";
|
||||||
import { WithOptionContext } from "./FlinkSqlParser";
|
import { WithOptionContext } from "./FlinkSqlParser";
|
||||||
import { IfNotExistsContext } from "./FlinkSqlParser";
|
import { IfNotExistsContext } from "./FlinkSqlParser";
|
||||||
@ -2115,6 +2119,17 @@ export interface FlinkSqlParserListener extends ParseTreeListener {
|
|||||||
*/
|
*/
|
||||||
exitPrimaryExpression?: (ctx: PrimaryExpressionContext) => void;
|
exitPrimaryExpression?: (ctx: PrimaryExpressionContext) => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter a parse tree produced by `FlinkSqlParser.functionNameCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
enterFunctionNameCreate?: (ctx: FunctionNameCreateContext) => void;
|
||||||
|
/**
|
||||||
|
* Exit a parse tree produced by `FlinkSqlParser.functionNameCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
exitFunctionNameCreate?: (ctx: FunctionNameCreateContext) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by `FlinkSqlParser.functionName`.
|
* Enter a parse tree produced by `FlinkSqlParser.functionName`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
@ -2357,6 +2372,17 @@ export interface FlinkSqlParserListener extends ParseTreeListener {
|
|||||||
*/
|
*/
|
||||||
exitCatalogPath?: (ctx: CatalogPathContext) => void;
|
exitCatalogPath?: (ctx: CatalogPathContext) => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter a parse tree produced by `FlinkSqlParser.catalogPathCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
enterCatalogPathCreate?: (ctx: CatalogPathCreateContext) => void;
|
||||||
|
/**
|
||||||
|
* Exit a parse tree produced by `FlinkSqlParser.catalogPathCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
exitCatalogPathCreate?: (ctx: CatalogPathCreateContext) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by `FlinkSqlParser.databasePath`.
|
* Enter a parse tree produced by `FlinkSqlParser.databasePath`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
@ -2401,6 +2427,28 @@ export interface FlinkSqlParserListener extends ParseTreeListener {
|
|||||||
*/
|
*/
|
||||||
exitTablePath?: (ctx: TablePathContext) => void;
|
exitTablePath?: (ctx: TablePathContext) => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter a parse tree produced by `FlinkSqlParser.viewPath`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
enterViewPath?: (ctx: ViewPathContext) => void;
|
||||||
|
/**
|
||||||
|
* Exit a parse tree produced by `FlinkSqlParser.viewPath`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
exitViewPath?: (ctx: ViewPathContext) => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter a parse tree produced by `FlinkSqlParser.viewPathCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
enterViewPathCreate?: (ctx: ViewPathCreateContext) => void;
|
||||||
|
/**
|
||||||
|
* Exit a parse tree produced by `FlinkSqlParser.viewPathCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
exitViewPathCreate?: (ctx: ViewPathCreateContext) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by `FlinkSqlParser.uid`.
|
* Enter a parse tree produced by `FlinkSqlParser.uid`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
|
@ -169,6 +169,7 @@ import { PredicateContext } from "./FlinkSqlParser";
|
|||||||
import { LikePredicateContext } from "./FlinkSqlParser";
|
import { LikePredicateContext } from "./FlinkSqlParser";
|
||||||
import { ValueExpressionContext } from "./FlinkSqlParser";
|
import { ValueExpressionContext } from "./FlinkSqlParser";
|
||||||
import { PrimaryExpressionContext } from "./FlinkSqlParser";
|
import { PrimaryExpressionContext } from "./FlinkSqlParser";
|
||||||
|
import { FunctionNameCreateContext } from "./FlinkSqlParser";
|
||||||
import { FunctionNameContext } from "./FlinkSqlParser";
|
import { FunctionNameContext } from "./FlinkSqlParser";
|
||||||
import { FunctionParamContext } from "./FlinkSqlParser";
|
import { FunctionParamContext } from "./FlinkSqlParser";
|
||||||
import { DereferenceDefinitionContext } from "./FlinkSqlParser";
|
import { DereferenceDefinitionContext } from "./FlinkSqlParser";
|
||||||
@ -191,10 +192,13 @@ import { UnquotedIdentifierContext } from "./FlinkSqlParser";
|
|||||||
import { QuotedIdentifierContext } from "./FlinkSqlParser";
|
import { QuotedIdentifierContext } from "./FlinkSqlParser";
|
||||||
import { WhenClauseContext } from "./FlinkSqlParser";
|
import { WhenClauseContext } from "./FlinkSqlParser";
|
||||||
import { CatalogPathContext } from "./FlinkSqlParser";
|
import { CatalogPathContext } from "./FlinkSqlParser";
|
||||||
|
import { CatalogPathCreateContext } from "./FlinkSqlParser";
|
||||||
import { DatabasePathContext } from "./FlinkSqlParser";
|
import { DatabasePathContext } from "./FlinkSqlParser";
|
||||||
import { DatabasePathCreateContext } from "./FlinkSqlParser";
|
import { DatabasePathCreateContext } from "./FlinkSqlParser";
|
||||||
import { TablePathCreateContext } from "./FlinkSqlParser";
|
import { TablePathCreateContext } from "./FlinkSqlParser";
|
||||||
import { TablePathContext } from "./FlinkSqlParser";
|
import { TablePathContext } from "./FlinkSqlParser";
|
||||||
|
import { ViewPathContext } from "./FlinkSqlParser";
|
||||||
|
import { ViewPathCreateContext } from "./FlinkSqlParser";
|
||||||
import { UidContext } from "./FlinkSqlParser";
|
import { UidContext } from "./FlinkSqlParser";
|
||||||
import { WithOptionContext } from "./FlinkSqlParser";
|
import { WithOptionContext } from "./FlinkSqlParser";
|
||||||
import { IfNotExistsContext } from "./FlinkSqlParser";
|
import { IfNotExistsContext } from "./FlinkSqlParser";
|
||||||
@ -1423,6 +1427,13 @@ export interface FlinkSqlParserVisitor<Result> extends ParseTreeVisitor<Result>
|
|||||||
*/
|
*/
|
||||||
visitPrimaryExpression?: (ctx: PrimaryExpressionContext) => Result;
|
visitPrimaryExpression?: (ctx: PrimaryExpressionContext) => Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visit a parse tree produced by `FlinkSqlParser.functionNameCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
* @return the visitor result
|
||||||
|
*/
|
||||||
|
visitFunctionNameCreate?: (ctx: FunctionNameCreateContext) => Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit a parse tree produced by `FlinkSqlParser.functionName`.
|
* Visit a parse tree produced by `FlinkSqlParser.functionName`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
@ -1577,6 +1588,13 @@ export interface FlinkSqlParserVisitor<Result> extends ParseTreeVisitor<Result>
|
|||||||
*/
|
*/
|
||||||
visitCatalogPath?: (ctx: CatalogPathContext) => Result;
|
visitCatalogPath?: (ctx: CatalogPathContext) => Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visit a parse tree produced by `FlinkSqlParser.catalogPathCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
* @return the visitor result
|
||||||
|
*/
|
||||||
|
visitCatalogPathCreate?: (ctx: CatalogPathCreateContext) => Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit a parse tree produced by `FlinkSqlParser.databasePath`.
|
* Visit a parse tree produced by `FlinkSqlParser.databasePath`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
@ -1605,6 +1623,20 @@ export interface FlinkSqlParserVisitor<Result> extends ParseTreeVisitor<Result>
|
|||||||
*/
|
*/
|
||||||
visitTablePath?: (ctx: TablePathContext) => Result;
|
visitTablePath?: (ctx: TablePathContext) => Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visit a parse tree produced by `FlinkSqlParser.viewPath`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
* @return the visitor result
|
||||||
|
*/
|
||||||
|
visitViewPath?: (ctx: ViewPathContext) => Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visit a parse tree produced by `FlinkSqlParser.viewPathCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
* @return the visitor result
|
||||||
|
*/
|
||||||
|
visitViewPathCreate?: (ctx: ViewPathCreateContext) => Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit a parse tree produced by `FlinkSqlParser.uid`.
|
* Visit a parse tree produced by `FlinkSqlParser.uid`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -393,10 +393,11 @@ import { SortByClauseContext } from "./HiveSqlParser";
|
|||||||
import { TrimFunctionContext } from "./HiveSqlParser";
|
import { TrimFunctionContext } from "./HiveSqlParser";
|
||||||
import { Function_Context } from "./HiveSqlParser";
|
import { Function_Context } from "./HiveSqlParser";
|
||||||
import { Null_treatmentContext } from "./HiveSqlParser";
|
import { Null_treatmentContext } from "./HiveSqlParser";
|
||||||
|
import { FunctionNameCreateContext } from "./HiveSqlParser";
|
||||||
import { FunctionNameForDDLContext } from "./HiveSqlParser";
|
import { FunctionNameForDDLContext } from "./HiveSqlParser";
|
||||||
import { FunctionNameForInvokeContext } from "./HiveSqlParser";
|
import { FunctionNameForInvokeContext } from "./HiveSqlParser";
|
||||||
import { UserDefinedFuncNameContext } from "./HiveSqlParser";
|
import { UserDefinedFuncNameContext } from "./HiveSqlParser";
|
||||||
import { FunctionNameCreateContext } from "./HiveSqlParser";
|
import { InternalFunctionNameContext } from "./HiveSqlParser";
|
||||||
import { CastExpressionContext } from "./HiveSqlParser";
|
import { CastExpressionContext } from "./HiveSqlParser";
|
||||||
import { CaseExpressionContext } from "./HiveSqlParser";
|
import { CaseExpressionContext } from "./HiveSqlParser";
|
||||||
import { WhenExpressionContext } from "./HiveSqlParser";
|
import { WhenExpressionContext } from "./HiveSqlParser";
|
||||||
@ -4820,6 +4821,17 @@ export interface HiveSqlParserListener extends ParseTreeListener {
|
|||||||
*/
|
*/
|
||||||
exitNull_treatment?: (ctx: Null_treatmentContext) => void;
|
exitNull_treatment?: (ctx: Null_treatmentContext) => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter a parse tree produced by `HiveSqlParser.functionNameCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
enterFunctionNameCreate?: (ctx: FunctionNameCreateContext) => void;
|
||||||
|
/**
|
||||||
|
* Exit a parse tree produced by `HiveSqlParser.functionNameCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
exitFunctionNameCreate?: (ctx: FunctionNameCreateContext) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by `HiveSqlParser.functionNameForDDL`.
|
* Enter a parse tree produced by `HiveSqlParser.functionNameForDDL`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
@ -4854,15 +4866,15 @@ export interface HiveSqlParserListener extends ParseTreeListener {
|
|||||||
exitUserDefinedFuncName?: (ctx: UserDefinedFuncNameContext) => void;
|
exitUserDefinedFuncName?: (ctx: UserDefinedFuncNameContext) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by `HiveSqlParser.functionNameCreate`.
|
* Enter a parse tree produced by `HiveSqlParser.internalFunctionName`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
*/
|
*/
|
||||||
enterFunctionNameCreate?: (ctx: FunctionNameCreateContext) => void;
|
enterInternalFunctionName?: (ctx: InternalFunctionNameContext) => void;
|
||||||
/**
|
/**
|
||||||
* Exit a parse tree produced by `HiveSqlParser.functionNameCreate`.
|
* Exit a parse tree produced by `HiveSqlParser.internalFunctionName`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
*/
|
*/
|
||||||
exitFunctionNameCreate?: (ctx: FunctionNameCreateContext) => void;
|
exitInternalFunctionName?: (ctx: InternalFunctionNameContext) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by `HiveSqlParser.castExpression`.
|
* Enter a parse tree produced by `HiveSqlParser.castExpression`.
|
||||||
|
@ -393,10 +393,11 @@ import { SortByClauseContext } from "./HiveSqlParser";
|
|||||||
import { TrimFunctionContext } from "./HiveSqlParser";
|
import { TrimFunctionContext } from "./HiveSqlParser";
|
||||||
import { Function_Context } from "./HiveSqlParser";
|
import { Function_Context } from "./HiveSqlParser";
|
||||||
import { Null_treatmentContext } from "./HiveSqlParser";
|
import { Null_treatmentContext } from "./HiveSqlParser";
|
||||||
|
import { FunctionNameCreateContext } from "./HiveSqlParser";
|
||||||
import { FunctionNameForDDLContext } from "./HiveSqlParser";
|
import { FunctionNameForDDLContext } from "./HiveSqlParser";
|
||||||
import { FunctionNameForInvokeContext } from "./HiveSqlParser";
|
import { FunctionNameForInvokeContext } from "./HiveSqlParser";
|
||||||
import { UserDefinedFuncNameContext } from "./HiveSqlParser";
|
import { UserDefinedFuncNameContext } from "./HiveSqlParser";
|
||||||
import { FunctionNameCreateContext } from "./HiveSqlParser";
|
import { InternalFunctionNameContext } from "./HiveSqlParser";
|
||||||
import { CastExpressionContext } from "./HiveSqlParser";
|
import { CastExpressionContext } from "./HiveSqlParser";
|
||||||
import { CaseExpressionContext } from "./HiveSqlParser";
|
import { CaseExpressionContext } from "./HiveSqlParser";
|
||||||
import { WhenExpressionContext } from "./HiveSqlParser";
|
import { WhenExpressionContext } from "./HiveSqlParser";
|
||||||
@ -3263,6 +3264,13 @@ export interface HiveSqlParserVisitor<Result> extends ParseTreeVisitor<Result> {
|
|||||||
*/
|
*/
|
||||||
visitNull_treatment?: (ctx: Null_treatmentContext) => Result;
|
visitNull_treatment?: (ctx: Null_treatmentContext) => Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visit a parse tree produced by `HiveSqlParser.functionNameCreate`.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
* @return the visitor result
|
||||||
|
*/
|
||||||
|
visitFunctionNameCreate?: (ctx: FunctionNameCreateContext) => Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit a parse tree produced by `HiveSqlParser.functionNameForDDL`.
|
* Visit a parse tree produced by `HiveSqlParser.functionNameForDDL`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
@ -3285,11 +3293,11 @@ export interface HiveSqlParserVisitor<Result> extends ParseTreeVisitor<Result> {
|
|||||||
visitUserDefinedFuncName?: (ctx: UserDefinedFuncNameContext) => Result;
|
visitUserDefinedFuncName?: (ctx: UserDefinedFuncNameContext) => Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit a parse tree produced by `HiveSqlParser.functionNameCreate`.
|
* Visit a parse tree produced by `HiveSqlParser.internalFunctionName`.
|
||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
* @return the visitor result
|
* @return the visitor result
|
||||||
*/
|
*/
|
||||||
visitFunctionNameCreate?: (ctx: FunctionNameCreateContext) => Result;
|
visitInternalFunctionName?: (ctx: InternalFunctionNameContext) => Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit a parse tree produced by `HiveSqlParser.castExpression`.
|
* Visit a parse tree produced by `HiveSqlParser.castExpression`.
|
||||||
|
@ -15,6 +15,8 @@ export interface CaretPosition {
|
|||||||
export enum SyntaxContextType {
|
export enum SyntaxContextType {
|
||||||
/** catalog name */
|
/** catalog name */
|
||||||
CATALOG = 'catalog',
|
CATALOG = 'catalog',
|
||||||
|
/** catalog name that will be created */
|
||||||
|
CATALOG_CREATE = 'catalogCreate',
|
||||||
/** database name path, such as catalog.db */
|
/** database name path, such as catalog.db */
|
||||||
DATABASE = 'database',
|
DATABASE = 'database',
|
||||||
/** database name path that will be created */
|
/** database name path that will be created */
|
||||||
|
@ -23,11 +23,15 @@ export default class FlinkSQL extends BasicParser<FlinkSqlLexer, ProgramContext,
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected preferredRules = new Set([
|
protected preferredRules = new Set([
|
||||||
FlinkSqlParser.RULE_tablePath, // table name >> select / insert ...
|
|
||||||
FlinkSqlParser.RULE_tablePathCreate, // table name >> create
|
|
||||||
FlinkSqlParser.RULE_databasePath, // database name >> show
|
|
||||||
FlinkSqlParser.RULE_databasePathCreate, // database name >> create
|
|
||||||
FlinkSqlParser.RULE_catalogPath, // catalog name
|
FlinkSqlParser.RULE_catalogPath, // catalog name
|
||||||
|
FlinkSqlParser.RULE_databasePath, // database name
|
||||||
|
FlinkSqlParser.RULE_databasePathCreate, // database name that will be created
|
||||||
|
FlinkSqlParser.RULE_tablePath, // table name
|
||||||
|
FlinkSqlParser.RULE_tablePathCreate, // table name that will be created
|
||||||
|
FlinkSqlParser.RULE_viewPath, // view name path
|
||||||
|
FlinkSqlParser.RULE_viewPathCreate, // viewName that will be created
|
||||||
|
FlinkSqlParser.RULE_functionName, // functionName
|
||||||
|
FlinkSqlParser.RULE_functionNameCreate, // functionName that will be created
|
||||||
]);
|
]);
|
||||||
|
|
||||||
protected get splitListener () {
|
protected get splitListener () {
|
||||||
@ -50,6 +54,18 @@ export default class FlinkSQL extends BasicParser<FlinkSqlLexer, ProgramContext,
|
|||||||
|
|
||||||
let syntaxContextType: SyntaxContextType;
|
let syntaxContextType: SyntaxContextType;
|
||||||
switch (ruleType) {
|
switch (ruleType) {
|
||||||
|
case FlinkSqlParser.RULE_catalogPath: {
|
||||||
|
syntaxContextType = SyntaxContextType.CATALOG;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FlinkSqlParser.RULE_databasePath: {
|
||||||
|
syntaxContextType = SyntaxContextType.DATABASE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FlinkSqlParser.RULE_databasePathCreate: {
|
||||||
|
syntaxContextType = SyntaxContextType.DATABASE_CREATE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case FlinkSqlParser.RULE_tablePath: {
|
case FlinkSqlParser.RULE_tablePath: {
|
||||||
syntaxContextType = SyntaxContextType.TABLE;
|
syntaxContextType = SyntaxContextType.TABLE;
|
||||||
break;
|
break;
|
||||||
@ -58,16 +74,20 @@ export default class FlinkSQL extends BasicParser<FlinkSqlLexer, ProgramContext,
|
|||||||
syntaxContextType = SyntaxContextType.TABLE_CREATE;
|
syntaxContextType = SyntaxContextType.TABLE_CREATE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FlinkSqlParser.RULE_databasePath: {
|
case FlinkSqlParser.RULE_viewPath: {
|
||||||
syntaxContextType = SyntaxContextType.DATABASE;
|
syntaxContextType = SyntaxContextType.VIEW;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FlinkSqlParser.RULE_databasePathCreate: {
|
case FlinkSqlParser.RULE_viewPathCreate : {
|
||||||
syntaxContextType = SyntaxContextType.DATABASE;
|
syntaxContextType = SyntaxContextType.VIEW_CREATE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FlinkSqlParser.RULE_catalogPath: {
|
case FlinkSqlParser.RULE_functionName : {
|
||||||
syntaxContextType = SyntaxContextType.CATALOG;
|
syntaxContextType = SyntaxContextType.FUNCTION;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FlinkSqlParser.RULE_functionNameCreate : {
|
||||||
|
syntaxContextType = SyntaxContextType.FUNCTION_CREATE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -24,7 +24,8 @@ export default class HiveSQL extends BasicParser<HiveSqlLexer, ProgramContext, H
|
|||||||
HiveSqlParser.RULE_tableNameCreate, // table name that will be created
|
HiveSqlParser.RULE_tableNameCreate, // table name that will be created
|
||||||
HiveSqlParser.RULE_viewName, // view name
|
HiveSqlParser.RULE_viewName, // view name
|
||||||
HiveSqlParser.RULE_viewNameCreate, // view name that will be created
|
HiveSqlParser.RULE_viewNameCreate, // view name that will be created
|
||||||
HiveSqlParser.RULE_userDefinedFuncName, // function name
|
HiveSqlParser.RULE_functionNameForDDL, // function name
|
||||||
|
HiveSqlParser.RULE_functionNameForInvoke, // function name
|
||||||
HiveSqlParser.RULE_functionNameCreate, // function name that will be created
|
HiveSqlParser.RULE_functionNameCreate, // function name that will be created
|
||||||
|
|
||||||
]);
|
]);
|
||||||
@ -72,7 +73,8 @@ export default class HiveSQL extends BasicParser<HiveSqlLexer, ProgramContext, H
|
|||||||
syntaxContextType = SyntaxContextType.VIEW_CREATE;
|
syntaxContextType = SyntaxContextType.VIEW_CREATE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case HiveSqlParser.RULE_userDefinedFuncName: {
|
case HiveSqlParser.RULE_functionNameForDDL:
|
||||||
|
case HiveSqlParser.RULE_functionNameForInvoke: {
|
||||||
syntaxContextType = SyntaxContextType.FUNCTION;
|
syntaxContextType = SyntaxContextType.FUNCTION;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,25 @@
|
|||||||
INSERT INTO cat.db.tb
|
DROP CATALOG cat;
|
||||||
|
;
|
||||||
SELECT * FROM cat.db
|
SELECT * FROM cat. ;
|
||||||
|
;
|
||||||
CREATE TABLE cat.db ;
|
CREATE TABLE cat.db ;
|
||||||
|
;
|
||||||
|
SHOW TABLES FROM cat;
|
||||||
|
;
|
||||||
|
ALTER DATABASE cat.;
|
||||||
|
;
|
||||||
|
DROP VIEW v;
|
||||||
|
;
|
||||||
|
SELECT * FROM ;
|
||||||
|
;
|
||||||
|
CREATE VIEW cv;
|
||||||
|
;
|
||||||
|
SELECT name, calculate_age(birthdate) AS age FROM students;
|
||||||
|
;
|
||||||
|
CREATE FUNCTION fnc;
|
||||||
|
;
|
||||||
|
SHOW COLUMNS FROM vie;
|
||||||
|
;
|
||||||
|
SHOW CREATE TABLE tb1;
|
||||||
|
|
||||||
SHOW TABLES FROM cat
|
SHOW CREATE VIEW v1;
|
||||||
|
|
||||||
ALTER DATABASE cat.
|
|
||||||
|
|
||||||
USE DATABASE cat.
|
|
@ -15,30 +15,43 @@ describe('Flink SQL Syntax Suggestion', () => {
|
|||||||
expect(parser.validate(syntaxSql).length).not.toBe(0);
|
expect(parser.validate(syntaxSql).length).not.toBe(0);
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Insert table ', () => {
|
test("Multiple SQL use database", () => {
|
||||||
const pos: CaretPosition = {
|
const pos: CaretPosition = {
|
||||||
lineNumber: 1,
|
lineNumber: 19,
|
||||||
column: 22
|
column: 10,
|
||||||
}
|
}
|
||||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
const syntaxes = parser.getSuggestionAtCaretPosition(multipleSql, pos)?.syntax;
|
||||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||||
|
|
||||||
expect(suggestion).not.toBeUndefined();
|
expect(suggestion).not.toBeUndefined();
|
||||||
expect(suggestion?.wordRanges.map(token => token.text))
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
.toEqual([ 'cat', '.', 'db', '.', 'tb' ])
|
.toEqual([ 'cat1', '.' ]);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Drop catalog', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 1,
|
||||||
|
column: 17
|
||||||
|
}
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.CATALOG);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
|
.toEqual([ 'cat' ]);
|
||||||
|
});
|
||||||
|
|
||||||
test('Select table', () => {
|
test('Select table', () => {
|
||||||
const pos: CaretPosition = {
|
const pos: CaretPosition = {
|
||||||
lineNumber: 3,
|
lineNumber: 3,
|
||||||
column: 21
|
column: 19
|
||||||
}
|
}
|
||||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||||
|
console.log(syntaxes);
|
||||||
expect(suggestion).not.toBeUndefined();
|
expect(suggestion).not.toBeUndefined();
|
||||||
expect(suggestion?.wordRanges.map(token => token.text))
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
.toEqual([ 'cat', '.', 'db' ])
|
.toEqual([ 'cat', '.' ])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Create table', () => {
|
test('Create table', () => {
|
||||||
@ -60,7 +73,7 @@ describe('Flink SQL Syntax Suggestion', () => {
|
|||||||
column: 21
|
column: 21
|
||||||
}
|
}
|
||||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
||||||
|
|
||||||
expect(suggestion).not.toBeUndefined();
|
expect(suggestion).not.toBeUndefined();
|
||||||
expect(suggestion?.wordRanges.map(token => token.text))
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
@ -80,30 +93,107 @@ describe('Flink SQL Syntax Suggestion', () => {
|
|||||||
.toEqual([ 'cat', '.' ])
|
.toEqual([ 'cat', '.' ])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Use database', () => {
|
test('Drop view', () => {
|
||||||
const pos: CaretPosition = {
|
const pos: CaretPosition = {
|
||||||
lineNumber: 9,
|
lineNumber: 11,
|
||||||
|
column: 12
|
||||||
|
}
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
|
.toEqual([ 'v' ]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Select view', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 13,
|
||||||
|
column: 15
|
||||||
|
}
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
|
.toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create view', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 15,
|
||||||
|
column: 15
|
||||||
|
}
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW_CREATE);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
|
.toEqual(['cv']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Function call', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 17,
|
||||||
|
column: 27
|
||||||
|
}
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.FUNCTION);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
|
.toEqual(['calculate_age']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create Function', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 19,
|
||||||
column: 20
|
column: 20
|
||||||
}
|
}
|
||||||
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.FUNCTION_CREATE);
|
||||||
|
|
||||||
expect(suggestion).not.toBeUndefined();
|
expect(suggestion).not.toBeUndefined();
|
||||||
expect(suggestion?.wordRanges.map(token => token.text))
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
.toEqual([ 'cat', '.' ]);
|
.toEqual(['fnc']);
|
||||||
})
|
});
|
||||||
|
|
||||||
test("Multiple SQL use database", () => {
|
test('Show columns from view', () => {
|
||||||
const pos: CaretPosition = {
|
const pos: CaretPosition = {
|
||||||
lineNumber: 19,
|
lineNumber: 21,
|
||||||
column: 10,
|
column: 22
|
||||||
}
|
}
|
||||||
const syntaxes = parser.getSuggestionAtCaretPosition(multipleSql, pos)?.syntax;
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.DATABASE);
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||||
|
|
||||||
expect(suggestion).not.toBeUndefined();
|
expect(suggestion).not.toBeUndefined();
|
||||||
expect(suggestion?.wordRanges.map(token => token.text))
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
.toEqual([ 'cat1', '.' ]);
|
.toEqual(['vie']);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
test('Show create table', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 23,
|
||||||
|
column: 22
|
||||||
|
}
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.TABLE);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
|
.toEqual(['tb1']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Show create view', () => {
|
||||||
|
const pos: CaretPosition = {
|
||||||
|
lineNumber: 25,
|
||||||
|
column: 20
|
||||||
|
}
|
||||||
|
const syntaxes = parser.getSuggestionAtCaretPosition(syntaxSql, pos)?.syntax;
|
||||||
|
const suggestion = syntaxes?.find(syn => syn.syntaxContextType === SyntaxContextType.VIEW);
|
||||||
|
|
||||||
|
expect(suggestion).not.toBeUndefined();
|
||||||
|
expect(suggestion?.wordRanges.map(token => token.text))
|
||||||
|
.toEqual(['v1']);
|
||||||
|
});
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user