[vectorized](function) support array_count function (#18557)

support array_count function.
array_count:Returns the number of non-zero and non-null elements in the given array.
This commit is contained in:
Ziyu Wang
2023-05-16 17:00:01 +08:00
committed by GitHub
parent e22f5891d2
commit 325a1d4b28
10 changed files with 500 additions and 3 deletions

View File

@ -35,13 +35,13 @@ import java.util.List;
public class LambdaFunctionCallExpr extends FunctionCallExpr {
public static final ImmutableSet<String> LAMBDA_FUNCTION_SET = new ImmutableSortedSet.Builder(
String.CASE_INSENSITIVE_ORDER).add("array_map").add("array_filter").add("array_exists").add("array_sortby")
.add("array_first_index").add("array_last").build();
.add("array_first_index").add("array_last").add("array_count").build();
// The functions in this set are all normal array functions when implemented initially.
// and then wants add lambda expr as the input param, so we rewrite it to contains an array_map lambda function
// rather than reimplementing a lambda function, this will be reused the implementation of normal array function
public static final ImmutableSet<String> LAMBDA_MAPPED_FUNCTION_SET = new ImmutableSortedSet.Builder(
String.CASE_INSENSITIVE_ORDER).add("array_exists").add("array_sortby")
.add("array_first_index").add("array_last")
.add("array_first_index").add("array_last").add("array_count")
.build();
private static final Logger LOG = LogManager.getLogger(LambdaFunctionCallExpr.class);
@ -108,7 +108,8 @@ public class LambdaFunctionCallExpr extends FunctionCallExpr {
}
fn.setReturnType(ArrayType.create(lambda.getChild(0).getType(), true));
} else if (fnName.getFunction().equalsIgnoreCase("array_exists")
|| fnName.getFunction().equalsIgnoreCase("array_first_index")) {
|| fnName.getFunction().equalsIgnoreCase("array_first_index")
|| fnName.getFunction().equalsIgnoreCase("array_count")) {
if (fnParams.exprs() == null || fnParams.exprs().size() < 1) {
throw new AnalysisException("The " + fnName.getFunction() + " function must have at least one param");
}