morrySnow commented on code in PR #24301: URL: https://github.com/apache/doris/pull/24301#discussion_r1326135628
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortBy.java: ########## @@ -0,0 +1,98 @@ +// 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.DataType; +import org.apache.doris.nereids.types.LambdaType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +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_sortby'. + */ +public class ArraySortBy extends ScalarFunction + implements ExplicitlyCastableSignature { + + public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( + FunctionSignature.ret(new FollowToAnyDataType(0)).args(LambdaType.INSTANCE) + ); + + /** + * constructor with arguments. + * array_sortby(lambda, a1, ...) = array_sortby(a1, array_map(lambda, a1, ...)) + */ + private ArraySortBy(Lambda lambda) { + super("array_sortby", lambda.getLambdaArgument(0).getArrayExpression(), new ArrayMap(lambda)); + } + + private ArraySortBy(List<Expression> expressions) { + super("array_sortby", expressions); + } + + public ArraySortBy(Expression arg) { + this((Lambda) arg); + } + + @Override + public ArraySortBy withChildren(List<Expression> children) { + Preconditions.checkArgument(children.size() == 2 && !(children.get(0) instanceof Lambda), + getName() + " accept wrong arguments " + children); + return new ArraySortBy(children); + } + + @Override + public DataType getDataType() { + return children.get(0).getDataType(); + } + + @Override + public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { + return visitor.visitArraySortBy(this, context); + } + + @Override + public List<FunctionSignature> getSignatures() { + return SIGNATURES; + } + + @Override + public List<DataType> expectedInputTypes() { + return ImmutableList.of(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX), + ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)); + } + + @Override + public boolean nullable() { + return children.get(0).nullable(); + } + + @Override + public boolean hasVarArguments() { + return false; + } Review Comment: do we need override this function? ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayFirstIndex.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_first_index'. + */ +public class ArrayFirstIndex extends ScalarFunction + implements ExplicitlyCastableSignature { + + public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( + FunctionSignature.ret(new FollowToAnyDataType(0)).args(LambdaType.INSTANCE) + ); + + /** + * constructor with arguments. + * array_first_index(lambda, a1, ...) = array_first_index(array_map(lambda, a1, ...)) + */ + private ArrayFirstIndex(Lambda lambda) { + super("array_first_index", new ArrayMap(lambda)); + } + + private ArrayFirstIndex(List<Expression> expressions) { + super("array_first_index", expressions); + } + + public ArrayFirstIndex(Expression arg) { + this((Lambda) arg); + } + + /** + * withChildren. + */ + @Override + public ArrayFirstIndex withChildren(List<Expression> children) { + Preconditions.checkArgument(children.size() == 1 && !(children.get(0) instanceof Lambda), + getName() + " accept wrong arguments " + children); + return new ArrayFirstIndex(children); + } + + @Override + public DataType getDataType() { + return BigIntType.INSTANCE; + } + + @Override + public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { + return visitor.visitArrayFirstIndex(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: i think we do not need to override this interface ########## 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); Review Comment: use message template rather than string concat, for example ```java ..., "%s accept wrong arguments %s", getName(), children); ``` ########## 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; + } Review Comment: i think the u should change the ret type in signature, and remove this function ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayExists.java: ########## Review Comment: u should change all of these functions just like comments in `ArrayCount.java` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayLastIndex.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_last_index'. + */ +public class ArrayLastIndex extends ScalarFunction + implements ExplicitlyCastableSignature { + + public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( + FunctionSignature.ret(new FollowToAnyDataType(0)).args(LambdaType.INSTANCE) + ); + + /** + * constructor with arguments. + * array_last_index(lambda, a1, ...) = array_last_index(array_map(lambda, a1, ...)) + */ + private ArrayLastIndex(Lambda lambda) { + super("array_last_index", new ArrayMap(lambda)); + } + + private ArrayLastIndex(List<Expression> expressions) { + super("array_last_index", expressions); + } + + public ArrayLastIndex(Expression arg) { + this((Lambda) arg); + } + + /** + * withChildren. + */ + @Override + public ArrayLastIndex withChildren(List<Expression> children) { + Preconditions.checkArgument(children.size() == 1 && !(children.get(0) instanceof Lambda), + getName() + " accept wrong arguments " + children); + return new ArrayLastIndex(children); + } + + @Override + public DataType getDataType() { + return BigIntType.INSTANCE; + } + + @Override + public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { + return visitor.visitArrayLastIndex(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: ditto ########## 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) Review Comment: ```suggestion FunctionSignature.ret(BigintType.INSTANCE).args(LambdaType.INSTANCE) ``` ########## 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: do not need override this function ########## 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; + } Review Comment: use `AlwaysNotNullable` ########## 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)); + } Review Comment: why expectedInputTypes is only `array<boolean>`? it is unreasonable -- 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