1919
2020grammar SqlBase;
2121
22- @parser::members {public static boolean hasSingleQuoteString;}
23-
2422singleStatement
2523 : statement EOF
2624 ;
2725
26+ /*
27+ * According to The Definitive ANTLR 4 Reference, 11. Altering the Parse with Semantic Predicates, Altering the Parse with Semantic Predicates.
28+ * "It s a good idea to avoid embedding predicates in the parser when possible for efficiency and clarity reasons."
29+ * So if unnecessary, don't use embedding predicates.
30+ */
31+
2832statement
29- : {hasSingleQuoteString = false ;} CREATE TIMESERIES fullPath alias? WITH attributeClauses #createTimeseries
30- | {hasSingleQuoteString = false ;} DELETE TIMESERIES prefixPath (COMMA prefixPath)* #deleteTimeseries
31- | {hasSingleQuoteString = false ;} ALTER TIMESERIES fullPath alterClause #alterTimeseries
32- | {hasSingleQuoteString = false ;} INSERT INTO prefixPath insertColumnSpec VALUES insertValuesSpec #insertStatement
33- | {hasSingleQuoteString = false ;} UPDATE prefixPath setClause whereClause? #updateStatement
34- | {hasSingleQuoteString = false ;} DELETE FROM prefixPath (COMMA prefixPath)* (whereClause)? #deleteStatement
35- | {hasSingleQuoteString = false ;} SET STORAGE GROUP TO prefixPath #setStorageGroup
36- | {hasSingleQuoteString = false ;} DELETE STORAGE GROUP prefixPath (COMMA prefixPath)* #deleteStorageGroup
33+ : CREATE TIMESERIES fullPath alias? WITH attributeClauses #createTimeseries
34+ | DELETE TIMESERIES prefixPath (COMMA prefixPath)* #deleteTimeseries
35+ | ALTER TIMESERIES fullPath alterClause #alterTimeseries
36+ | INSERT INTO prefixPath insertColumnSpec VALUES insertValuesSpec #insertStatement
37+ | UPDATE prefixPath setClause whereClause? #updateStatement
38+ | DELETE FROM prefixPath (COMMA prefixPath)* (whereClause)? #deleteStatement
39+ | SET STORAGE GROUP TO prefixPath #setStorageGroup
40+ | DELETE STORAGE GROUP prefixPath (COMMA prefixPath)* #deleteStorageGroup
3741 | SHOW METADATA #showMetadata // not support yet
3842 | DESCRIBE prefixPath #describePath // not support yet
3943 | CREATE INDEX ON fullPath USING function=ID indexWithClause? whereClause? #createIndex // not support yet
4044 | DROP INDEX function=ID ON fullPath #dropIndex // not support yet
4145 | MERGE #merge
42- | {hasSingleQuoteString = false ;} FLUSH prefixPath? (COMMA prefixPath)* (booleanClause)?#flush
46+ | FLUSH prefixPath? (COMMA prefixPath)* (booleanClause)?#flush
4347 | FULL MERGE #fullMerge
4448 | CLEAR CACHE #clearcache
45- | {hasSingleQuoteString = true ;} CREATE USER userName=ID password= stringLiteral#createUser
46- | {hasSingleQuoteString = true ;} ALTER USER userName=(ROOT |ID ) SET PASSWORD password=stringLiteral #alterUser
49+ | CREATE USER userName=ID password= stringLiteral#createUser
50+ | ALTER USER userName=(ROOT |ID ) SET PASSWORD password=stringLiteral #alterUser
4751 | DROP USER userName=ID #dropUser
4852 | CREATE ROLE roleName=ID #createRole
4953 | DROP ROLE roleName=ID #dropRole
50- | GRANT USER userName=ID PRIVILEGES privileges ON {hasSingleQuoteString = false ;} prefixPath #grantUser
51- | GRANT ROLE roleName=ID PRIVILEGES privileges ON {hasSingleQuoteString = false ;} prefixPath #grantRole
52- | REVOKE USER userName=ID PRIVILEGES privileges ON {hasSingleQuoteString = false ;} prefixPath #revokeUser
53- | REVOKE ROLE roleName=ID PRIVILEGES privileges ON {hasSingleQuoteString = false ;} prefixPath #revokeRole
54+ | GRANT USER userName=ID PRIVILEGES privileges ON prefixPath #grantUser
55+ | GRANT ROLE roleName=ID PRIVILEGES privileges ON prefixPath #grantRole
56+ | REVOKE USER userName=ID PRIVILEGES privileges ON prefixPath #revokeUser
57+ | REVOKE ROLE roleName=ID PRIVILEGES privileges ON prefixPath #revokeRole
5458 | GRANT roleName=ID TO userName=ID #grantRoleToUser
5559 | REVOKE roleName = ID FROM userName = ID #revokeRoleFromUser
56- | {hasSingleQuoteString = true ;} LOAD TIMESERIES (fileName=stringLiteral) prefixPath#loadStatement
60+ | LOAD TIMESERIES (fileName=stringLiteral) prefixPath#loadStatement
5761 | GRANT WATERMARK_EMBEDDING TO rootOrId (COMMA rootOrId)* #grantWatermarkEmbedding
5862 | REVOKE WATERMARK_EMBEDDING FROM rootOrId (COMMA rootOrId)* #revokeWatermarkEmbedding
5963 | LIST USER #listUser
6064 | LIST ROLE #listRole
61- | LIST PRIVILEGES USER username=rootOrId ON {hasSingleQuoteString = false ;} prefixPath #listPrivilegesUser
62- | LIST PRIVILEGES ROLE roleName=ID ON {hasSingleQuoteString = false ;} prefixPath #listPrivilegesRole
65+ | LIST PRIVILEGES USER username=rootOrId ON prefixPath #listPrivilegesUser
66+ | LIST PRIVILEGES ROLE roleName=ID ON prefixPath #listPrivilegesRole
6367 | LIST USER PRIVILEGES username =rootOrId #listUserPrivileges
6468 | LIST ROLE PRIVILEGES roleName = ID #listRolePrivileges
6569 | LIST ALL ROLE OF USER username = rootOrId #listAllRoleOfUser
6670 | LIST ALL USER OF ROLE roleName = ID #listAllUserOfRole
67- | {hasSingleQuoteString = false ;} SET TTL TO path=prefixPath time=INT #setTTLStatement
68- | {hasSingleQuoteString = false ;} UNSET TTL TO path=prefixPath #unsetTTLStatement
69- | {hasSingleQuoteString = false ;} SHOW TTL ON prefixPath (COMMA prefixPath)* #showTTLStatement
71+ | SET TTL TO path=prefixPath time=INT #setTTLStatement
72+ | UNSET TTL TO path=prefixPath #unsetTTLStatement
73+ | SHOW TTL ON prefixPath (COMMA prefixPath)* #showTTLStatement
7074 | SHOW ALL TTL #showAllTTLStatement
7175 | SHOW FLUSH TASK INFO #showFlushTaskInfo
7276 | SHOW DYNAMIC PARAMETER #showDynamicParameter
7377 | SHOW VERSION #showVersion
74- | {hasSingleQuoteString = false ;} SHOW LATEST ? TIMESERIES prefixPath? showWhereClause? limitClause? #showTimeseries
75- | {hasSingleQuoteString = false ;} SHOW STORAGE GROUP prefixPath? #showStorageGroup
76- | {hasSingleQuoteString = false ;} SHOW CHILD PATHS prefixPath? #showChildPaths
77- | {hasSingleQuoteString = false ;} SHOW DEVICES prefixPath? #showDevices
78+ | SHOW LATEST ? TIMESERIES prefixPath? showWhereClause? limitClause? #showTimeseries
79+ | SHOW STORAGE GROUP prefixPath? #showStorageGroup
80+ | SHOW CHILD PATHS prefixPath? #showChildPaths
81+ | SHOW DEVICES prefixPath? #showDevices
7882 | SHOW MERGE #showMergeStatus
7983 | TRACING ON #tracingOn
8084 | TRACING OFF #tracingOff
@@ -83,10 +87,10 @@ statement
8387 | COUNT STORAGE GROUP prefixPath? #countStorageGroup
8488 | COUNT NODES prefixPath LEVEL OPERATOR_EQ INT #countNodes
8589 | LOAD CONFIGURATION (MINUS GLOBAL )? #loadConfigurationStatement
86- | {hasSingleQuoteString = true ;} LOAD stringLiteral autoCreateSchema?#loadFiles
87- | {hasSingleQuoteString = true ;} REMOVE stringLiteral #removeFile
88- | {hasSingleQuoteString = true ;} MOVE stringLiteral stringLiteral #moveFile
89- | {hasSingleQuoteString = false ;} DELETE PARTITION prefixPath INT (COMMA INT )* #deletePartition
90+ | LOAD stringLiteral autoCreateSchema?#loadFiles
91+ | REMOVE stringLiteral #removeFile
92+ | MOVE stringLiteral stringLiteral #moveFile
93+ | DELETE PARTITION prefixPath INT (COMMA INT )* #deletePartition
9094 | CREATE SNAPSHOT FOR SCHEMA #createSnapshot
9195 | SELECT INDEX func=ID // not support yet
9296 LR_BRACKET
@@ -96,20 +100,25 @@ statement
96100 fromClause
97101 whereClause?
98102 specialClause? #selectIndexStatement
99- | {hasSingleQuoteString = true ;} SELECT selectElements
103+ | SELECT selectElements
100104 fromClause
101105 whereClause?
102106 specialClause? #selectStatement
103107 ;
104108
105109selectElements
106110 : functionCall (COMMA functionCall)* #functionElement
107- | suffixPath (COMMA suffixPath )* #selectElement
111+ | suffixPathOrConstant (COMMA suffixPathOrConstant )* #selectElement
108112 | lastClause #lastElement
109113 | asClause (COMMA asClause)* #asElement
110114 | functionAsClause (COMMA functionAsClause)* #functionAsElement
111115 ;
112116
117+ suffixPathOrConstant
118+ : suffixPath
119+ | SINGLE_QUOTE_STRING_LITERAL
120+ ;
121+
113122functionCall
114123 : functionName LR_BRACKET suffixPath RR_BRACKET
115124 ;
@@ -157,7 +166,7 @@ aliasClause
157166 ;
158167
159168attributeClauses
160- : DATATYPE OPERATOR_EQ dataType COMMA ENCODING OPERATOR_EQ encoding
169+ : DATATYPE OPERATOR_EQ dataType ( COMMA ENCODING OPERATOR_EQ encoding)?
161170 (COMMA (COMPRESSOR | COMPRESSION ) OPERATOR_EQ compressor)?
162171 (COMMA property)*
163172 tagClause
@@ -216,7 +225,7 @@ inClause
216225 ;
217226
218227fromClause
219- : {hasSingleQuoteString = false ;} FROM prefixPath (COMMA prefixPath)*
228+ : FROM prefixPath (COMMA prefixPath)*
220229 ;
221230
222231specialClause
@@ -352,7 +361,7 @@ setCol
352361 ;
353362
354363privileges
355- : {hasSingleQuoteString = true ;} stringLiteral (COMMA stringLiteral)*
364+ : stringLiteral (COMMA stringLiteral)*
356365 ;
357366
358367rootOrId
@@ -374,7 +383,7 @@ timeValue
374383propertyValue
375384 : INT
376385 | ID
377- | {hasSingleQuoteString = true ;} stringLiteral
386+ | stringLiteral
378387 | constant
379388 ;
380389
@@ -393,7 +402,7 @@ suffixPath
393402nodeName
394403 : ID
395404 | STAR
396- | stringLiteral
405+ | DOUBLE_QUOTE_STRING_LITERAL
397406 | ID STAR
398407 | DURATION
399408 | encoding
@@ -504,7 +513,7 @@ nodeName
504513
505514nodeNameWithoutStar
506515 : ID
507- | stringLiteral
516+ | DOUBLE_QUOTE_STRING_LITERAL
508517 | DURATION
509518 | encoding
510519 | dataType
@@ -626,7 +635,7 @@ constant
626635 | NaN
627636 | MINUS ? realLiteral
628637 | MINUS ? INT
629- | {hasSingleQuoteString = true ;} stringLiteral
638+ | stringLiteral
630639 | booleanClause
631640 ;
632641
@@ -1241,7 +1250,7 @@ UNDERLINE : '_';
12411250NaN : ' NaN' ;
12421251
12431252stringLiteral
1244- : {hasSingleQuoteString} ? SINGLE_QUOTE_STRING_LITERAL
1253+ : SINGLE_QUOTE_STRING_LITERAL
12451254 | DOUBLE_QUOTE_STRING_LITERAL
12461255 ;
12471256
0 commit comments