This is an automated email from the ASF dual-hosted git repository.
HappenLee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new df23f641732 [fix](fe) Correct topn_weighted array return types (#68483)
df23f641732 is described below
commit df23f641732b9814cde44e876448aac22a34db9b
Author: HappenLee <[email protected]>
AuthorDate: Mon Sep 28 09:48:57 2026 +0800
[fix](fe) Correct topn_weighted array return types (#68483)
### What problem does this PR solve?
Issue Number: N/A
For example, `topn_weighted(CAST('2024-01-01 00:00:00' AS
DATETIMEV2(0)), CAST(1 AS BIGINT), 1, 100)[1]` fails at execution with a
return-type mismatch: FE expects a string while BE produces an array of
datetime values.
The four-argument DATETIMEV2 and DECIMALV2 overloads incorrectly declare
VARCHAR return types. Match their array return types to the existing
three-argument overloads, preserving the existing datetime precision
inference and BE implementation. Add signature coverage and SQL
regression tests for both arities, datetime precision, nullable input,
grouping, empty input and array extraction.
### Release note
Fix `topn_weighted` four-argument return-type declarations for datetime
and legacy decimal inputs so they match the array implementation.
### Check List (For Author)
- Test:
- [x] Regression test: `topn_weighted_return_type`; generated output and
normal result comparison both passed on the newly built FE with a local
ASAN BE.
- [x] Unit Test: `TopNWeightedSignatureTest`; all 3 tests passed.
- Behavior changed:
- [x] Yes. Fix previously failing four-argument calls to return arrays.
- Does this need documentation?
- [x] No. The documented return type is already an array.
FE build with integrated Checkstyle and `git diff --check` passed.
Legacy DECIMALV2 is checked in the FE signature tests; SQL regression
also exercises the current DECIMAL input coercion path.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
---
.../expressions/functions/agg/TopNWeighted.java | 4 +-
.../functions/agg/TopNWeightedSignatureTest.java | 65 +++++++++++++++++++
.../topn/topn_weighted_return_type.out | 54 ++++++++++++++++
.../topn/topn_weighted_return_type.groovy | 75 ++++++++++++++++++++++
4 files changed, 196 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeighted.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeighted.java
index 6bd5497c3e2..2ce8a96da11 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeighted.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeighted.java
@@ -90,7 +90,7 @@ public class TopNWeighted extends NullableAggregateFunction
// four arguments
FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE))
.args(DoubleType.INSTANCE, BigIntType.INSTANCE,
IntegerType.INSTANCE, IntegerType.INSTANCE),
- FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
+ FunctionSignature.ret(ArrayType.of(DecimalV2Type.CATALOG_DEFAULT))
.args(DecimalV2Type.CATALOG_DEFAULT,
BigIntType.INSTANCE,
IntegerType.INSTANCE,
@@ -122,7 +122,7 @@ public class TopNWeighted extends NullableAggregateFunction
BigIntType.INSTANCE,
IntegerType.INSTANCE,
IntegerType.INSTANCE),
- FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
+ FunctionSignature.ret(ArrayType.of(DateTimeV2Type.WILDCARD))
.args(DateTimeV2Type.WILDCARD,
BigIntType.INSTANCE,
IntegerType.INSTANCE,
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeightedSignatureTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeightedSignatureTest.java
new file mode 100644
index 00000000000..b1896ec166b
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNWeightedSignatureTest.java
@@ -0,0 +1,65 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.expressions.functions.agg;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.types.ArrayType;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.DateTimeV2Type;
+import org.apache.doris.nereids.types.DecimalV2Type;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class TopNWeightedSignatureTest {
+ @Test
+ void testDateTimePrecision() {
+ for (int scale = 0; scale <= 6; scale++) {
+ assertReturnType(DateTimeV2Type.of(scale));
+ }
+ }
+
+ @Test
+ void testDecimalV2() {
+ assertReturnType(DecimalV2Type.CATALOG_DEFAULT);
+ }
+
+ @Test
+ void testAllOverloadsReturnInputArray() {
+ for (FunctionSignature signature : TopNWeighted.SIGNATURES) {
+ Assertions.assertEquals(ArrayType.of(signature.getArgType(0)),
signature.returnType,
+ signature.toString());
+ }
+ }
+
+ private void assertReturnType(DataType inputType) {
+ Expression value = SlotReference.of("value", inputType);
+ TopNWeighted threeArguments = new TopNWeighted(value, new
BigIntLiteral(1), new IntegerLiteral(1));
+ TopNWeighted fourArguments = new TopNWeighted(value, new
BigIntLiteral(1),
+ new IntegerLiteral(1), new IntegerLiteral(100));
+ for (TopNWeighted function : new TopNWeighted[] {threeArguments,
fourArguments}) {
+ FunctionSignature signature = function.getSignature();
+ Assertions.assertEquals(inputType, signature.getArgType(0));
+ Assertions.assertEquals(ArrayType.of(inputType),
signature.returnType);
+ }
+ }
+}
diff --git
a/regression-test/data/nereids_function_p0/agg_function/topn/topn_weighted_return_type.out
b/regression-test/data/nereids_function_p0/agg_function/topn/topn_weighted_return_type.out
new file mode 100644
index 00000000000..805be28fe31
--- /dev/null
+++
b/regression-test/data/nereids_function_p0/agg_function/topn/topn_weighted_return_type.out
@@ -0,0 +1,54 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !constant_0 --
+["2024-01-01 00:00:00"] ["2024-01-01 00:00:00"] 2024-01-01T00:00
+
+-- !constant_3 --
+["2024-01-01 00:00:00.123"] ["2024-01-01 00:00:00.123"]
2024-01-01T00:00:00.123
+
+-- !constant_6 --
+["2024-01-01 00:00:00.123456"] ["2024-01-01 00:00:00.123456"]
2024-01-01T00:00:00.123456
+
+-- !d0_global --
+["2024-01-02 00:00:00", "2024-01-01 00:00:00"] ["2024-01-02 00:00:00",
"2024-01-01 00:00:00"] 2024-01-02T00:00
+
+-- !d0_grouped --
+1 ["2024-01-02 00:00:00", "2024-01-01 00:00:00"] ["2024-01-02 00:00:00",
"2024-01-01 00:00:00"] 2024-01-02T00:00
+2 ["2024-01-01 00:00:00"] ["2024-01-01 00:00:00"] 2024-01-01T00:00
+3 \N \N \N
+
+-- !d0_empty --
+\N \N
+
+-- !d3_global --
+["2024-01-02 00:00:00.456", "2024-01-01 00:00:00.123"] ["2024-01-02
00:00:00.456", "2024-01-01 00:00:00.123"] 2024-01-02T00:00:00.456
+
+-- !d3_grouped --
+1 ["2024-01-02 00:00:00.456", "2024-01-01 00:00:00.123"] ["2024-01-02
00:00:00.456", "2024-01-01 00:00:00.123"] 2024-01-02T00:00:00.456
+2 ["2024-01-01 00:00:00.123"] ["2024-01-01 00:00:00.123"]
2024-01-01T00:00:00.123
+3 \N \N \N
+
+-- !d3_empty --
+\N \N
+
+-- !d6_global --
+["2024-01-02 00:00:00.456789", "2024-01-01 00:00:00.123456"] ["2024-01-02
00:00:00.456789", "2024-01-01 00:00:00.123456"] 2024-01-02T00:00:00.456789
+
+-- !d6_grouped --
+1 ["2024-01-02 00:00:00.456789", "2024-01-01 00:00:00.123456"]
["2024-01-02 00:00:00.456789", "2024-01-01 00:00:00.123456"]
2024-01-02T00:00:00.456789
+2 ["2024-01-01 00:00:00.123456"] ["2024-01-01 00:00:00.123456"]
2024-01-01T00:00:00.123456
+3 \N \N \N
+
+-- !d6_empty --
+\N \N
+
+-- !amount_global --
+[2.5, 1.25] [2.5, 1.25] 2.5
+
+-- !amount_grouped --
+1 [2.5, 1.25] [2.5, 1.25] 2.5
+2 [1.25] [1.25] 1.25
+3 \N \N \N
+
+-- !amount_empty --
+\N \N
+
diff --git
a/regression-test/suites/nereids_function_p0/agg_function/topn/topn_weighted_return_type.groovy
b/regression-test/suites/nereids_function_p0/agg_function/topn/topn_weighted_return_type.groovy
new file mode 100644
index 00000000000..235138da366
--- /dev/null
+++
b/regression-test/suites/nereids_function_p0/agg_function/topn/topn_weighted_return_type.groovy
@@ -0,0 +1,75 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("topn_weighted_return_type") {
+ sql "DROP TABLE IF EXISTS topn_weighted_return_type"
+ sql """
+ CREATE TABLE topn_weighted_return_type (
+ id INT NOT NULL,
+ g INT NOT NULL,
+ d0 DATETIMEV2(0) NULL,
+ d3 DATETIMEV2(3) NULL,
+ d6 DATETIMEV2(6) NULL,
+ amount DECIMAL(18, 3) NULL,
+ weight BIGINT NOT NULL
+ )
+ DISTRIBUTED BY HASH(id) BUCKETS 3
+ PROPERTIES ("replication_num" = "1")
+ """
+ sql """
+ INSERT INTO topn_weighted_return_type VALUES
+ (1, 1, '2024-01-01 00:00:00', '2024-01-01 00:00:00.123',
+ '2024-01-01 00:00:00.123456', 1.25, 10),
+ (2, 1, '2024-01-02 00:00:00', '2024-01-02 00:00:00.456',
+ '2024-01-02 00:00:00.456789', 2.50, 40),
+ (3, 2, '2024-01-01 00:00:00', '2024-01-01 00:00:00.123',
+ '2024-01-01 00:00:00.123456', 1.25, 20),
+ (4, 2, NULL, NULL, NULL, NULL, 5),
+ (5, 3, NULL, NULL, NULL, NULL, 5)
+ """
+
+ [0, 3, 6].each { scale ->
+ "order_qt_constant_${scale}" """
+ SELECT topn_weighted(CAST('2024-01-01 00:00:00.123456' AS
DATETIMEV2(${scale})),
+ CAST(1 AS BIGINT), 1),
+ topn_weighted(CAST('2024-01-01 00:00:00.123456' AS
DATETIMEV2(${scale})),
+ CAST(1 AS BIGINT), 1, 100),
+ topn_weighted(CAST('2024-01-01 00:00:00.123456' AS
DATETIMEV2(${scale})),
+ CAST(1 AS BIGINT), 1, 100)[1]
+ """
+ }
+
+ ["d0", "d3", "d6", "amount"].each { column ->
+ "order_qt_${column}_global" """
+ SELECT topn_weighted(${column}, weight, 2),
+ topn_weighted(${column}, weight, 2, 100),
+ topn_weighted(${column}, weight, 2, 100)[1]
+ FROM topn_weighted_return_type
+ """
+ "order_qt_${column}_grouped" """
+ SELECT g, topn_weighted(${column}, weight, 2),
+ topn_weighted(${column}, weight, 2, 100),
+ topn_weighted(${column}, weight, 2, 100)[1]
+ FROM topn_weighted_return_type GROUP BY g
+ """
+ "order_qt_${column}_empty" """
+ SELECT topn_weighted(${column}, weight, 2),
+ topn_weighted(${column}, weight, 2, 100)
+ FROM topn_weighted_return_type WHERE id < 0
+ """
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]