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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java:
##########
@@ -100,6 +102,13 @@ public GroupConcat(Expression arg0, Expression arg1, 
OrderExpression... orders)
     public GroupConcat(boolean distinct, boolean alwaysNullable, int 
nonOrderArguments, List<Expression> args) {
         super("group_concat", distinct, alwaysNullable, args);
         this.nonOrderArguments = nonOrderArguments;
+        checkArguments();
+    }
+
+    @Override
+    public boolean nullable() {
+        return children().stream()
+                .anyMatch(expression -> !(expression instanceof 
OrderExpression) && expression.nullable());

Review Comment:
   this is not right, we need to process scalar agg(no group by), so the class 
implement `NullableAggregateFunction`, when `alwaysNullable` set to `true`, 
`nullable()` need to return `true`.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java:
##########
@@ -0,0 +1,164 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.expressions.functions.agg;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.OrderExpression;
+import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.VarcharType;
+import org.apache.doris.nereids.types.coercion.AnyDataType;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/** MultiDistinctGroupConcat */
+public class MultiDistinctGroupConcat extends NullableAggregateFunction
+        implements ExplicitlyCastableSignature {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT),
+            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT,
+                    AnyDataType.INSTANCE),
+            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT,
+                    VarcharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE));
+
+    private final int nonOrderArguments;
+
+    /**
+     * constructor with 1 argument.
+     */
+    public MultiDistinctGroupConcat(boolean alwaysNullable, Expression arg,
+            OrderExpression... orders) {
+        super("multi_distinct_group_concat", true, alwaysNullable,
+                ExpressionUtils.mergeArguments(arg, orders));
+        this.nonOrderArguments = 1;
+    }
+
+    /**
+     * constructor with 1 argument.
+     */
+    public MultiDistinctGroupConcat(Expression arg, OrderExpression... orders) 
{
+        this(false, arg, orders);
+    }
+
+    /**
+     * constructor with 2 arguments.
+     */
+    public MultiDistinctGroupConcat(boolean alwaysNullable, Expression arg0,
+            Expression arg1, OrderExpression... orders) {
+        super("multi_distinct_group_concat", true, alwaysNullable,
+                ExpressionUtils.mergeArguments(arg0, arg1, orders));
+        this.nonOrderArguments = 2;
+    }
+
+    /**
+     * constructor with 2 arguments.
+     */
+    public MultiDistinctGroupConcat(Expression arg0, Expression arg1, 
OrderExpression... orders) {
+        this(false, arg0, arg1, orders);
+    }
+
+    /**
+     * constructor for always nullable.
+     */
+    public MultiDistinctGroupConcat(boolean alwaysNullable, int 
nonOrderArguments,
+            List<Expression> args) {
+        super("multi_distinct_group_concat", true, alwaysNullable, args);
+        this.nonOrderArguments = nonOrderArguments;
+    }
+
+    @Override
+    public boolean nullable() {
+        return children().stream()
+                .anyMatch(expression -> !(expression instanceof 
OrderExpression) && expression.nullable());
+    }

Review Comment:
   same as GroupConcat



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java:
##########
@@ -55,6 +55,7 @@ public class GroupConcat extends NullableAggregateFunction
     public GroupConcat(boolean distinct, boolean alwaysNullable, Expression 
arg, OrderExpression... orders) {
         super("group_concat", distinct, alwaysNullable, 
ExpressionUtils.mergeArguments(arg, orders));
         this.nonOrderArguments = 1;
+        checkArguments();

Review Comment:
   if u change the signature of legacy planner, u should also change it in 
Nereids



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java:
##########
@@ -0,0 +1,164 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.expressions.functions.agg;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.OrderExpression;
+import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.VarcharType;
+import org.apache.doris.nereids.types.coercion.AnyDataType;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/** MultiDistinctGroupConcat */
+public class MultiDistinctGroupConcat extends NullableAggregateFunction
+        implements ExplicitlyCastableSignature {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT),
+            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT,
+                    AnyDataType.INSTANCE),
+            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT,
+                    VarcharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE));
+
+    private final int nonOrderArguments;
+
+    /**
+     * constructor with 1 argument.
+     */
+    public MultiDistinctGroupConcat(boolean alwaysNullable, Expression arg,
+            OrderExpression... orders) {
+        super("multi_distinct_group_concat", true, alwaysNullable,
+                ExpressionUtils.mergeArguments(arg, orders));
+        this.nonOrderArguments = 1;
+    }
+
+    /**
+     * constructor with 1 argument.
+     */
+    public MultiDistinctGroupConcat(Expression arg, OrderExpression... orders) 
{
+        this(false, arg, orders);
+    }
+
+    /**
+     * constructor with 2 arguments.
+     */
+    public MultiDistinctGroupConcat(boolean alwaysNullable, Expression arg0,
+            Expression arg1, OrderExpression... orders) {
+        super("multi_distinct_group_concat", true, alwaysNullable,
+                ExpressionUtils.mergeArguments(arg0, arg1, orders));
+        this.nonOrderArguments = 2;
+    }
+
+    /**
+     * constructor with 2 arguments.
+     */
+    public MultiDistinctGroupConcat(Expression arg0, Expression arg1, 
OrderExpression... orders) {
+        this(false, arg0, arg1, orders);
+    }
+
+    /**
+     * constructor for always nullable.
+     */
+    public MultiDistinctGroupConcat(boolean alwaysNullable, int 
nonOrderArguments,
+            List<Expression> args) {
+        super("multi_distinct_group_concat", true, alwaysNullable, args);
+        this.nonOrderArguments = nonOrderArguments;
+    }
+
+    @Override
+    public boolean nullable() {
+        return children().stream()
+                .anyMatch(expression -> !(expression instanceof 
OrderExpression) && expression.nullable());
+    }
+
+    @Override
+    public void checkLegalityBeforeTypeCoercion() {
+        DataType typeOrArg0 = getArgumentType(0);
+        if (!typeOrArg0.isStringLikeType() && !typeOrArg0.isNullType()) {
+            throw new AnalysisException(
+                    "multi_distinct_group_concat requires first parameter to 
be of type STRING: "
+                            + this.toSql());
+        }
+
+        if (nonOrderArguments == 2) {
+            DataType typeOrArg1 = getArgumentType(1);
+            if (!typeOrArg1.isStringLikeType() && !typeOrArg1.isNullType()) {
+                throw new AnalysisException(
+                        "multi_distinct_group_concat requires second parameter 
to be of type STRING: "
+                                + this.toSql());
+            }
+        }
+    }

Review Comment:
   i don't think it could work as u expect since 
`checkLegalityBeforeTypeCoercion` only called in `FunctionBinder`



-- 
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