This is an automated email from the ASF dual-hosted git repository.

hui pushed a commit to branch lmh/ddlRefactor
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 0d3a280895191407d08c4bad5c710a1bac78244a
Author: Minghui Liu <[email protected]>
AuthorDate: Mon Feb 27 17:44:23 2023 +0800

    refactor ddlStatement structure in IoTDBSqlParser.g4
---
 .../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4   | 465 +++++++++++----------
 1 file changed, 247 insertions(+), 218 deletions(-)

diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 
b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
index 5f04e5406d..45ba9a7f79 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
@@ -36,16 +36,25 @@ statement
     ;
 
 ddlStatement
-    : createStorageGroup | createTimeseries | createSchemaTemplate | 
createTimeseriesOfSchemaTemplate
-    | createFunction | createTrigger | createContinuousQuery
-    | alterTimeseries | alterStorageGroup | deleteStorageGroup | 
deleteTimeseries | deletePartition | deleteTimeseriesOfSchemaTemplate
-    | dropFunction | dropTrigger | dropContinuousQuery | dropSchemaTemplate
-    | setTTL | unsetTTL | startTrigger | stopTrigger | setSchemaTemplate | 
unsetSchemaTemplate
-    | showStorageGroup | showDevices | showTimeseries | showChildPaths | 
showChildNodes
-    | showFunctions | showTriggers | showContinuousQueries | showTTL | 
showAllTTL | showCluster | showVariables | showRegion | showDataNodes | 
showConfigNodes
-    | showSchemaTemplates | showNodesInSchemaTemplate
-    | showPathsUsingSchemaTemplate | showPathsSetSchemaTemplate
-    | countStorageGroup | countDevices | countTimeseries | countNodes
+    // Database
+    : createDatabase | dropDatabase | dropPartition | alterDatabase | 
showDatabases | countDatabases
+    // Timeseries & Path
+    | createTimeseries | dropTimeseries | alterTimeseries
+    | showDevices | showTimeseries | showChildPaths | showChildNodes | 
countDevices | countTimeseries | countNodes
+    // Schema Template
+    | createSchemaTemplate | createTimeseriesOfSchemaTemplate | 
dropSchemaTemplate | dropTimeseriesOfSchemaTemplate
+    | showSchemaTemplates | showNodesInSchemaTemplate | 
showPathsUsingSchemaTemplate | showPathsSetSchemaTemplate
+    | setSchemaTemplate | unsetSchemaTemplate
+    // TTL
+    | setTTL | unsetTTL | showTTL | showAllTTL
+    // Function
+    | createFunction | dropFunction | showFunctions
+    // Trigger
+    | createTrigger | dropTrigger | showTriggers | startTrigger | stopTrigger
+    // CQ
+    | createContinuousQuery | dropContinuousQuery | showContinuousQueries
+    // Cluster
+    | showVariables | showCluster | showRegions | showDataNodes | 
showConfigNodes
     | getRegionId | getTimeSlotList | getSeriesSlotList | migrateRegion
     ;
 
@@ -72,26 +81,58 @@ syncStatement
  * 2. Data Definition Language (DDL)
  */
 
-// Create Storage Group
-createStorageGroup
-    : SET STORAGE GROUP TO prefixPath storageGroupAttributesClause?
-    | CREATE (STORAGE GROUP | DATABASE) prefixPath 
storageGroupAttributesClause?
+// Database 
=========================================================================================
+// ---- Create Database
+createDatabase
+    : SET STORAGE GROUP TO prefixPath databaseAttributesClause?
+    | CREATE (STORAGE GROUP | DATABASE) prefixPath databaseAttributesClause?
     ;
 
-storageGroupAttributesClause
-    : WITH storageGroupAttributeClause (COMMA? storageGroupAttributeClause)*
+databaseAttributesClause
+    : WITH databaseAttributeClause (COMMA? databaseAttributeClause)*
     ;
 
-storageGroupAttributeClause
-    : (TTL | SCHEMA_REPLICATION_FACTOR | DATA_REPLICATION_FACTOR | 
TIME_PARTITION_INTERVAL | SCHEMA_REGION_GROUP_NUM | DATA_REGION_GROUP_NUM) '=' 
INTEGER_LITERAL
+databaseAttributeClause
+    : databaseAttributeKey operator_eq INTEGER_LITERAL
     ;
 
