Skip to content

Commit 53ead45

Browse files
authored
Optimize/auto complete (DTStack#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
1 parent c403092 commit 53ead45

File tree

15 files changed

+10504
-9604
lines changed

15 files changed

+10504
-9604
lines changed

src/grammar/flinksql/FlinkSqlParser.g4

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ useModuleStatement
6363
showStatememt
6464
: KW_SHOW (KW_CATALOGS | KW_DATABASES | KW_VIEWS | KW_JARS)
6565
| KW_SHOW KW_CURRENT (KW_CATALOG | KW_DATABASE)
66-
| KW_SHOW KW_TABLES (( KW_FROM | KW_IN ) tablePath)? likePredicate?
67-
| KW_SHOW KW_COLUMNS ( KW_FROM | KW_IN ) uid likePredicate?
68-
| KW_SHOW KW_CREATE (KW_TABLE | KW_VIEW) uid
66+
| KW_SHOW KW_TABLES (( KW_FROM | KW_IN ) databasePath)? likePredicate?
67+
| KW_SHOW KW_COLUMNS ( KW_FROM | KW_IN ) (viewPath| tablePath) likePredicate?
68+
| KW_SHOW KW_CREATE (KW_TABLE tablePath | KW_VIEW viewPath)
6969
| KW_SHOW KW_USER? KW_FUNCTIONS
7070
| KW_SHOW KW_FULL? KW_MODULES
7171
;
@@ -258,19 +258,19 @@ likeOption
258258
;
259259

260260
createCatalog
261-
: KW_CREATE KW_CATALOG uid withOption
261+
: KW_CREATE KW_CATALOG catalogPathCreate withOption
262262
;
263263

264264
createDatabase
265265
: KW_CREATE KW_DATABASE ifNotExists? databasePathCreate commentSpec? withOption
266266
;
267267

268268
createView
269-
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? uid columnNameList? commentSpec? KW_AS queryStatement
269+
: KW_CREATE KW_TEMPORARY? KW_VIEW ifNotExists? viewPathCreate columnNameList? commentSpec? KW_AS queryStatement
270270
;
271271

272272
createFunction
273-
: KW_CREATE (KW_TEMPORARY|KW_TEMPORARY KW_SYSTEM)? KW_FUNCTION ifNotExists? functionName KW_AS identifier (KW_LANGUAGE (KW_JAVA|KW_SCALA|KW_PYTHON))? usingClause?
273+
: KW_CREATE (KW_TEMPORARY|KW_TEMPORARY KW_SYSTEM)? KW_FUNCTION ifNotExists? functionNameCreate KW_AS identifier (KW_LANGUAGE (KW_JAVA|KW_SCALA|KW_PYTHON))? usingClause?
274274
;
275275

276276
usingClause
@@ -314,15 +314,15 @@ notForced
314314
;
315315

316316
alertView
317-
: KW_ALTER KW_VIEW uid (renameDefinition | KW_AS queryStatement)
317+
: KW_ALTER KW_VIEW viewPath (renameDefinition | KW_AS queryStatement)
318318
;
319319

320320
alterDatabase
321321
: KW_ALTER KW_DATABASE databasePath setKeyValueDefinition
322322
;
323323

324324
alterFunction
325-
: KW_ALTER (KW_TEMPORARY|KW_TEMPORARY KW_SYSTEM)? KW_FUNCTION ifExists? uid KW_AS identifier (KW_LANGUAGE (KW_JAVA|KW_SCALA|KW_PYTHON))?
325+
: KW_ALTER (KW_TEMPORARY|KW_TEMPORARY KW_SYSTEM)? KW_FUNCTION ifExists? functionName KW_AS identifier (KW_LANGUAGE (KW_JAVA|KW_SCALA|KW_PYTHON))? // TODO
326326
;
327327

328328

@@ -341,7 +341,7 @@ dropDatabase
341341
;
342342

343343
dropView
344-
: KW_DROP KW_TEMPORARY? KW_VIEW ifExists? uid
344+
: KW_DROP KW_TEMPORARY? KW_VIEW ifExists? viewPath
345345
;
346346

347347
dropFunction
@@ -450,13 +450,12 @@ tableReference
450450

451451
tablePrimary
452452
: KW_TABLE? tablePath systemTimePeriod? (KW_AS? correlationName)?
453+
| viewPath systemTimePeriod? (KW_AS? correlationName)?
453454
| KW_LATERAL KW_TABLE LR_BRACKET functionName LR_BRACKET functionParam (COMMA functionParam)* RR_BRACKET RR_BRACKET
454455
| KW_LATERAL? LR_BRACKET queryStatement RR_BRACKET
455456
| KW_UNNEST LR_BRACKET expression RR_BRACKET
456457
;
457458

458-
459-
460459
systemTimePeriod
461460
: KW_FOR KW_SYSTEM_TIME KW_AS KW_OF dateTimeExpression
462461
;
@@ -731,6 +730,10 @@ primaryExpression
731730
// KW_FROM position=valueExpression (KW_FOR length=valueExpression)? ')' #overlay
732731
;
733732

733+
functionNameCreate
734+
: uid
735+
;
736+
734737
functionName
735738
: reservedKeywordsUsedAsFuncName
736739
| nonReservedKeywords
@@ -827,23 +830,39 @@ whenClause
827830
;
828831

829832
catalogPath
830-
: uid
833+
: identifier
834+
;
835+
836+
catalogPathCreate
837+
: identifier
831838
;
832839

833840
databasePath
834-
: uid
841+
: identifier (DOT identifier)?
835842
;
836843

837844
databasePathCreate
838-
: uid
845+
: identifier (DOT identifier)?
839846
;
840847

841848
tablePathCreate
842-
: uid
849+
: identifier (DOT identifier)?
850+
| identifier DOT identifier (DOT identifier)?
843851
;
844852

845853
tablePath
846-
: uid
854+
: identifier (DOT identifier)?
855+
| identifier DOT identifier (DOT identifier)?
856+
;
857+
858+
viewPath
859+
: identifier (DOT identifier)?
860+
| identifier DOT identifier (DOT identifier)?
861+
;
862+
863+
viewPathCreate
864+
: identifier (DOT identifier)?
865+
| identifier DOT identifier (DOT identifier)?
847866
;
848867

849868
uid

src/grammar/hive/HiveSqlParser.g4

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,23 +2177,27 @@ null_treatment
21772177
| KW_IGNORE KW_NULLS
21782178
;
21792179

2180-
functionNameForDDL
2181-
: functionNameForInvoke
2180+
functionNameCreate
2181+
: functionIdentifier
2182+
;
2183+
2184+
functionNameForDDL // Function name use to DDL, such as drop function
2185+
: userDefinedFuncName
21822186
| StringLiteral
21832187
;
21842188

2185-
functionNameForInvoke
2189+
functionNameForInvoke // Function name used to invoke
21862190
: userDefinedFuncName
2187-
| sql11ReservedKeywordsUsedAsFunctionName
2188-
| sysFuncNames
2191+
| internalFunctionName
21892192
;
21902193

2191-
userDefinedFuncName
2194+
userDefinedFuncName // User Defined Function
21922195
: functionIdentifier
21932196
;
21942197

2195-
functionNameCreate
2196-
: functionIdentifier
2198+
internalFunctionName // Hive Internal Function
2199+
: sql11ReservedKeywordsUsedAsFunctionName
2200+
| sysFuncNames
21972201
;
21982202

21992203
castExpression

src/lib/flinksql/FlinkSqlParser.interp

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

0 commit comments

Comments
 (0)