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

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

commit 7dec34a373dd31a72b7eeb0bdc8ef2e45de34aa3
Author: liuminghui233 <[email protected]>
AuthorDate: Sat May 28 23:13:57 2022 +0800

    support create storage group
---
 .../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4   | 14 ++++--
 .../iotdb/db/mpp/plan/parser/ASTVisitor.java       | 55 +++++++++++++++-------
 2 files changed, 47 insertions(+), 22 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 326eac60b0..bc8167772e 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
@@ -76,15 +76,19 @@ syncStatement
 
 // Create Storage Group
 setStorageGroup
-    : SET STORAGE GROUP TO prefixPath (WITH storageGroupAttributeClause (COMMA 
storageGroupAttributeClause)*)?
+    : SET STORAGE GROUP TO prefixPath storageGroupAttributesClause?
     ;
 
-storageGroupAttributeClause
-    : (TTL | SCHEMA_REPLICATION_FACTOR | DATA_REPLICATION_FACTOR | 
TIME_PARTITION_INTERVAL) '=' INTEGER_LITERAL
+createStorageGroup
+    : CREATE STORAGE GROUP prefixPath storageGroupAttributesClause?
     ;
 
-createStorageGroup
-    : CREATE STORAGE GROUP prefixPath
+storageGroupAttributesClause
+    : WITH storageGroupAttributeClause (COMMA storageGroupAttributeClause)*
+    ;
+
+storageGroupAttributeClause
+    : (TTL | SCHEMA_REPLICATION_FACTOR | DATA_REPLICATION_FACTOR | 
TIME_PARTITION_INTERVAL) '=' INTEGER_LITERAL
     ;
 
 // Create Timeseries
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
index 652a8dbe3a..8d0f4ed71e 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
@@ -1643,32 +1643,53 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
     return privileges.toArray(new String[0]);
   }
 
+  // Create Storage Group
+
   @Override
   public Statement visitSetStorageGroup(IoTDBSqlParser.SetStorageGroupContext 
ctx) {
     SetStorageGroupStatement setStorageGroupStatement = new 
SetStorageGroupStatement();
     PartialPath path = parsePrefixPath(ctx.prefixPath());
     setStorageGroupStatement.setStorageGroupPath(path);
-    if (ctx.storageGroupAttributeClause() != null) {
-      for (IoTDBSqlParser.StorageGroupAttributeClauseContext attribute :
-          ctx.storageGroupAttributeClause()) {
-        if (attribute.TTL() != null) {
-          long ttl = Long.parseLong(attribute.INTEGER_LITERAL().getText());
-          setStorageGroupStatement.setTtl(ttl);
-        } else if (attribute.SCHEMA_REPLICATION_FACTOR() != null) {
-          int schemaReplicationFactor = 
Integer.parseInt(attribute.INTEGER_LITERAL().getText());
-          
setStorageGroupStatement.setSchemaReplicationFactor(schemaReplicationFactor);
-        } else if (attribute.DATA_REPLICATION_FACTOR() != null) {
-          int dataReplicationFactor = 
Integer.parseInt(attribute.INTEGER_LITERAL().getText());
-          
setStorageGroupStatement.setDataReplicationFactor(dataReplicationFactor);
-        } else if (attribute.TIME_PARTITION_INTERVAL() != null) {
-          long timePartitionInterval = 
Long.parseLong(attribute.INTEGER_LITERAL().getText());
-          
setStorageGroupStatement.setTimePartitionInterval(timePartitionInterval);
-        }
-      }
+    if (ctx.storageGroupAttributesClause() != null) {
+      parseStorageGroupAttributesClause(
+          setStorageGroupStatement, ctx.storageGroupAttributesClause());
     }
     return setStorageGroupStatement;
   }
 
+  @Override
+  public Statement 
visitCreateStorageGroup(IoTDBSqlParser.CreateStorageGroupContext ctx) {
+    SetStorageGroupStatement setStorageGroupStatement = new 
SetStorageGroupStatement();
+    PartialPath path = parsePrefixPath(ctx.prefixPath());
+    setStorageGroupStatement.setStorageGroupPath(path);
+    if (ctx.storageGroupAttributesClause() != null) {
+      parseStorageGroupAttributesClause(
+          setStorageGroupStatement, ctx.storageGroupAttributesClause());
+    }
+    return setStorageGroupStatement;
+  }
+
+  private void parseStorageGroupAttributesClause(
+      SetStorageGroupStatement setStorageGroupStatement,
+      IoTDBSqlParser.StorageGroupAttributesClauseContext ctx) {
+    for (IoTDBSqlParser.StorageGroupAttributeClauseContext attribute :
+        ctx.storageGroupAttributeClause()) {
+      if (attribute.TTL() != null) {
+        long ttl = Long.parseLong(attribute.INTEGER_LITERAL().getText());
+        setStorageGroupStatement.setTtl(ttl);
+      } else if (attribute.SCHEMA_REPLICATION_FACTOR() != null) {
+        int schemaReplicationFactor = 
Integer.parseInt(attribute.INTEGER_LITERAL().getText());
+        
setStorageGroupStatement.setSchemaReplicationFactor(schemaReplicationFactor);
+      } else if (attribute.DATA_REPLICATION_FACTOR() != null) {
+        int dataReplicationFactor = 
Integer.parseInt(attribute.INTEGER_LITERAL().getText());
+        
setStorageGroupStatement.setDataReplicationFactor(dataReplicationFactor);
+      } else if (attribute.TIME_PARTITION_INTERVAL() != null) {
+        long timePartitionInterval = 
Long.parseLong(attribute.INTEGER_LITERAL().getText());
+        
setStorageGroupStatement.setTimePartitionInterval(timePartitionInterval);
+      }
+    }
+  }
+
   @Override
   public Statement visitSetTTL(IoTDBSqlParser.SetTTLContext ctx) {
     SetTTLStatement setTTLStatement = new SetTTLStatement();

Reply via email to