[fix](window_function) window function first_value/last_value should be always nullable (#26014)

This commit is contained in:
Jerry Hu
2023-10-27 20:53:48 +08:00
committed by GitHub
parent 5e884bc065
commit c715facafa
4 changed files with 18 additions and 3 deletions

View File

@ -58,7 +58,8 @@ public class AggregateFunction extends Function {
FunctionSet.ARRAY_AGG, FunctionSet.COLLECT_LIST, FunctionSet.COLLECT_SET);
public static ImmutableSet<String> ALWAYS_NULLABLE_AGGREGATE_FUNCTION_NAME_SET =
ImmutableSet.of("stddev_samp", "variance_samp", "var_samp", "percentile_approx");
ImmutableSet.of("stddev_samp", "variance_samp", "var_samp", "percentile_approx", "first_value",
"last_value");
public static ImmutableSet<String> CUSTOM_AGGREGATE_FUNCTION_NAME_SET =
ImmutableSet.of("group_concat");

View File

@ -19,8 +19,8 @@ package org.apache.doris.nereids.trees.expressions.functions.window;
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.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import org.apache.doris.nereids.types.coercion.AnyDataType;
@ -30,7 +30,7 @@ import java.util.List;
/** parent class for first_value() and last_value() */
public abstract class FirstOrLastValue extends WindowFunction
implements UnaryExpression, PropagateNullable, ExplicitlyCastableSignature {
implements UnaryExpression, AlwaysNullable, ExplicitlyCastableSignature {
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE_WITHOUT_INDEX)

View File

@ -13,3 +13,10 @@
23 04-23-10 ["p7", "year4"] ["p7", "year4"]
24 02-24-10-21 [""] [""]
-- !select_always_nullable --
21 04-21-11 ["amory", "clever"] \N \N
22 04-22-10-21 ["doris", "aws", "greate"] \N \N
22 04-22-10-21 ["is ", "cute", "tea"] 1 999
23 04-23-10 ["p7", "year4"] \N \N
24 02-24-10-21 [""] \N \N

View File

@ -74,4 +74,11 @@ suite("test_first_value_window") {
qt_select_default """ select *,first_value(state) over(partition by myday order by time_col range between current row and unbounded following) from ${tableName1} order by myday, time_col; """
qt_select_always_nullable """
select
*,
first_value(1) over(partition by myday order by time_col rows between 1 preceding and 1 preceding) first_value,
last_value(999) over(partition by myday order by time_col rows between 1 preceding and 1 preceding) last_value
from test_first_value_window_array order by myday, time_col;
"""
}