This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 87edfb5c09f [fix](window_function) window function
first_value/last_value should be always nullable (#26014) (#26260)
87edfb5c09f is described below
commit 87edfb5c09f716fe0784401773a0022136d52d28
Author: Jerry Hu <[email protected]>
AuthorDate: Thu Nov 2 14:13:09 2023 +0800
[fix](window_function) window function first_value/last_value should be
always nullable (#26014) (#26260)
---
.../apache/doris/catalog/AggregateFunction.java | 3 +-
.../functions/window/FirstOrLastValue.java | 4 +--
.../correctness_p0/test_first_value_window.out | 7 +++++
.../correctness_p0/test_first_value_window.groovy | 34 ++++++++++++++++++++++
4 files changed, 45 insertions(+), 3 deletions(-)
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 bfaa07aa326..594516fe59f 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.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");
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 44bcf40ec36..12fba8478ce 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 @@ 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.IdenticalSignature;
-import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import com.google.common.collect.ImmutableList;
@@ -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, IdenticalSignature,
RequireTrivialTypes {
+ implements UnaryExpression, AlwaysNullable, IdenticalSignature,
RequireTrivialTypes {
static {
List<FunctionSignature> signatures = Lists.newArrayList();
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 5a2ad3022b8..2913dbd01d2 100644
--- a/regression-test/data/correctness_p0/test_first_value_window.out
+++ b/regression-test/data/correctness_p0/test_first_value_window.out
@@ -6,3 +6,10 @@
23 04-23-10 1 1
24 02-24-10-21 1 1
+-- !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 dd56e9ac2db..374290e7a34 100644
--- a/regression-test/suites/correctness_p0/test_first_value_window.groovy
+++ b/regression-test/suites/correctness_p0/test_first_value_window.groovy
@@ -45,4 +45,38 @@ 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
${tableName} order by myday, time_col, state; """
+
+ def tableName1 = "test_first_value_window_array"
+
+ sql """ DROP TABLE IF EXISTS ${tableName1} """
+ sql """
+ CREATE TABLE IF NOT EXISTS ${tableName1} (
+ `myday` INT,
+ `time_col` VARCHAR(40) NOT NULL,
+ `state` ARRAY<STRING>
+ ) ENGINE=OLAP
+ DUPLICATE KEY(`myday`,time_col)
+ COMMENT "OLAP"
+ DISTRIBUTED BY HASH(`myday`) BUCKETS 2
+ PROPERTIES (
+ "replication_num" = "1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ );
+ """
+
+ sql """ INSERT INTO ${tableName1} VALUES
+ (21,"04-21-11",["amory", "clever"]),
+ (22,"04-22-10-21",["is ", "cute", "tea"]),
+ (22,"04-22-10-21",["doris", "aws", "greate"]),
+ (23,"04-23-10", ["p7", "year4"]),
+ (24,"02-24-10-21",[""]); """
+
+ 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;
+ """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]