-// Alter StorageGroup
-alterStorageGroup
-    : ALTER (STORAGE GROUP | DATABASE) prefixPath storageGroupAttributesClause
+databaseAttributeKey
+    : TTL
+    | SCHEMA_REPLICATION_FACTOR
+    | DATA_REPLICATION_FACTOR
+    | TIME_PARTITION_INTERVAL
+    | SCHEMA_REGION_GROUP_NUM
+    | DATA_REGION_GROUP_NUM
     ;
 
-// Create Timeseries
+// ---- Drop Database
+dropDatabase
+    : (DELETE | DROP) (STORAGE GROUP | DATABASE) prefixPath (COMMA prefixPath)*
+    ;
+
+// ---- Drop Partition
+dropPartition
+    : (DELETE | DROP) PARTITION prefixPath INTEGER_LITERAL(COMMA 
INTEGER_LITERAL)*
+    ;
+
+// ---- Alter Database
+alterDatabase
+    : ALTER (STORAGE GROUP | DATABASE) prefixPath databaseAttributesClause
+    ;
+
+// ---- Show Databases
+showDatabases
+    : SHOW (STORAGE GROUP | DATABASES) DETAILS? prefixPath?
+    ;
+
+// ---- Count Databases
+countDatabases
+    : COUNT (STORAGE GROUP | DATABASES) prefixPath?
+    ;
+
+
+// Timeseries & Path 
===============================================================================
+// ---- Create Timeseries
 createTimeseries
     : CREATE ALIGNED TIMESERIES fullPath alignedMeasurements? 
#createAlignedTimeseries
     | CREATE TIMESERIES fullPath attributeClauses  #createNonAlignedTimeseries
@@ -102,316 +143,303 @@ alignedMeasurements
     (COMMA nodeNameWithoutWildcard attributeClauses)* RR_BRACKET
     ;
 
-// Create Schema Template
-createSchemaTemplate
-    : CREATE SCHEMA TEMPLATE templateName=identifier
-    ALIGNED? LR_BRACKET templateMeasurementClause (COMMA 
templateMeasurementClause)* RR_BRACKET
+// ---- Drop Timeseries
+dropTimeseries
+    : (DELETE | DROP) TIMESERIES prefixPath (COMMA prefixPath)*
     ;
 
-templateMeasurementClause
-    : nodeNameWithoutWildcard attributeClauses
+// ---- Alter Timeseries
+alterTimeseries
+    : ALTER TIMESERIES fullPath alterClause
     ;
 
-// Create Timeseries Of Schema Template
-createTimeseriesOfSchemaTemplate
-    : CREATE TIMESERIES OF SCHEMA TEMPLATE ON prefixPath
+alterClause
+    : RENAME beforeName=attributeKey TO currentName=attributeKey
+    | SET attributePair (COMMA attributePair)*
+    | DROP attributeKey (COMMA attributeKey)*
+    | ADD TAGS attributePair (COMMA attributePair)*
+    | ADD ATTRIBUTES attributePair (COMMA attributePair)*
+    | UPSERT aliasClause? tagClause? attributeClause?
     ;
 
-// Create Function
-createFunction
-    : CREATE FUNCTION udfName=identifier AS className=STRING_LITERAL uriClasue?
+aliasClause
+    : ALIAS operator_eq alias
     ;
 
-uriClasue
-    : USING URI uri
+// ---- Show Devices
+showDevices
+    : SHOW DEVICES prefixPath? (WITH (STORAGE GROUP | DATABASE))? 
rowPaginationClause?
     ;
 
-uri
-    : STRING_LITERAL
+// ---- Show Timeseries
+showTimeseries
+    : SHOW LATEST? TIMESERIES prefixPath? tagWhereClause? rowPaginationClause?
     ;
 
