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

Mryange 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 a70c212956c  [fix](uniform function) fix constant argument handling 
and use ColumnView                                                              
                                       (#63076)
a70c212956c is described below

commit a70c212956cad9a3614602e935dc1868bac10e92
Author: Mryange <[email protected]>
AuthorDate: Wed May 20 14:51:53 2026 +0800

     [fix](uniform function) fix constant argument handling and use ColumnView  
                                                                                
                   (#63076)
    
    What problem does this PR solve?
    Issue Number: N/A
    Problem Summary:
    
    The uniform function takes three arguments: min, max, and seed. Only the
    first two (min, max) are truly "always constant" — the seed column
    should be treated as a
    regular column, not a constant. Without overriding
    get_arguments_that_are_always_constant(), when a user passes a constant
    value as the third argument (seed), the
    default framework logic treats it as a constant column, leading to
    incorrect results.
    
    Root cause: the base class default
    get_arguments_that_are_always_constant() does not distinguish between
    the seed argument and the min/max arguments, so a constant
    seed would be folded by the constant-handling path rather than being
    treated as a per-row value.
    Fix:
    - Override get_arguments_that_are_always_constant() to return {0, 1},
    explicitly marking only min and max as always-constant arguments.
    - Refactor seed column access to use ColumnView<TYPE_BIGINT> for safer
    and more idiomatic typed column iteration.
---
 be/src/exprs/function/uniform.cpp                          | 14 +++++++++-----
 .../suites/nereids_function_p0/scalar_function/U.groovy    |  2 ++
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/be/src/exprs/function/uniform.cpp 
b/be/src/exprs/function/uniform.cpp
index 86f5bff50aa..713d0f5c3ac 100644
--- a/be/src/exprs/function/uniform.cpp
+++ b/be/src/exprs/function/uniform.cpp
@@ -30,6 +30,7 @@
 #include "core/block/block.h"
 #include "core/block/column_numbers.h"
 #include "core/column/column.h"
+#include "core/column/column_execute_util.h"
 #include "core/column/column_vector.h"
 #include "core/data_type/data_type_number.h" // IWYU pragma: keep
 #include "core/data_type/primitive_type.h"
@@ -73,12 +74,12 @@ struct UniformIntImpl {
                     "uniform's min should be less than max, but got [{}, {})", 
min, max);
         }
 
-        // Get gen column (seed values)
-        const auto& gen_column = block.get_by_position(arguments[2]).column;
+        auto gen_column =
+                
ColumnView<TYPE_BIGINT>::create(block.get_by_position(arguments[2]).column);
 
         for (int i = 0; i < input_rows_count; i++) {
             // Use gen value as seed for each row
-            auto seed = (*gen_column)[i].get<TYPE_BIGINT>();
+            auto seed = gen_column.value_at(i);
             std::mt19937_64 generator(seed);
             std::uniform_int_distribution<int64_t> distribution(min, max);
             res_data[i] = distribution(generator);
@@ -122,11 +123,12 @@ struct UniformDoubleImpl {
         }
 
         // Get gen column (seed values)
-        const auto& gen_column = block.get_by_position(arguments[2]).column;
+        auto gen_column =
+                
ColumnView<TYPE_BIGINT>::create(block.get_by_position(arguments[2]).column);
 
         for (int i = 0; i < input_rows_count; i++) {
             // Use gen value as seed for each row
-            auto seed = (*gen_column)[i].get<TYPE_BIGINT>();
+            auto seed = gen_column.value_at(i);
             std::mt19937_64 generator(seed);
             std::uniform_real_distribution<double> distribution(min, max);
             res_data[i] = distribution(generator);
@@ -157,6 +159,8 @@ public:
         return Impl::get_variadic_argument_types();
     }
 
+    ColumnNumbers get_arguments_that_are_always_constant() const override { 
return {0, 1}; }
+
     Status open(FunctionContext* context, FunctionContext::FunctionStateScope 
scope) override {
         // init_function_context do set_constant_cols for FRAGMENT_LOCAL scope
         if (scope == FunctionContext::FRAGMENT_LOCAL) {
diff --git 
a/regression-test/suites/nereids_function_p0/scalar_function/U.groovy 
b/regression-test/suites/nereids_function_p0/scalar_function/U.groovy
index 68642fa31ec..f43bc4cb6ee 100644
--- a/regression-test/suites/nereids_function_p0/scalar_function/U.groovy
+++ b/regression-test/suites/nereids_function_p0/scalar_function/U.groovy
@@ -62,6 +62,8 @@ suite("nereids_scalar_fn_U") {
 
        def result = sql """select uniform(1, 100, random()*10000) from 
numbers("number" = "10");"""
        assertTrue(result.size() == 10)
+       def doubleResult = sql """select uniform(1.23, 100.100, random()*10000) 
from numbers("number" = "10");"""
+       assertTrue(doubleResult.size() == 10)
        test {
                sql """select uniform(100, 1, random()*10000) from 
numbers("number" = "10");"""
                exception "uniform's min should be less than max"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to