From c3bd2a22d48b01649c029e2c5bac78ecd7918e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=81=A5?= Date: Tue, 19 Sep 2023 18:58:49 +0800 Subject: [PATCH] [feature](Nereids) add many array functions (#24301) Add function array_filter, array_sortby, array_last_index, array_first_index, array_orderby, array_count --- .../doris/catalog/BuiltinScalarFunctions.java | 12 + .../glue/translator/ExpressionTranslator.java | 4 + .../functions/scalar/ArrayCount.java | 76 + .../functions/scalar/ArrayExists.java | 75 + .../functions/scalar/ArrayFilter.java | 68 + .../functions/scalar/ArrayFirstIndex.java | 76 + .../functions/scalar/ArrayLastIndex.java | 76 + .../functions/scalar/ArraySortBy.java | 73 + .../functions/scalar/HighOrderFunction.java | 42 + .../visitor/ScalarFunctionVisitor.java | 30 + .../scalar_function/Array.out | 1624 +++++++++++++++++ .../script/array_func_generator.py | 58 + .../scalar_function/Array.groovy | 119 ++ 13 files changed, 2333 insertions(+) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayCount.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayExists.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayFilter.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayFirstIndex.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayLastIndex.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortBy.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HighOrderFunction.java create mode 100644 regression-test/script/array_func_generator.py diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java index 1a2d064d2b..1b20af39a1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java @@ -28,13 +28,18 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Array; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayAvg; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCompact; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayContains; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCount; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCumSum; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayDifference; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayDistinct; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayEnumerate; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayExcept; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayExists; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayFilter; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayFirstIndex; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayIntersect; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayJoin; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayLastIndex; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMap; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMax; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMin; @@ -47,6 +52,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRemove; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayReverseSort; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySlice; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySort; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySortBy; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySum; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayUnion; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayWithConstant; @@ -387,13 +393,18 @@ public class BuiltinScalarFunctions implements FunctionHelper { scalar(ArrayAvg.class, "array_avg"), scalar(ArrayCompact.class, "array_compact"), scalar(ArrayContains.class, "array_contains"), + scalar(ArrayCount.class, "array_count"), scalar(ArrayCumSum.class, "array_cum_sum"), scalar(ArrayDifference.class, "array_difference"), scalar(ArrayDistinct.class, "array_distinct"), scalar(ArrayEnumerate.class, "array_enumerate"), scalar(ArrayExcept.class, "array_except"), + scalar(ArrayExists.class, "array_exists"), + scalar(ArrayFilter.class, "array_filter"), + scalar(ArrayFirstIndex.class, "array_first_index"), scalar(ArrayIntersect.class, "array_intersect"), scalar(ArrayJoin.class, "array_join"), + scalar(ArrayLastIndex.class, "array_last_index"), scalar(ArrayMap.class, "array_map"), scalar(ArrayMax.class, "array_max"), scalar(ArrayMin.class, "array_min"), @@ -406,6 +417,7 @@ public class BuiltinScalarFunctions implements FunctionHelper { scalar(ArrayReverseSort.class, "array_reverse_sort"), scalar(ArraySlice.class, "array_slice"), scalar(ArraySort.class, "array_sort"), + scalar(ArraySortBy.class, "array_sortby"), scalar(ArraySum.class, "array_sum"), scalar(ArrayUnion.class, "array_union"), scalar(ArrayWithConstant.class, "array_with_constant"), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java index d120a7ece4..d2a16c29b8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java @@ -472,6 +472,10 @@ public class ExpressionTranslator extends DefaultExpressionVisitor SIGNATURES = ImmutableList.of( + FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE)) + ); + + private ArrayCount(List expressions) { + super("array_count", expressions); + } + + /** + * constructor with arguments. + * array_count(lambda, a1, ...) = array_count(array_map(lambda, a1, ...)) + */ + public ArrayCount(Expression arg) { + super("array_count", new ArrayMap(arg)); + if (!(arg instanceof Lambda)) { + throw new AnalysisException( + String.format("The 1st arg of %s must be lambda but is %s", getName(), arg)); + } + } + + /** + * withChildren. + */ + @Override + public ArrayCount withChildren(List children) { + return new ArrayCount(children); + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayCount(this, context); + } + + @Override + public List getImplSignature() { + return SIGNATURES; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayExists.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayExists.java new file mode 100644 index 0000000000..deaf8a1496 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayExists.java @@ -0,0 +1,75 @@ +// 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.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.types.ArrayType; +import org.apache.doris.nereids.types.BooleanType; + +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_exists'. + */ +public class ArrayExists extends ScalarFunction + implements HighOrderFunction, PropagateNullable { + + public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(ArrayType.of(BooleanType.INSTANCE)) + ); + + private ArrayExists(List expressions) { + super("array_exists", expressions); + } + + /** + * constructor with arguments. + * array_exists(lambda, a1, ...) = array_exists(array_map(lambda, a1, ...)) + */ + public ArrayExists(Expression arg) { + super("array_exists", new ArrayMap(arg)); + if (!(arg instanceof Lambda)) { + throw new AnalysisException( + String.format("The 1st arg of %s must be lambda but is %s", getName(), arg)); + } + } + + /** + * withChildren. + */ + @Override + public ArrayExists withChildren(List children) { + return new ArrayExists(children); + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayExists(this, context); + } + + @Override + public List getImplSignature() { + return SIGNATURES; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayFilter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayFilter.java new file mode 100644 index 0000000000..1e8f1c5acb --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayFilter.java @@ -0,0 +1,68 @@ +// 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.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; +import org.apache.doris.nereids.types.ArrayType; +import org.apache.doris.nereids.types.BooleanType; +import org.apache.doris.nereids.types.coercion.AnyDataType; + +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_filter'. + */ +public class ArrayFilter extends ScalarFunction + implements HighOrderFunction, PropagateNullable { + + public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX), + ArrayType.of(BooleanType.INSTANCE)) + ); + + private ArrayFilter(List expressions) { + super("array_filter", expressions); + } + + /** + * constructor with arguments. + * array_filter(lambda, a1, ...) = array_filter(a1, array_map(lambda, a1, ...)) + */ + public ArrayFilter(Expression arg) { + super("array_filter", arg.child(1).child(0), new ArrayMap(arg)); + if (!(arg instanceof Lambda)) { + throw new AnalysisException( + String.format("The 1st arg of %s must be lambda but is %s", getName(), arg)); + } + } + + @Override + public ArrayFilter withChildren(List children) { + return new ArrayFilter(children); + } + + @Override + public List getImplSignature() { + return SIGNATURES; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayFirstIndex.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayFirstIndex.java new file mode 100644 index 0000000000..fef17fe8a1 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayFirstIndex.java @@ -0,0 +1,76 @@ +// 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.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; +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 com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_first_index'. + */ +public class ArrayFirstIndex extends ScalarFunction + implements HighOrderFunction, AlwaysNotNullable { + + public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE)) + ); + + private ArrayFirstIndex(List expressions) { + super("array_first_index", expressions); + } + + /** + * constructor with arguments. + * array_first_index(lambda, a1, ...) = array_first_index(array_map(lambda, a1, ...)) + */ + public ArrayFirstIndex(Expression arg) { + super("array_first_index", new ArrayMap(arg)); + if (!(arg instanceof Lambda)) { + throw new AnalysisException( + String.format("The 1st arg of %s must be lambda but is %s", getName(), arg)); + } + } + + /** + * withChildren. + */ + @Override + public ArrayFirstIndex withChildren(List children) { + return new ArrayFirstIndex(children); + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayFirstIndex(this, context); + } + + @Override + public List getImplSignature() { + return SIGNATURES; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayLastIndex.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayLastIndex.java new file mode 100644 index 0000000000..6ae19884ae --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayLastIndex.java @@ -0,0 +1,76 @@ +// 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.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; +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 com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_last_index'. + */ +public class ArrayLastIndex extends ScalarFunction + implements HighOrderFunction, AlwaysNotNullable { + + public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE)) + ); + + private ArrayLastIndex(List expressions) { + super("array_last_index", expressions); + } + + /** + * constructor with arguments. + * array_last_index(lambda, a1, ...) = array_last_index(array_map(lambda, a1, ...)) + */ + public ArrayLastIndex(Expression arg) { + super("array_last_index", new ArrayMap(arg)); + if (!(arg instanceof Lambda)) { + throw new AnalysisException( + String.format("The 1st arg of %s must be lambda but is %s", getName(), arg)); + } + } + + /** + * withChildren. + */ + @Override + public ArrayLastIndex withChildren(List children) { + return new ArrayLastIndex(children); + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayLastIndex(this, context); + } + + @Override + public List getImplSignature() { + return SIGNATURES; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortBy.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortBy.java new file mode 100644 index 0000000000..ea4ac04aca --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortBy.java @@ -0,0 +1,73 @@ +// 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.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.types.ArrayType; +import org.apache.doris.nereids.types.coercion.AnyDataType; + +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_sortby'. + */ +public class ArraySortBy extends ScalarFunction + implements HighOrderFunction, PropagateNullable { + + public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX), + ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) + ); + + private ArraySortBy(List expressions) { + super("array_sortby", expressions); + } + + /** + * constructor with arguments. + * array_sortby(lambda, a1, ...) = array_sortby(a1, array_map(lambda, a1, ...)) + */ + public ArraySortBy(Expression arg) { + super("array_sortby", arg.child(1).child(0), new ArrayMap(arg)); + if (!(arg instanceof Lambda)) { + throw new AnalysisException( + String.format("The 1st arg of %s must be lambda but is %s", getName(), arg)); + } + } + + @Override + public ArraySortBy withChildren(List children) { + return new ArraySortBy(children); + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArraySortBy(this, context); + } + + @Override + public List getImplSignature() { + return SIGNATURES; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HighOrderFunction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HighOrderFunction.java new file mode 100644 index 0000000000..a929f2dd5d --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HighOrderFunction.java @@ -0,0 +1,42 @@ +// 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.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.types.LambdaType; +import org.apache.doris.nereids.types.coercion.AnyDataType; + +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * Interface of HighOrderFunction, provide default FunctionSignature of LambdaType argument + */ +public interface HighOrderFunction extends ExplicitlyCastableSignature { + @Override + default List getSignatures() { + return new ImmutableList.Builder() + .addAll(getImplSignature()) + .add(FunctionSignature.ret(AnyDataType.INSTANCE_WITHOUT_INDEX).args(LambdaType.INSTANCE)) + .build(); + } + + List getImplSignature(); +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java index 75c6644a4d..34068f6ad2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java @@ -32,13 +32,18 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Array; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayAvg; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCompact; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayContains; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCount; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCumSum; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayDifference; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayDistinct; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayEnumerate; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayExcept; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayExists; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayFilter; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayFirstIndex; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayIntersect; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayJoin; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayLastIndex; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMap; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMax; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMin; @@ -51,6 +56,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRemove; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayReverseSort; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySlice; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySort; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySortBy; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySum; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayUnion; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayWithConstant; @@ -411,6 +417,10 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(arrayContains, context); } + default R visitArrayCount(ArrayCount arrayCount, C context) { + return visitScalarFunction(arrayCount, context); + } + default R visitArrayCumSum(ArrayCumSum arrayCumSum, C context) { return visitScalarFunction(arrayCumSum, context); } @@ -431,6 +441,18 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(arrayExcept, context); } + default R visitArrayExists(ArrayExists arrayExists, C context) { + return visitScalarFunction(arrayExists, context); + } + + default R visitArrayFilter(ArrayFilter arrayFilter, C context) { + return visitScalarFunction(arrayFilter, context); + } + + default R visitArrayFirstIndex(ArrayFirstIndex arrayFirstIndex, C context) { + return visitScalarFunction(arrayFirstIndex, context); + } + default R visitArrayIntersect(ArrayIntersect arrayIntersect, C context) { return visitScalarFunction(arrayIntersect, context); } @@ -439,6 +461,10 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(arrayJoin, context); } + default R visitArrayLastIndex(ArrayLastIndex arrayLastIndex, C context) { + return visitScalarFunction(arrayLastIndex, context); + } + default R visitArrayMax(ArrayMax arrayMax, C context) { return visitScalarFunction(arrayMax, context); } @@ -479,6 +505,10 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(arraySort, context); } + default R visitArraySortBy(ArraySortBy arraySortBy, C context) { + return visitScalarFunction(arraySortBy, context); + } + default R visitArrayMap(ArrayMap arraySort, C context) { return visitScalarFunction(arraySort, context); } diff --git a/regression-test/data/nereids_function_p0/scalar_function/Array.out b/regression-test/data/nereids_function_p0/scalar_function/Array.out index 4c5c5b93d9..7c63c9abd8 100644 --- a/regression-test/data/nereids_function_p0/scalar_function/Array.out +++ b/regression-test/data/nereids_function_p0/scalar_function/Array.out @@ -9946,3 +9946,1627 @@ true [1, 1] [1, 1] +-- !sql_array_exists_Double -- +\N +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[1] +[1] + +-- !sql_array_exists_Double_notnull -- +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[1] +[1] + +-- !sql_array_exists_Float -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_Float_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_LargeInt -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_LargeInt_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_BigInt -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_BigInt_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_SmallInt -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_SmallInt_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_Integer -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_Integer_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_exists_TinyInt -- +\N +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] + +-- !sql_array_exists_TinyInt_notnull -- +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] + +-- !sql_array_exists_DecimalV3 -- +\N +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[1, 1] +[1, 1] + +-- !sql_array_exists_DecimalV3_notnull -- +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[1, 1] +[1, 1] + +-- !sql_array_first_index_Double -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 + +-- !sql_array_first_index_Double_notnull -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 + +-- !sql_array_first_index_Float -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_Float_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_LargeInt -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_LargeInt_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_BigInt -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_BigInt_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_SmallInt -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_SmallInt_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_Integer -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_Integer_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_first_index_TinyInt -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 + +-- !sql_array_first_index_TinyInt_notnull -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 + +-- !sql_array_first_index_DecimalV3 -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 + +-- !sql_array_first_index_DecimalV3_notnull -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 + +-- !sql_array_count_Double -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 + +-- !sql_array_count_Double_notnull -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 + +-- !sql_array_count_Float -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_Float_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_LargeInt -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_LargeInt_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_BigInt -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_BigInt_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_SmallInt -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_SmallInt_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_Integer -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_Integer_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_count_TinyInt -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 + +-- !sql_array_count_TinyInt_notnull -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 + +-- !sql_array_count_DecimalV3 -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +2 +2 + +-- !sql_array_count_DecimalV3_notnull -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +2 +2 + +-- !sql_array_map_Double -- +\N +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[1] +[1] + +-- !sql_array_map_Double_notnull -- +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[1] +[1] + +-- !sql_array_map_Float -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_Float_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_LargeInt -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_LargeInt_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_BigInt -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_BigInt_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_SmallInt -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_SmallInt_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_Integer -- +\N +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_Integer_notnull -- +[0] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_map_TinyInt -- +\N +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] + +-- !sql_array_map_TinyInt_notnull -- +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[0] + +-- !sql_array_map_DecimalV3 -- +\N +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[1, 1] +[1, 1] + +-- !sql_array_map_DecimalV3_notnull -- +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[0, 0] +[1, 1] +[1, 1] + +-- !sql_array_filter_Double -- +\N +[1.1] +[1.2] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] + +-- !sql_array_filter_Double_notnull -- +[1.1] +[1.2] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] + +-- !sql_array_filter_Float -- +\N +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_Float_notnull -- +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_LargeInt -- +\N +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_LargeInt_notnull -- +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_BigInt -- +\N +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_BigInt_notnull -- +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_SmallInt -- +\N +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_SmallInt_notnull -- +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_Integer -- +\N +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_Integer_notnull -- +[10] +[11] +[12] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] +[] + +-- !sql_array_filter_TinyInt -- +\N +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] + +-- !sql_array_filter_TinyInt_notnull -- +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] + +-- !sql_array_filter_DecimalV3 -- +\N +[1.100000000, 1.100000000] +[1.200000000, 1.200000000] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] + +-- !sql_array_filter_DecimalV3_notnull -- +[1.100000000, 1.100000000] +[1.200000000, 1.200000000] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] + +-- !sql_array_sortby_Double -- +\N +[0.1] +[0.2] +[0.3] +[0.4] +[0.5] +[0.6] +[0.7] +[0.8] +[0.9] +[1.1] +[1.2] +[1] + +-- !sql_array_sortby_Double_notnull -- +[0.1] +[0.2] +[0.3] +[0.4] +[0.5] +[0.6] +[0.7] +[0.8] +[0.9] +[1.1] +[1.2] +[1] + +-- !sql_array_sortby_Float -- +\N +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_Float_notnull -- +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_LargeInt -- +\N +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_LargeInt_notnull -- +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_BigInt -- +\N +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_BigInt_notnull -- +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_SmallInt -- +\N +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_SmallInt_notnull -- +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_Integer -- +\N +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_Integer_notnull -- +[10] +[11] +[12] +[1] +[2] +[3] +[4] +[5] +[6] +[7] +[8] +[9] + +-- !sql_array_sortby_TinyInt -- +\N +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_sortby_TinyInt_notnull -- +[0] +[0] +[0] +[0] +[0] +[0] +[0] +[1] +[1] +[1] +[1] +[1] + +-- !sql_array_sortby_DecimalV3 -- +\N +[0.100000000, 0.100000000] +[0.200000000, 0.200000000] +[0.300000000, 0.300000000] +[0.400000000, 0.400000000] +[0.500000000, 0.500000000] +[0.600000000, 0.600000000] +[0.700000000, 0.700000000] +[0.800000000, 0.800000000] +[0.900000000, 0.900000000] +[1.000000000, 1.000000000] +[1.100000000, 1.100000000] +[1.200000000, 1.200000000] + +-- !sql_array_sortby_DecimalV3_notnull -- +[0.100000000, 0.100000000] +[0.200000000, 0.200000000] +[0.300000000, 0.300000000] +[0.400000000, 0.400000000] +[0.500000000, 0.500000000] +[0.600000000, 0.600000000] +[0.700000000, 0.700000000] +[0.800000000, 0.800000000] +[0.900000000, 0.900000000] +[1.000000000, 1.000000000] +[1.100000000, 1.100000000] +[1.200000000, 1.200000000] + +-- !sql_array_last_index_Double -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 + +-- !sql_array_last_index_Double_notnull -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 + +-- !sql_array_last_index_Float -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_Float_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_LargeInt -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_LargeInt_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_BigInt -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_BigInt_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_SmallInt -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_SmallInt_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_Integer -- +0 +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_Integer_notnull -- +0 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 + +-- !sql_array_last_index_TinyInt -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 + +-- !sql_array_last_index_TinyInt_notnull -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 + +-- !sql_array_last_index_DecimalV3 -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +2 +2 + +-- !sql_array_last_index_DecimalV3_notnull -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +2 +2 + diff --git a/regression-test/script/array_func_generator.py b/regression-test/script/array_func_generator.py new file mode 100644 index 0000000000..c46f9ae762 --- /dev/null +++ b/regression-test/script/array_func_generator.py @@ -0,0 +1,58 @@ +# 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. + +def generate_test_queries(func_name, lambda_name): + data_types = { + 'Double': 'kadbl', + 'Float': 'kafloat', + 'LargeInt': 'kalint', + 'BigInt': 'kabint', + 'SmallInt': 'kasint', + 'Integer': 'kaint', + 'TinyInt': 'katint', + 'DecimalV3': 'kadcml' + } + + table_names = { + 'Double': 'fn_test', + 'Float': 'fn_test', + 'LargeInt': 'fn_test', + 'BigInt': 'fn_test', + 'SmallInt': 'fn_test', + 'Integer': 'fn_test', + 'TinyInt': 'fn_test', + 'DecimalV3': 'fn_test' + } + + queries = [] + for data_type, column_name in data_types.items(): + query = f'order_qt_sql_{func_name}_{data_type} "select {func_name}({lambda_name}, {column_name}) from {table_names[data_type]}"' + query_not_null = f'order_qt_sql_{func_name}_{data_type}_notnull "select {func_name}({lambda_name}, {column_name}) from {table_names[data_type]}_not_nullable"' + queries.append(query) + queries.append(query_not_null) + + return queries + +# 调用函数生成测试查询 +func_name_set = {"array_map", "array_filter", "array_exists", "array_count", "array_last_index", "array_first_index", "array_sortby"} +queries = [] +for func_name in func_name_set: + queries.append(f"// test {func_name}") + queries.extend(generate_test_queries(func_name, "x -> x > 1")) + +for query in queries: + print(query) \ No newline at end of file diff --git a/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy b/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy index f772f30338..a02e324778 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy @@ -842,6 +842,125 @@ suite("nereids_scalar_fn_Array") { order_qt_sql_array_map_TinyInt_notnull "select array_map(x -> x is not null, katint) from fn_test_not_nullable" order_qt_sql_array_map_DecimalV3 "select array_map(x -> x is not null, kadcml) from fn_test" order_qt_sql_array_map_DecimalV3_notnull "select array_map(x -> x is not null, kadcml) from fn_test_not_nullable" + // test array_exists + order_qt_sql_array_exists_Double "select array_exists(x -> x > 1, kadbl) from fn_test" + order_qt_sql_array_exists_Double_notnull "select array_exists(x -> x > 1, kadbl) from fn_test_not_nullable" + order_qt_sql_array_exists_Float "select array_exists(x -> x > 1, kafloat) from fn_test" + order_qt_sql_array_exists_Float_notnull "select array_exists(x -> x > 1, kafloat) from fn_test_not_nullable" + order_qt_sql_array_exists_LargeInt "select array_exists(x -> x > 1, kalint) from fn_test" + order_qt_sql_array_exists_LargeInt_notnull "select array_exists(x -> x > 1, kalint) from fn_test_not_nullable" + order_qt_sql_array_exists_BigInt "select array_exists(x -> x > 1, kabint) from fn_test" + order_qt_sql_array_exists_BigInt_notnull "select array_exists(x -> x > 1, kabint) from fn_test_not_nullable" + order_qt_sql_array_exists_SmallInt "select array_exists(x -> x > 1, kasint) from fn_test" + order_qt_sql_array_exists_SmallInt_notnull "select array_exists(x -> x > 1, kasint) from fn_test_not_nullable" + order_qt_sql_array_exists_Integer "select array_exists(x -> x > 1, kaint) from fn_test" + order_qt_sql_array_exists_Integer_notnull "select array_exists(x -> x > 1, kaint) from fn_test_not_nullable" + order_qt_sql_array_exists_TinyInt "select array_exists(x -> x > 1, katint) from fn_test" + order_qt_sql_array_exists_TinyInt_notnull "select array_exists(x -> x > 1, katint) from fn_test_not_nullable" + order_qt_sql_array_exists_DecimalV3 "select array_exists(x -> x > 1, kadcml) from fn_test" + order_qt_sql_array_exists_DecimalV3_notnull "select array_exists(x -> x > 1, kadcml) from fn_test_not_nullable" + // test array_first_index + order_qt_sql_array_first_index_Double "select array_first_index(x -> x > 1, kadbl) from fn_test" + order_qt_sql_array_first_index_Double_notnull "select array_first_index(x -> x > 1, kadbl) from fn_test_not_nullable" + order_qt_sql_array_first_index_Float "select array_first_index(x -> x > 1, kafloat) from fn_test" + order_qt_sql_array_first_index_Float_notnull "select array_first_index(x -> x > 1, kafloat) from fn_test_not_nullable" + order_qt_sql_array_first_index_LargeInt "select array_first_index(x -> x > 1, kalint) from fn_test" + order_qt_sql_array_first_index_LargeInt_notnull "select array_first_index(x -> x > 1, kalint) from fn_test_not_nullable" + order_qt_sql_array_first_index_BigInt "select array_first_index(x -> x > 1, kabint) from fn_test" + order_qt_sql_array_first_index_BigInt_notnull "select array_first_index(x -> x > 1, kabint) from fn_test_not_nullable" + order_qt_sql_array_first_index_SmallInt "select array_first_index(x -> x > 1, kasint) from fn_test" + order_qt_sql_array_first_index_SmallInt_notnull "select array_first_index(x -> x > 1, kasint) from fn_test_not_nullable" + order_qt_sql_array_first_index_Integer "select array_first_index(x -> x > 1, kaint) from fn_test" + order_qt_sql_array_first_index_Integer_notnull "select array_first_index(x -> x > 1, kaint) from fn_test_not_nullable" + order_qt_sql_array_first_index_TinyInt "select array_first_index(x -> x > 1, katint) from fn_test" + order_qt_sql_array_first_index_TinyInt_notnull "select array_first_index(x -> x > 1, katint) from fn_test_not_nullable" + order_qt_sql_array_first_index_DecimalV3 "select array_first_index(x -> x > 1, kadcml) from fn_test" + order_qt_sql_array_first_index_DecimalV3_notnull "select array_first_index(x -> x > 1, kadcml) from fn_test_not_nullable" + // test array_count + order_qt_sql_array_count_Double "select array_count(x -> x > 1, kadbl) from fn_test" + order_qt_sql_array_count_Double_notnull "select array_count(x -> x > 1, kadbl) from fn_test_not_nullable" + order_qt_sql_array_count_Float "select array_count(x -> x > 1, kafloat) from fn_test" + order_qt_sql_array_count_Float_notnull "select array_count(x -> x > 1, kafloat) from fn_test_not_nullable" + order_qt_sql_array_count_LargeInt "select array_count(x -> x > 1, kalint) from fn_test" + order_qt_sql_array_count_LargeInt_notnull "select array_count(x -> x > 1, kalint) from fn_test_not_nullable" + order_qt_sql_array_count_BigInt "select array_count(x -> x > 1, kabint) from fn_test" + order_qt_sql_array_count_BigInt_notnull "select array_count(x -> x > 1, kabint) from fn_test_not_nullable" + order_qt_sql_array_count_SmallInt "select array_count(x -> x > 1, kasint) from fn_test" + order_qt_sql_array_count_SmallInt_notnull "select array_count(x -> x > 1, kasint) from fn_test_not_nullable" + order_qt_sql_array_count_Integer "select array_count(x -> x > 1, kaint) from fn_test" + order_qt_sql_array_count_Integer_notnull "select array_count(x -> x > 1, kaint) from fn_test_not_nullable" + order_qt_sql_array_count_TinyInt "select array_count(x -> x > 1, katint) from fn_test" + order_qt_sql_array_count_TinyInt_notnull "select array_count(x -> x > 1, katint) from fn_test_not_nullable" + order_qt_sql_array_count_DecimalV3 "select array_count(x -> x > 1, kadcml) from fn_test" + order_qt_sql_array_count_DecimalV3_notnull "select array_count(x -> x > 1, kadcml) from fn_test_not_nullable" + // test array_map + order_qt_sql_array_map_Double "select array_map(x -> x > 1, kadbl) from fn_test" + order_qt_sql_array_map_Double_notnull "select array_map(x -> x > 1, kadbl) from fn_test_not_nullable" + order_qt_sql_array_map_Float "select array_map(x -> x > 1, kafloat) from fn_test" + order_qt_sql_array_map_Float_notnull "select array_map(x -> x > 1, kafloat) from fn_test_not_nullable" + order_qt_sql_array_map_LargeInt "select array_map(x -> x > 1, kalint) from fn_test" + order_qt_sql_array_map_LargeInt_notnull "select array_map(x -> x > 1, kalint) from fn_test_not_nullable" + order_qt_sql_array_map_BigInt "select array_map(x -> x > 1, kabint) from fn_test" + order_qt_sql_array_map_BigInt_notnull "select array_map(x -> x > 1, kabint) from fn_test_not_nullable" + order_qt_sql_array_map_SmallInt "select array_map(x -> x > 1, kasint) from fn_test" + order_qt_sql_array_map_SmallInt_notnull "select array_map(x -> x > 1, kasint) from fn_test_not_nullable" + order_qt_sql_array_map_Integer "select array_map(x -> x > 1, kaint) from fn_test" + order_qt_sql_array_map_Integer_notnull "select array_map(x -> x > 1, kaint) from fn_test_not_nullable" + order_qt_sql_array_map_TinyInt "select array_map(x -> x > 1, katint) from fn_test" + order_qt_sql_array_map_TinyInt_notnull "select array_map(x -> x > 1, katint) from fn_test_not_nullable" + order_qt_sql_array_map_DecimalV3 "select array_map(x -> x > 1, kadcml) from fn_test" + order_qt_sql_array_map_DecimalV3_notnull "select array_map(x -> x > 1, kadcml) from fn_test_not_nullable" + // test array_filter + order_qt_sql_array_filter_Double "select array_filter(x -> x > 1, kadbl) from fn_test" + order_qt_sql_array_filter_Double_notnull "select array_filter(x -> x > 1, kadbl) from fn_test_not_nullable" + order_qt_sql_array_filter_Float "select array_filter(x -> x > 1, kafloat) from fn_test" + order_qt_sql_array_filter_Float_notnull "select array_filter(x -> x > 1, kafloat) from fn_test_not_nullable" + order_qt_sql_array_filter_LargeInt "select array_filter(x -> x > 1, kalint) from fn_test" + order_qt_sql_array_filter_LargeInt_notnull "select array_filter(x -> x > 1, kalint) from fn_test_not_nullable" + order_qt_sql_array_filter_BigInt "select array_filter(x -> x > 1, kabint) from fn_test" + order_qt_sql_array_filter_BigInt_notnull "select array_filter(x -> x > 1, kabint) from fn_test_not_nullable" + order_qt_sql_array_filter_SmallInt "select array_filter(x -> x > 1, kasint) from fn_test" + order_qt_sql_array_filter_SmallInt_notnull "select array_filter(x -> x > 1, kasint) from fn_test_not_nullable" + order_qt_sql_array_filter_Integer "select array_filter(x -> x > 1, kaint) from fn_test" + order_qt_sql_array_filter_Integer_notnull "select array_filter(x -> x > 1, kaint) from fn_test_not_nullable" + order_qt_sql_array_filter_TinyInt "select array_filter(x -> x > 1, katint) from fn_test" + order_qt_sql_array_filter_TinyInt_notnull "select array_filter(x -> x > 1, katint) from fn_test_not_nullable" + order_qt_sql_array_filter_DecimalV3 "select array_filter(x -> x > 1, kadcml) from fn_test" + order_qt_sql_array_filter_DecimalV3_notnull "select array_filter(x -> x > 1, kadcml) from fn_test_not_nullable" + // test array_sortby + order_qt_sql_array_sortby_Double "select array_sortby(x -> x + 1, kadbl) from fn_test" + order_qt_sql_array_sortby_Double_notnull "select array_sortby(x -> x + 1, kadbl) from fn_test_not_nullable" + order_qt_sql_array_sortby_Float "select array_sortby(x -> x + 1, kafloat) from fn_test" + order_qt_sql_array_sortby_Float_notnull "select array_sortby(x -> x + 1, kafloat) from fn_test_not_nullable" + order_qt_sql_array_sortby_LargeInt "select array_sortby(x -> x + 1, kalint) from fn_test" + order_qt_sql_array_sortby_LargeInt_notnull "select array_sortby(x -> x + 1, kalint) from fn_test_not_nullable" + order_qt_sql_array_sortby_BigInt "select array_sortby(x -> x + 1, kabint) from fn_test" + order_qt_sql_array_sortby_BigInt_notnull "select array_sortby(x -> x + 1, kabint) from fn_test_not_nullable" + order_qt_sql_array_sortby_SmallInt "select array_sortby(x -> x + 1, kasint) from fn_test" + order_qt_sql_array_sortby_SmallInt_notnull "select array_sortby(x -> x + 1, kasint) from fn_test_not_nullable" + order_qt_sql_array_sortby_Integer "select array_sortby(x -> x + 1, kaint) from fn_test" + order_qt_sql_array_sortby_Integer_notnull "select array_sortby(x -> x + 1, kaint) from fn_test_not_nullable" + order_qt_sql_array_sortby_TinyInt "select array_sortby(x -> x + 1, katint) from fn_test" + order_qt_sql_array_sortby_TinyInt_notnull "select array_sortby(x -> x + 1, katint) from fn_test_not_nullable" + order_qt_sql_array_sortby_DecimalV3 "select array_sortby(x -> x + 1, kadcml) from fn_test" + order_qt_sql_array_sortby_DecimalV3_notnull "select array_sortby(x -> x + 1, kadcml) from fn_test_not_nullable" + // test array_last_index + order_qt_sql_array_last_index_Double "select array_last_index(x -> x > 1, kadbl) from fn_test" + order_qt_sql_array_last_index_Double_notnull "select array_last_index(x -> x > 1, kadbl) from fn_test_not_nullable" + order_qt_sql_array_last_index_Float "select array_last_index(x -> x > 1, kafloat) from fn_test" + order_qt_sql_array_last_index_Float_notnull "select array_last_index(x -> x > 1, kafloat) from fn_test_not_nullable" + order_qt_sql_array_last_index_LargeInt "select array_last_index(x -> x > 1, kalint) from fn_test" + order_qt_sql_array_last_index_LargeInt_notnull "select array_last_index(x -> x > 1, kalint) from fn_test_not_nullable" + order_qt_sql_array_last_index_BigInt "select array_last_index(x -> x > 1, kabint) from fn_test" + order_qt_sql_array_last_index_BigInt_notnull "select array_last_index(x -> x > 1, kabint) from fn_test_not_nullable" + order_qt_sql_array_last_index_SmallInt "select array_last_index(x -> x > 1, kasint) from fn_test" + order_qt_sql_array_last_index_SmallInt_notnull "select array_last_index(x -> x > 1, kasint) from fn_test_not_nullable" + order_qt_sql_array_last_index_Integer "select array_last_index(x -> x > 1, kaint) from fn_test" + order_qt_sql_array_last_index_Integer_notnull "select array_last_index(x -> x > 1, kaint) from fn_test_not_nullable" + order_qt_sql_array_last_index_TinyInt "select array_last_index(x -> x > 1, katint) from fn_test" + order_qt_sql_array_last_index_TinyInt_notnull "select array_last_index(x -> x > 1, katint) from fn_test_not_nullable" + order_qt_sql_array_last_index_DecimalV3 "select array_last_index(x -> x > 1, kadcml) from fn_test" + order_qt_sql_array_last_index_DecimalV3_notnull "select array_last_index(x -> x > 1, kadcml) from fn_test_not_nullable" test { sql "select tokenize('arg1','xxx = yyy,zzz');"