-// Create Trigger
-createTrigger
-    : CREATE triggerType? TRIGGER triggerName=identifier
-        triggerEventClause
-        ON prefixPath
-        AS className=STRING_LITERAL
-        uriClasue?
-        triggerAttributeClause?
+// ---- Show Child Paths
+showChildPaths
+    : SHOW CHILD PATHS prefixPath?
     ;
 
-triggerType
-    : STATELESS | STATEFUL
+// ---- Show Child Nodes
+showChildNodes
+    : SHOW CHILD NODES prefixPath?
     ;
 
-triggerEventClause
-    : (BEFORE | AFTER) (INSERT | DELETE)
+// ---- Count Devices
+countDevices
+    : COUNT DEVICES prefixPath?
     ;
 
-triggerAttributeClause
-    : WITH LR_BRACKET triggerAttribute (COMMA triggerAttribute)* RR_BRACKET
+// ---- Count Timeseries
+countTimeseries
+    : COUNT TIMESERIES prefixPath? tagWhereClause? (GROUP BY LEVEL operator_eq 
INTEGER_LITERAL)?
     ;
 
-triggerAttribute
-    : key=attributeKey operator_eq value=attributeValue
+// ---- Count Nodes
+countNodes
+    : COUNT NODES prefixPath LEVEL operator_eq INTEGER_LITERAL
     ;
 
-// Create Continuous Query
-createContinuousQuery
-    : CREATE (CONTINUOUS QUERY | CQ) cqId=identifier
-        resampleClause?
-        timeoutPolicyClause?
-        BEGIN
-            selectStatement
-        END
+tagWhereClause
+    : WHERE (attributePair | containsExpression)
     ;
 
-resampleClause
-    : RESAMPLE
-        (EVERY everyInterval=DURATION_LITERAL)?
-        (BOUNDARY boundaryTime=timeValue)?
-        (RANGE startTimeOffset=DURATION_LITERAL (COMMA 
endTimeOffset=DURATION_LITERAL)?)?
+
+// Schema Template 
==================================================================================
+// ---- Create Schema Template
+createSchemaTemplate
+    : CREATE SCHEMA TEMPLATE templateName=identifier
+    ALIGNED? LR_BRACKET templateMeasurementClause (COMMA 
templateMeasurementClause)* RR_BRACKET
     ;
 
-timeoutPolicyClause
-    : TIMEOUT POLICY (BLOCKED | DISCARD)
+templateMeasurementClause
+    : nodeNameWithoutWildcard attributeClauses
     ;
 
-// Alter Timeseries
-alterTimeseries
-    : ALTER TIMESERIES fullPath alterClause
+// ---- Create Timeseries Of Schema Template
+createTimeseriesOfSchemaTemplate
+    : CREATE TIMESERIES OF SCHEMA TEMPLATE ON prefixPath
     ;
 
-alterClause
-    : RENAME beforeName=attributeKey TO currentName=attributeKey
-    | SET attributePair (COMMA attributePair)*
-    | DROP attributeKey (COMMA attributeKey)*
-    | ADD TAGS attributePair (COMMA attributePair)*
-    | ADD ATTRIBUTES attributePair (COMMA attributePair)*
-    | UPSERT aliasClause? tagClause? attributeClause?
+// ---- Drop Schema Template
+dropSchemaTemplate
+    : DROP SCHEMA TEMPLATE templateName=identifier
     ;
 
-aliasClause
-    : ALIAS operator_eq alias
+// ---- Drop Timeseries of Schema Template
+dropTimeseriesOfSchemaTemplate
+    : ((DELETE | DROP) TIMESERIES OF | DEACTIVATE) SCHEMA TEMPLATE 
(templateName=identifier) ? FROM prefixPath (COMMA prefixPath)*
     ;
 
-alias
-    : constant
-    | identifier
+// ---- Show Schema Template
+showSchemaTemplates
+    : SHOW SCHEMA TEMPLATES
     ;
 
-// Delete Storage Group
-deleteStorageGroup
-    : (DELETE | DROP) (STORAGE GROUP | DATABASE) prefixPath (COMMA prefixPath)*
+// ---- Show Measurements In Schema Template
+showNodesInSchemaTemplate
+    : SHOW NODES OPERATOR_IN SCHEMA TEMPLATE templateName=identifier
     ;
 
