XieJiann commented on code in PR #24301:
URL: https://github.com/apache/doris/pull/24301#discussion_r1326709935


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayCount.java:
##########
@@ -0,0 +1,101 @@
+// 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.scalar;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.ArrayType;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.BooleanType;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.LambdaType;
+import org.apache.doris.nereids.types.coercion.FollowToAnyDataType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * ScalarFunction 'array_count'.
+ */
+public class ArrayCount extends ScalarFunction
+        implements ExplicitlyCastableSignature {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            FunctionSignature.ret(new 
FollowToAnyDataType(0)).args(LambdaType.INSTANCE)
+    );
+
+    /**
+     * constructor with arguments.
+     * array_count(lambda, a1, ...) = array_count(array_map(lambda, a1, ...))
+     */
+    private ArrayCount(Lambda lambda) {
+        super("array_count", new ArrayMap(lambda));
+    }
+
+    private ArrayCount(List<Expression> expressions) {
+        super("array_count", expressions);
+    }
+
+    public ArrayCount(Expression arg) {
+        this((Lambda) arg);
+    }
+
+    /**
+     * withChildren.
+     */
+    @Override
+    public ArrayCount withChildren(List<Expression> children) {
+        Preconditions.checkArgument(children.size() == 1 && !(children.get(0) 
instanceof Lambda),
+                getName() + " accept wrong arguments " + children);
+        return new ArrayCount(children);
+    }
+
+    @Override
+    public DataType getDataType() {
+        return BigIntType.INSTANCE;
+    }
+
+    @Override
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitArrayCount(this, context);
+    }
+
+    @Override
+    public List<FunctionSignature> getSignatures() {
+        return SIGNATURES;
+    }
+
+    @Override
+    public boolean nullable() {
+        return false;
+    }
+
+    @Override
+    public List<DataType> expectedInputTypes() {
+        return ImmutableList.of(ArrayType.of(BooleanType.INSTANCE));
+    }
+
+    @Override
+    public boolean hasVarArguments() {
+        return false;
+    }

Review Comment:
   It's a trick. For this function, its children are not equal to their 
signature. 
    For example: `array_count(lambda) ==> array_count(array_map(lambda))`. 
Therefore, we need to avoid calling `getSignatures()` to avoid the check 
failed. And `hasVarArguments` calls this function.
   I'm not sure this is a good idea



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to