This is an automated email from the ASF dual-hosted git repository.
zclll 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 ec31a80c7ff [fix](function)width_bucket did not enforce that the
fourth argument must be a constant. (#60643)
ec31a80c7ff is described below
commit ec31a80c7ffc4e2642f81c3f184e55b78eccb1aa
Author: Mryange <[email protected]>
AuthorDate: Sun Feb 22 14:12:10 2026 +0800
[fix](function)width_bucket did not enforce that the fourth argument must
be a constant. (#60643)
The implementation of width_bucket requires the fourth argument to be
constant but did not enforce this; a regular column can be passed in,
however width_bucket will only use the first row.
before
```sql
mysql> SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'),
date('2027-11-18'), v4) AS w FROM width_bucket_test ORDER BY k1;
+------+------------+-----------+--------+------+
| k1 | v1 | v2 | v3 | w |
+------+------------+-----------+--------+------+
| 1 | 2022-11-18 | 290000 | 290000 | 0 |
| 2 | 2023-11-18 | 320000 | 320000 | 1 |
| 3 | 2024-11-18 | 399999.99 | 399999 | 1 |
| 4 | 2025-11-18 | 400000 | 400000 | 1 |
| 5 | 2026-11-18 | 470000 | 470000 | 1 |
| 6 | 2027-11-18 | 510000 | 510000 | 2 |
| 7 | 2028-11-18 | 610000 | 610000 | 2 |
| 8 | NULL | NULL | NULL | NULL |
+------+------------+-----------+--------+------+
```
now
```sql
mysql> SELECT k1, v1, v2, v3, width_bucket(v1, date('2023-11-18'),
date('2027-11-18'), v4) AS w FROM width_bucket_test ORDER BY k1;
ERROR 1105 (HY000): errCode = 2, detailMessage = The fourth argument of
WidthBucket must be a constant.
```
---
be/src/vec/functions/function_width_bucket.cpp | 3 +--
.../trees/expressions/functions/scalar/WidthBucket.java | 13 +++++++++++++
.../width_bucket_fuctions/test_width_bucket_function.groovy | 6 ++++++
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/functions/function_width_bucket.cpp
b/be/src/vec/functions/function_width_bucket.cpp
index 5e2f2858c0f..46790db43c4 100644
--- a/be/src/vec/functions/function_width_bucket.cpp
+++ b/be/src/vec/functions/function_width_bucket.cpp
@@ -68,8 +68,7 @@ public:
block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
ColumnPtr max_value_ptr =
block.get_by_position(arguments[2]).column->convert_to_full_column_if_const();
- ColumnPtr num_buckets_ptr =
-
block.get_by_position(arguments[3]).column->convert_to_full_column_if_const();
+ ColumnPtr num_buckets_ptr = block.get_by_position(arguments[3]).column;
int64_t num_buckets = num_buckets_ptr->get_int(0);
if (num_buckets <= 0) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/WidthBucket.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/WidthBucket.java
index 2404d471d9f..090a850a8b8 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/WidthBucket.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/WidthBucket.java
@@ -18,6 +18,7 @@
package org.apache.doris.nereids.trees.expressions.functions.scalar;
import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
@@ -74,6 +75,18 @@ public class WidthBucket extends ScalarFunction implements
ExplicitlyCastableSig
return new WidthBucket(getFunctionParams(children));
}
+ @Override
+ public void checkLegalityBeforeTypeCoercion() {
+ if (!child(3).isLiteral()) {
+ throw new AnalysisException("The fourth argument of WidthBucket
must be a constant.");
+ }
+ }
+
+ @Override
+ public void checkLegalityAfterRewrite() {
+ checkLegalityBeforeTypeCoercion();
+ }
+
@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
diff --git
a/regression-test/suites/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.groovy
b/regression-test/suites/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.groovy
index 1a455da9244..c96d7b08f50 100644
---
a/regression-test/suites/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.groovy
+++
b/regression-test/suites/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.groovy
@@ -94,4 +94,10 @@ suite("test_width_bucket_function", "arrow_flight_sql") {
sql "select width_bucket(4, 0, 8, 0)"
exception "buckets must be a positive integer value"
}
+
+
+ test {
+ sql "SELECT k1, width_bucket(v2, 200000, 600000, k1) FROM ${tableName2}
ORDER BY k1"
+ exception "The fourth argument of WidthBucket must be a constant"
+ }
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]