-// Delete Timeseries
-deleteTimeseries
-    : (DELETE | DROP) TIMESERIES prefixPath (COMMA prefixPath)*
+// ---- Show Paths Set Schema Template
+showPathsSetSchemaTemplate
+    : SHOW PATHS SET SCHEMA TEMPLATE templateName=identifier
     ;
 
-// Delete Partition
-deletePartition
-    : DELETE PARTITION prefixPath INTEGER_LITERAL(COMMA INTEGER_LITERAL)*
+// ---- Show Paths Using Schema Template
+showPathsUsingSchemaTemplate
+    : SHOW PATHS prefixPath? USING SCHEMA TEMPLATE templateName=identifier
     ;
 
-// Delete Timeseries of Schema Template
-deleteTimeseriesOfSchemaTemplate
-    : (DELETE TIMESERIES OF | DEACTIVATE) SCHEMA TEMPLATE 
(templateName=identifier) ? FROM prefixPath (COMMA prefixPath)*
+// ---- Set Schema Template
+setSchemaTemplate
+    : SET SCHEMA TEMPLATE templateName=identifier TO prefixPath
     ;
 
-// Drop Function
-dropFunction
-    : DROP FUNCTION udfName=identifier
+// ---- Unset Schema Template
+unsetSchemaTemplate
+    : UNSET SCHEMA TEMPLATE templateName=identifier FROM prefixPath
     ;
 
-// Drop Trigger
-dropTrigger
-    : DROP TRIGGER triggerName=identifier
+
+// TTL 
=============================================================================================
+// ---- Set TTL
+setTTL
+    : SET TTL TO path=prefixPath time=INTEGER_LITERAL
     ;
 
-// Drop Continuous Query
-dropContinuousQuery
-    : DROP (CONTINUOUS QUERY|CQ) cqId=identifier
+// ---- Unset TTL
+unsetTTL
+    : UNSET TTL TO path=prefixPath
     ;
 
-// Drop Schema Template
-dropSchemaTemplate
-    : DROP SCHEMA TEMPLATE templateName=identifier
+// ---- Show TTL
+showTTL
+    : SHOW TTL ON prefixPath (COMMA prefixPath)*
     ;
 
-// Get Region Id
-getRegionId
-    : SHOW (DATA|SCHEMA) REGIONID OF path=prefixPath WHERE (SERIESSLOTID 
operator_eq
-        seriesSlot=INTEGER_LITERAL|DEVICEID operator_eq deviceId=prefixPath) 
(OPERATOR_AND (TIMESLOTID operator_eq timeSlot=INTEGER_LITERAL|
-        TIMESTAMP operator_eq timeStamp=INTEGER_LITERAL))?
+// ---- Show All TTL
+showAllTTL
+    : SHOW ALL TTL
     ;
 
-// Get Time Slot List
-getTimeSlotList
-    : SHOW TIMESLOTID OF path=prefixPath WHERE SERIESSLOTID operator_eq 
seriesSlot=INTEGER_LITERAL
-        (OPERATOR_AND STARTTIME operator_eq startTime=INTEGER_LITERAL)?
-        (OPERATOR_AND ENDTIME operator_eq endTime=INTEGER_LITERAL)?
+
+// Function 
=========================================================================================
+// ---- Create Function
+createFunction
+    : CREATE FUNCTION udfName=identifier AS className=STRING_LITERAL uriClasue?
     ;
 
-// Get Series Slot List
-getSeriesSlotList
-    : SHOW (DATA|SCHEMA)? SERIESSLOTID OF path=prefixPath
+uriClasue
+    : USING URI uri
     ;
 
-// Migrate Region
-migrateRegion
-    : MIGRATE REGION regionId=INTEGER_LITERAL FROM fromId=INTEGER_LITERAL TO 
toId=INTEGER_LITERAL
+uri
+    : STRING_LITERAL
     ;
 
-// Set TTL
-setTTL
-    : SET TTL TO path=prefixPath time=INTEGER_LITERAL
+// ---- Drop Function
+dropFunction
+    : DROP FUNCTION udfName=identifier
     ;
 
