[feature](Nereids) add many array functions (#24301)

Add function array_filter, array_sortby, array_last_index, array_first_index, array_orderby, array_count
This commit is contained in:
谢健
2023-09-19 18:58:49 +08:00
committed by GitHub
parent c9f5142420
commit c3bd2a22d4
13 changed files with 2333 additions and 0 deletions

View File

@ -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"),

View File

@ -472,6 +472,10 @@ public class ExpressionTranslator extends DefaultExpressionVisitor<Expr, PlanTra
"", TFunctionBinaryType.BUILTIN, true, true, nullableMode);
// create catalog FunctionCallExpr without analyze again
if (LambdaFunctionCallExpr.LAMBDA_FUNCTION_SET.contains(function.getName())
|| LambdaFunctionCallExpr.LAMBDA_MAPPED_FUNCTION_SET.contains(function.getName())) {
return new LambdaFunctionCallExpr(catalogFunction, new FunctionParams(false, arguments));
}
return new FunctionCallExpr(catalogFunction, new FunctionParams(false, arguments));
}

View File

@ -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_count'.
*/
public class ArrayCount extends ScalarFunction
implements HighOrderFunction, AlwaysNotNullable {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE))
);
private ArrayCount(List<Expression> 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<Expression> children) {
return new ArrayCount(children);
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitArrayCount(this, context);
}
@Override
public List<FunctionSignature> getImplSignature() {
return SIGNATURES;
}
}

View File

@ -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<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(ArrayType.of(BooleanType.INSTANCE))
);
private ArrayExists(List<Expression> 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<Expression> children) {
return new ArrayExists(children);
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitArrayExists(this, context);
}
@Override
public List<FunctionSignature> getImplSignature() {
return SIGNATURES;
}
}

View File

@ -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<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX),
ArrayType.of(BooleanType.INSTANCE))
);
private ArrayFilter(List<Expression> 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<Expression> children) {
return new ArrayFilter(children);
}
@Override
public List<FunctionSignature> getImplSignature() {
return SIGNATURES;
}
}

View File

@ -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<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE))
);
private ArrayFirstIndex(List<Expression> 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<Expression> children) {
return new ArrayFirstIndex(children);
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitArrayFirstIndex(this, context);
}
@Override
public List<FunctionSignature> getImplSignature() {
return SIGNATURES;
}
}

View File

@ -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<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE))
);
private ArrayLastIndex(List<Expression> 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<Expression> children) {
return new ArrayLastIndex(children);
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitArrayLastIndex(this, context);
}
@Override
public List<FunctionSignature> getImplSignature() {
return SIGNATURES;
}
}

View File

@ -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<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX),
ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX))
);
private ArraySortBy(List<Expression> 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<Expression> children) {
return new ArraySortBy(children);
}
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitArraySortBy(this, context);
}
@Override
public List<FunctionSignature> getImplSignature() {
return SIGNATURES;
}
}

View File

@ -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<FunctionSignature> getSignatures() {
return new ImmutableList.Builder<FunctionSignature>()
.addAll(getImplSignature())
.add(FunctionSignature.ret(AnyDataType.INSTANCE_WITHOUT_INDEX).args(LambdaType.INSTANCE))
.build();
}
List<FunctionSignature> getImplSignature();
}

View File

@ -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<R, C> {
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<R, C> {
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<R, C> {
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<R, C> {
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);
}

View File

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

View File

@ -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');"