diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/AggregateFunction.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/AggregateFunction.java index 198946683602a6..d954ab41a95f94 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/AggregateFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/AggregateFunction.java @@ -58,7 +58,8 @@ public class AggregateFunction extends Function { FunctionSet.ARRAY_AGG, FunctionSet.COLLECT_LIST, FunctionSet.COLLECT_SET); public static ImmutableSet 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 CUSTOM_AGGREGATE_FUNCTION_NAME_SET = ImmutableSet.of("group_concat"); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/FirstOrLastValue.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/FirstOrLastValue.java index 0cbccad58de2a0..463fe41aab2194 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/FirstOrLastValue.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/FirstOrLastValue.java @@ -19,8 +19,8 @@ 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 @@ /** 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 SIGNATURES = ImmutableList.of( FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE_WITHOUT_INDEX) diff --git a/regression-test/data/correctness_p0/test_first_value_window.out b/regression-test/data/correctness_p0/test_first_value_window.out index d0cecdaccf8cdc..cabae5b19abab0 100644 --- a/regression-test/data/correctness_p0/test_first_value_window.out +++ b/regression-test/data/correctness_p0/test_first_value_window.out @@ -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 + diff --git a/regression-test/suites/correctness_p0/test_first_value_window.groovy b/regression-test/suites/correctness_p0/test_first_value_window.groovy index 637b9f71616dd2..25246445fbb05d 100644 --- a/regression-test/suites/correctness_p0/test_first_value_window.groovy +++ b/regression-test/suites/correctness_p0/test_first_value_window.groovy @@ -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; + """ }