-// Unset TTL
-unsetTTL
-    : UNSET TTL TO path=prefixPath
+// ---- Show Functions
+showFunctions
+    : SHOW FUNCTIONS
     ;
 
-// Set Schema Template
-setSchemaTemplate
-    : SET SCHEMA TEMPLATE templateName=identifier TO prefixPath
+
+// Trigger 
=========================================================================================
+// ---- Create Trigger
+createTrigger
+    : CREATE triggerType? TRIGGER triggerName=identifier
+        triggerEventClause
+        ON prefixPath
+        AS className=STRING_LITERAL
+        uriClasue?
+        triggerAttributeClause?
     ;
 
-// Unset Schema Template
-unsetSchemaTemplate
-    : UNSET SCHEMA TEMPLATE templateName=identifier FROM prefixPath
+triggerType
+    : STATELESS | STATEFUL
     ;
 
-// Start Trigger
-startTrigger
-    : START TRIGGER triggerName=identifier
+triggerEventClause
+    : (BEFORE | AFTER) (INSERT | DELETE)
     ;
 
-// Stop Trigger
-stopTrigger
-    : STOP TRIGGER triggerName=identifier
+triggerAttributeClause
+    : WITH LR_BRACKET triggerAttribute (COMMA triggerAttribute)* RR_BRACKET
     ;
 
-// Show Storage Group
-showStorageGroup
-    : SHOW (STORAGE GROUP | DATABASES) DETAILS? prefixPath?
+triggerAttribute
+    : key=attributeKey operator_eq value=attributeValue
     ;
 
-// Show Devices
-showDevices
-    : SHOW DEVICES prefixPath? (WITH (STORAGE GROUP | DATABASE))? 
rowPaginationClause?
+// ---- Drop Trigger
+dropTrigger
+    : DROP TRIGGER triggerName=identifier
     ;
 
-// Show Timeseries
-showTimeseries
-    : SHOW LATEST? TIMESERIES prefixPath? tagWhereClause? rowPaginationClause?
+// ---- Show Triggers
+showTriggers
+    : SHOW TRIGGERS
     ;
 
-// Show Child Paths
-showChildPaths
-    : SHOW CHILD PATHS prefixPath?
+// ---- Start Trigger
+startTrigger
+    : START TRIGGER triggerName=identifier
     ;
 
-// Show Child Nodes
-showChildNodes
-    : SHOW CHILD NODES prefixPath?
+// ---- Stop Trigger
+stopTrigger
+    : STOP TRIGGER triggerName=identifier
     ;
 
-// Show Functions
-showFunctions
-    : SHOW FUNCTIONS
+
+// CQ 
==============================================================================================
+// ---- Create Continuous Query
+createContinuousQuery
+    : CREATE (CONTINUOUS QUERY | CQ) cqId=identifier
+        resampleClause?
+        timeoutPolicyClause?
+        BEGIN
+            selectStatement
+        END
     ;
 
-// Show Triggers
-showTriggers
-    : SHOW TRIGGERS
+resampleClause
+    : RESAMPLE
+        (EVERY everyInterval=DURATION_LITERAL)?
+        (BOUNDARY boundaryTime=timeValue)?
+        (RANGE startTimeOffset=DURATION_LITERAL (COMMA 
endTimeOffset=DURATION_LITERAL)?)?
     ;
 
-// Show Continuous Queries
-showContinuousQueries
-    : SHOW (CONTINUOUS QUERIES | CQS)
+timeoutPolicyClause
+    : TIMEOUT POLICY (BLOCKED | DISCARD)
     ;
 
-// Show TTL
-showTTL
-    : SHOW TTL ON prefixPath (COMMA prefixPath)*
+// ---- Drop Continuous Query
+dropContinuousQuery
+    : DROP (CONTINUOUS QUERY|CQ) cqId=identifier
     ;
 
-// Show All TTL
-showAllTTL
-    : SHOW ALL TTL
+// ---- Show Continuous Queries
+showContinuousQueries
+    : SHOW (CONTINUOUS QUERIES | CQS)
     ;
 
