Skip to content

Commit

Permalink
[fix](window_function) window function first_value/last_value should …
Browse files Browse the repository at this point in the history
…be always nullable
  • Loading branch information
mrhhsg committed Oct 27, 2023
1 parent bac5239 commit e690b4f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE_WITHOUT_INDEX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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;
"""
}

0 comments on commit e690b4f

Please sign in to comment.