[feature](window_function) support to secondary argument to ignore null values in first_value/last_value (#27623)
This commit is contained in:
@ -1426,6 +1426,22 @@ public class FunctionSet<T> {
|
||||
null,
|
||||
"",
|
||||
"", true));
|
||||
|
||||
addBuiltin(AggregateFunction.createAnalyticBuiltin("first_value",
|
||||
Lists.newArrayList(new ArrayType(t), Type.BOOLEAN), new ArrayType(t), Type.ARRAY,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
"",
|
||||
"", true));
|
||||
|
||||
addBuiltin(AggregateFunction.createAnalyticBuiltin("last_value",
|
||||
Lists.newArrayList(new ArrayType(t), Type.BOOLEAN), new ArrayType(t), Type.ARRAY,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
"",
|
||||
"", true));
|
||||
}
|
||||
|
||||
// Avg
|
||||
@ -1584,7 +1600,7 @@ public class FunctionSet<T> {
|
||||
|
||||
//vec first_value
|
||||
addBuiltin(AggregateFunction.createAnalyticBuiltin(
|
||||
"first_value", Lists.newArrayList(t), t, t,
|
||||
"first_value", Lists.newArrayList(t, Type.BOOLEAN), t, t,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
@ -1601,7 +1617,7 @@ public class FunctionSet<T> {
|
||||
false, false));
|
||||
//vec last_value
|
||||
addBuiltin(AggregateFunction.createAnalyticBuiltin(
|
||||
"last_value", Lists.newArrayList(t), t, t,
|
||||
"last_value", Lists.newArrayList(t, Type.BOOLEAN), t, t,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
|
||||
@ -320,7 +320,7 @@ public class WindowFunctionChecker extends DefaultExpressionVisitor<Expression,
|
||||
&& wf.getLeftBoundary().isNot(FrameBoundType.PRECEDING)) {
|
||||
windowExpression = windowExpression.withWindowFrame(
|
||||
wf.withFrameUnits(FrameUnitsType.ROWS).withRightBoundary(wf.getLeftBoundary()));
|
||||
LastValue lastValue = new LastValue(firstValue.child());
|
||||
LastValue lastValue = new LastValue(firstValue.children());
|
||||
windowExpression = windowExpression.withFunction(lastValue);
|
||||
return lastValue;
|
||||
}
|
||||
|
||||
@ -21,30 +21,41 @@ import org.apache.doris.catalog.FunctionSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
|
||||
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
|
||||
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;
|
||||
|
||||
/** parent class for first_value() and last_value() */
|
||||
/**
|
||||
* parent class for first_value() and last_value()
|
||||
*/
|
||||
public abstract class FirstOrLastValue extends WindowFunction
|
||||
implements UnaryExpression, AlwaysNullable, ExplicitlyCastableSignature {
|
||||
implements AlwaysNullable, ExplicitlyCastableSignature {
|
||||
|
||||
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
|
||||
FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE_WITHOUT_INDEX)
|
||||
FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE_WITHOUT_INDEX),
|
||||
FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE_WITHOUT_INDEX, BooleanType.INSTANCE)
|
||||
);
|
||||
|
||||
public FirstOrLastValue(String name, Expression child, Expression ignoreNullValue) {
|
||||
super(name, child, ignoreNullValue);
|
||||
}
|
||||
|
||||
public FirstOrLastValue(String name, Expression child) {
|
||||
super(name, child);
|
||||
}
|
||||
|
||||
public FirstOrLastValue(String name, List<Expression> children) {
|
||||
super(name, children);
|
||||
}
|
||||
|
||||
public FirstOrLastValue reverse() {
|
||||
if (this instanceof FirstValue) {
|
||||
return new LastValue(child());
|
||||
return new LastValue(children);
|
||||
} else {
|
||||
return new FirstValue(child());
|
||||
return new FirstValue(children);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -34,10 +34,18 @@ public class FirstValue extends FirstOrLastValue {
|
||||
super("first_value", child);
|
||||
}
|
||||
|
||||
public FirstValue(Expression child, Expression ignoreNullValue) {
|
||||
super("first_value", child, ignoreNullValue);
|
||||
}
|
||||
|
||||
public FirstValue(List<Expression> children) {
|
||||
super("first_value", children);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FirstValue withChildren(List<Expression> children) {
|
||||
Preconditions.checkArgument(children.size() == 1);
|
||||
return new FirstValue(children.get(0));
|
||||
Preconditions.checkArgument(children.size() == 1 || children.size() == 2);
|
||||
return new FirstValue(children);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,6 +55,6 @@ public class FirstValue extends FirstOrLastValue {
|
||||
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
return child().getDataType();
|
||||
return child(0).getDataType();
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,10 +34,18 @@ public class LastValue extends FirstOrLastValue {
|
||||
super("last_value", child);
|
||||
}
|
||||
|
||||
public LastValue(Expression child, Expression ignoreNullValue) {
|
||||
super("last_value", child, ignoreNullValue);
|
||||
}
|
||||
|
||||
public LastValue(List<Expression> children) {
|
||||
super("last_value", children);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LastValue withChildren(List<Expression> children) {
|
||||
Preconditions.checkArgument(children.size() == 1);
|
||||
return new LastValue(children.get(0));
|
||||
Preconditions.checkArgument(children.size() == 1 || children.size() == 2);
|
||||
return new LastValue(children);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user