-// Show Variables
+
+// Cluster 
=========================================================================================
+// ---- Show Variables
 showVariables
     : SHOW VARIABLES
     ;
 
-// Show Cluster
+// ---- Show Cluster
 showCluster
     : SHOW CLUSTER (DETAILS)?
     ;
 
-// Show Region
-showRegion
+// ---- Show Regions
+showRegions
     : SHOW (SCHEMA | DATA)? REGIONS (OF (STORAGE GROUP | DATABASE) prefixPath? 
(COMMA prefixPath)*)?
         (ON NODEID INTEGER_LITERAL (COMMA INTEGER_LITERAL)*)?
     ;
 
-// Show Data Nodes
+// ---- Show Data Nodes
 showDataNodes
     : SHOW DATANODES
     ;
 
-// Show Config Nodes
+// ---- Show Config Nodes
 showConfigNodes
     : SHOW CONFIGNODES
     ;
 
-// Show Schema Template
-showSchemaTemplates
-    : SHOW SCHEMA TEMPLATES
-    ;
-
-// Show Measurements In Schema Template
-showNodesInSchemaTemplate
-    : SHOW NODES OPERATOR_IN SCHEMA TEMPLATE templateName=identifier
-    ;
-
-// Show Paths Set Schema Template
-showPathsSetSchemaTemplate
-    : SHOW PATHS SET SCHEMA TEMPLATE templateName=identifier
-    ;
-
-// Show Paths Using Schema Template
-showPathsUsingSchemaTemplate
-    : SHOW PATHS prefixPath? USING SCHEMA TEMPLATE templateName=identifier
-    ;
-
-// Count Storage Group
-countStorageGroup
-    : COUNT (STORAGE GROUP | DATABASES) prefixPath?
-    ;
-
-// Count Devices
-countDevices
-    : COUNT DEVICES prefixPath?
+// ---- Get Region Id
+getRegionId
+    : SHOW (DATA|SCHEMA) REGIONID OF path=prefixPath WHERE (SERIESSLOTID 
operator_eq
+        seriesSlot=INTEGER_LITERAL|DEVICEID operator_eq deviceId=prefixPath) 
(OPERATOR_AND (TIMESLOTID operator_eq timeSlot=INTEGER_LITERAL|
+        TIMESTAMP operator_eq timeStamp=INTEGER_LITERAL))?
     ;
 
-// Count Timeseries
-countTimeseries
-    : COUNT TIMESERIES prefixPath? tagWhereClause? (GROUP BY LEVEL operator_eq 
INTEGER_LITERAL)?
+// ---- Get Time Slot List
+getTimeSlotList
+    : SHOW TIMESLOTID OF path=prefixPath WHERE SERIESSLOTID operator_eq 
seriesSlot=INTEGER_LITERAL
+        (OPERATOR_AND STARTTIME operator_eq startTime=INTEGER_LITERAL)?
+        (OPERATOR_AND ENDTIME operator_eq endTime=INTEGER_LITERAL)?
     ;
 
-// Count Nodes
-countNodes
-    : COUNT NODES prefixPath LEVEL operator_eq INTEGER_LITERAL
+// ---- Get Series Slot List
+getSeriesSlotList
+    : SHOW (DATA|SCHEMA)? SERIESSLOTID OF path=prefixPath
     ;
 
-tagWhereClause
-    : WHERE (attributePair | containsExpression)
+// ---- Migrate Region
+migrateRegion
+    : MIGRATE REGION regionId=INTEGER_LITERAL FROM fromId=INTEGER_LITERAL TO 
toId=INTEGER_LITERAL
     ;
 
 
@@ -873,10 +901,6 @@ prefixPath
     : ROOT (DOT nodeName)*
     ;
 
-suffixPath
-    : nodeName (DOT nodeName)*
-    ;
-
 intoPath
     : ROOT (DOT nodeNameInIntoPath)* #fullPathInIntoPath
     | nodeNameInIntoPath (DOT nodeNameInIntoPath)* #suffixPathInIntoPath
@@ -1011,3 +1035,8 @@ attributeValue
     : identifier
     | constant
     ;
+
+alias
+    : constant
+    | identifier
+    ;

Reply via email to