[enhancement](aggregate-function) enhance aggregate funtion collect and add group_array aliases (#15339)

Enhance aggregate function `collect_set` and `collect_list` to support optional `max_size` param,
which enables to limit the number of elements in result array.
This commit is contained in:
奕冷
2023-02-27 14:22:30 +08:00
committed by GitHub
parent 0723e55f76
commit c0360f80bb
11 changed files with 1000 additions and 211 deletions

View File

@ -1299,6 +1299,11 @@ public class FunctionCallExpr extends Expr {
fn.setReturnType(new ArrayType(getChild(0).type));
}
if (fnName.getFunction().equalsIgnoreCase("group_uniq_array")
|| fnName.getFunction().equalsIgnoreCase("group_array")) {
fn.setReturnType(new ArrayType(getChild(0).type));
}
if (fnName.getFunction().equalsIgnoreCase("from_unixtime")
|| fnName.getFunction().equalsIgnoreCase("date_format")) {
// if has only one child, it has default time format: yyyy-MM-dd HH:mm:ss.SSSSSS

View File

@ -1345,8 +1345,8 @@ public class FunctionSet<T> {
}
public void addScalarAndVectorizedBuiltin(String fnName, boolean userVisible,
Function.NullableMode nullableMode, Type retType,
boolean varArgs, Type ... args) {
Function.NullableMode nullableMode, Type retType,
boolean varArgs, Type ... args) {
ArrayList<Type> argsType = new ArrayList<Type>();
for (Type type : args) {
argsType.add(type);
@ -1405,6 +1405,10 @@ public class FunctionSet<T> {
public static final String SEQUENCE_COUNT = "sequence_count";
public static final String GROUP_UNIQ_ARRAY = "group_uniq_array";
public static final String GROUP_ARRAY = "group_array";
// Populate all the aggregate builtins in the catalog.
// null symbols indicate the function does not need that step of the evaluation.
// An empty symbol indicates a TODO for the BE to implement the function.
@ -2587,6 +2591,10 @@ public class FunctionSet<T> {
"", "", "", "", "", true, false, true, true));
addBuiltin(AggregateFunction.createBuiltin(COLLECT_SET, Lists.newArrayList(t), new ArrayType(t), t,
"", "", "", "", "", true, false, true, true));
addBuiltin(AggregateFunction.createBuiltin(COLLECT_LIST, Lists.newArrayList(t, Type.INT), new ArrayType(t), t,
"", "", "", "", "", true, false, true, true));
addBuiltin(AggregateFunction.createBuiltin(COLLECT_SET, Lists.newArrayList(t, Type.INT), new ArrayType(t), t,
"", "", "", "", "", true, false, true, true));
addBuiltin(
AggregateFunction.createBuiltin("topn_array", Lists.newArrayList(t, Type.INT), new ArrayType(t), t,
"", "", "", "", "", true, false, true, true));
@ -2611,8 +2619,20 @@ public class FunctionSet<T> {
"", "", "", "", "", true, false, true, true));
addBuiltin(AggregateFunction.createBuiltin(HIST, Lists.newArrayList(t, Type.DOUBLE, Type.INT), Type.VARCHAR, t,
"", "", "", "", "", true, false, true, true));
addBuiltin(AggregateFunction.createBuiltin(HISTOGRAM, Lists.newArrayList(t, Type.DOUBLE, Type.INT), Type.VARCHAR, t,
addBuiltin(AggregateFunction.createBuiltin(HISTOGRAM, Lists.newArrayList(t, Type.DOUBLE, Type.INT),
Type.VARCHAR, t,
"", "", "", "", "", true, false, true, true));
addBuiltin(AggregateFunction.createBuiltin(GROUP_UNIQ_ARRAY, Lists.newArrayList(t), new ArrayType(t), t,
"", "", "", "", "", true, false, true, true));
addBuiltin(
AggregateFunction.createBuiltin(GROUP_UNIQ_ARRAY, Lists.newArrayList(t, Type.INT), new ArrayType(t),
t, "", "", "", "", "", true, false, true, true));
addBuiltin(AggregateFunction.createBuiltin(GROUP_ARRAY, Lists.newArrayList(t), new ArrayType(t), t,
"", "", "", "", "", true, false, true, true));
addBuiltin(
AggregateFunction.createBuiltin(GROUP_ARRAY, Lists.newArrayList(t, Type.INT), new ArrayType(t),
t, "", "", "", "", "", true, false, true, true));
}
// Avg