morrySnow commented on code in PR #31585:
URL: https://github.com/apache/doris/pull/31585#discussion_r1507134490


##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -717,6 +722,21 @@ primaryExpression
     | primaryExpression COLLATE (identifier | STRING_LITERAL | DEFAULT)        
                #collate
     ;
 
+partitionFunctionCallExpression
+    : LEFT_PAREN partitionFunctionList RIGHT_PAREN
+    ;
+
+partitionFunctionList
+    : functions+=partitionFunction (COMMA functions+=partitionFunction)*
+    ;
+
+partitionFunction

Review Comment:
   it is better use `functionCallExpression` directly, and in 
LogicalPlanBuilder check return expression is `UnboundFunction`



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -2470,11 +2450,11 @@ public LogicalPlan visitCreateTable(CreateTableContext 
ctx) {
                     keysType,
                     ctx.keys != null ? visitIdentifierList(ctx.keys) : 
ImmutableList.of(),
                     "",
-                    isAutoPartition,
-                    autoPartitionExpr.build(),
-                    partitionType,
-                    ctx.partitionKeys != null ? 
visitIdentifierList(ctx.partitionKeys) : null,
-                    ctx.partitions != null ? 
visitPartitionsDef(ctx.partitions) : null,
+                    partitionInfo.isAutoPartition(),

Review Comment:
   if u aready merge all partition info into one class, u'd better update 
`CreateTableInfo`'s ctor to accept `PartitionTableInfo` as parameter



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -2512,6 +2492,75 @@ public List<ColumnDefinition> 
visitColumnDefs(ColumnDefsContext ctx) {
         return 
ctx.cols.stream().map(this::visitColumnDef).collect(Collectors.toList());
     }
 
+    @Override
+    public PartitionTableInfo 
visitPartitionForInternal(DorisParser.PartitionForInternalContext ctx) {
+        boolean isAutoPartition = ctx.autoPartition != null;
+        ImmutableList.Builder<Expression> autoPartitionExpr = new 
ImmutableList.Builder<>();
+        if (isAutoPartition) {
+            if (ctx.RANGE() != null) {
+                // AUTO PARTITION BY RANGE FUNC_CALL_EXPR
+                if (ctx.partitionExpr != null) {
+                    
autoPartitionExpr.add(visitFunctionCallExpression(ctx.partitionExpr));
+                } else {
+                    throw new AnalysisException(
+                        "AUTO PARTITION BY RANGE must provide a function 
expr");
+                }
+            } else {
+                // AUTO PARTITION BY LIST(`partition_col`)
+                if (ctx.partitionKeys != null) {
+                    // only support one column in auto partition
+                    
autoPartitionExpr.addAll(visitIdentifierList(ctx.partitionKeys).stream()
+                            .distinct().map(name -> UnboundSlot.quoted(name))
+                            .collect(Collectors.toList()));
+                } else {
+                    throw new AnalysisException(
+                        "AUTO PARTITION BY List must provide a partition 
column");
+                }
+            }
+        }
+        return new PartitionTableInfo(
+                isAutoPartition,
+                autoPartitionExpr.build(),
+                ctx.RANGE() != null ? "RANGE" : "LIST",
+                ctx.partitionKeys != null ? 
visitIdentifierList(ctx.partitionKeys) : null,
+                ctx.partitions != null ? visitPartitionsDef(ctx.partitions) : 
null);
+    }
+
+    @Override
+    public PartitionTableInfo 
visitPartitionForExternal(DorisParser.PartitionForExternalContext ctx) {
+        ImmutableList.Builder<Expression> partitionExpr = new 
ImmutableList.Builder<>();
+        if (ctx.partitionExpr != null) {
+            
partitionExpr.addAll(visitPartitionFunctionCallExpression(ctx.partitionExpr));
+        }
+
+        return new PartitionTableInfo(
+                false,
+                partitionExpr.build(),
+                "",
+                null,
+                null);
+    }
+
+    @Override
+    public List<Expression> visitPartitionFunctionCallExpression(
+                DorisParser.PartitionFunctionCallExpressionContext ctx) {
+        return visitPartitionFunctionList(ctx.partitionFunctionList());
+    }
+
+    @Override
+    public List<Expression> 
visitPartitionFunctionList(DorisParser.PartitionFunctionListContext ctx) {
+        return ctx.functions.stream()
+            .map(this::visitPartitionFunction)
+            .collect(ImmutableList.toImmutableList());
+    }
+
+    @Override
+    public Expression 
visitPartitionFunction(DorisParser.PartitionFunctionContext ctx) {
+        String name = ctx.identity.getText();
+        List<Expression> params = visit(ctx.expression(), Expression.class);

Review Comment:
   do u test this syntax? i think u want get is ctx.arguments()



##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -717,6 +722,21 @@ primaryExpression
     | primaryExpression COLLATE (identifier | STRING_LITERAL | DEFAULT)        
                #collate
     ;
 
+partitionFunctionCallExpression
+    : LEFT_PAREN partitionFunctionList RIGHT_PAREN
+    ;
+
+partitionFunctionList
+    : functions+=partitionFunction (COMMA functions+=partitionFunction)*
+    ;
+

Review Comment:
   why not merge this two statement into one?
   ```
   LEFT_PAREN functions+=partitionFunction (COMMA 
functions+=partitionFunction)* RIGHT_PAREN
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to