This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new 3677055f071 branch-4.0: [fix](function)width_bucket did not enforce 
that the fourth argument must be a constant. #60643 (#60794)
3677055f071 is described below

commit 3677055f071b0cac68399826f89af4353c2219fe
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Feb 24 13:28:00 2026 +0800

    branch-4.0: [fix](function)width_bucket did not enforce that the fourth 
argument must be a constant. #60643 (#60794)
    
    Cherry-picked from #60643
    
    Co-authored-by: Mryange <[email protected]>
---
 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]

Reply via email to