github-actions[bot] commented on code in PR #62743:
URL: https://github.com/apache/doris/pull/62743#discussion_r3130021828


##########
be/test/exprs/function/varray_match_function_test.cpp:
##########
@@ -0,0 +1,211 @@
+// 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.
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <string>
+
+#include "core/block/block.h"
+#include "core/column/column_array.h"
+#include "core/column/column_const.h"
+#include "core/column/column_nullable.h"
+#include "core/column/column_vector.h"
+#include "core/data_type/data_type_array.h"
+#include "core/data_type/data_type_nullable.h"
+#include "core/data_type/data_type_number.h"
+#include "exprs/function/function_test_util.h"
+#include "exprs/function/simple_function_factory.h"
+
+namespace doris {
+
+// -----------------------------------------------------------------------
+// Helper: build a ColumnArray<Nullable<Boolean>> from a flat bool list.
+// offsets[i] is the end of row i's elements.
+// -----------------------------------------------------------------------
+static ColumnPtr make_bool_array_column(const 
std::vector<std::vector<uint8_t>>& rows) {
+    // nested: Nullable<UInt8>
+    auto nested_data = ColumnUInt8::create();
+    auto nested_null = ColumnUInt8::create();
+    ColumnArray::Offsets64 offsets;
+    uint64_t total = 0;
+    for (const auto& row : rows) {
+        for (uint8_t v : row) {
+            nested_data->insert_value(v);
+            nested_null->insert_value(0);
+        }
+        total += row.size();
+        offsets.push_back(total);
+    }
+    auto nullable_nested =
+            ColumnNullable::create(std::move(nested_data), 
std::move(nested_null));
+    auto offsets_col = ColumnArray::ColumnOffsets::create();
+    offsets_col->get_data() = std::move(offsets);
+    return ColumnArray::create(std::move(nullable_nested), 
std::move(offsets_col));
+}
+
+// Return type: Nullable<UInt8>
+static DataTypePtr make_return_type() {
+    return make_nullable(std::make_shared<DataTypeUInt8>());
+}
+
+// Build a FunctionBasePtr for array_match_all / array_match_any.
+static FunctionBasePtr get_fn(const std::string& func_name, const DataTypePtr& 
input_type) {
+    ColumnsWithTypeAndName args = {{nullptr, input_type, "arg0"}};
+    return SimpleFunctionFactory::instance().get_function(func_name, args, 
make_return_type());
+}
+
+// Execute func with a single column block and return the result column.
+static ColumnPtr execute_fn(const std::string& func_name, const DataTypePtr& 
input_type,
+                             ColumnPtr col, size_t rows) {
+    Block block;
+    block.insert({col, input_type, "arg0"});
+    block.insert({nullptr, make_return_type(), "result"});
+
+    auto func = get_fn(func_name, input_type);
+    EXPECT_NE(func, nullptr);
+
+    FunctionUtils fn_utils(make_return_type(), {input_type}, false);
+    auto* ctx = fn_utils.get_fn_ctx();
+    ctx->set_constant_cols({nullptr});
+    EXPECT_EQ(func->open(ctx, FunctionContext::FRAGMENT_LOCAL), Status::OK());
+    EXPECT_EQ(func->open(ctx, FunctionContext::THREAD_LOCAL), Status::OK());
+
+    ColumnNumbers args_idx = {0};
+    EXPECT_EQ(func->execute(ctx, block, args_idx, 1, rows), Status::OK());
+
+    EXPECT_EQ(func->close(ctx, FunctionContext::THREAD_LOCAL), Status::OK());
+    EXPECT_EQ(func->close(ctx, FunctionContext::FRAGMENT_LOCAL), Status::OK());
+    return block.get_by_position(1).column;
+}
+
+// -----------------------------------------------------------------------
+// 1. Basic correctness: non-const input
+// -----------------------------------------------------------------------
+TEST(ArrayMatchFunctionTest, basic_correctness_check_function) {
+    // array_match_all(Array<Nullable<Boolean>>)
+    {
+        std::string func_name = "array_match_all";
+        InputTypeSet input_types = {PrimitiveType::TYPE_ARRAY, 
PrimitiveType::TYPE_NULL,
+                                    PrimitiveType::TYPE_BOOLEAN};
+        TestArray all_true = {UInt8(1), UInt8(1)};
+        TestArray has_false = {UInt8(1), UInt8(0)};
+        TestArray with_null = {UInt8(1), Null()};
+        TestArray all_null = {Null(), Null()};
+        TestArray empty_arr;
+        DataSet data_set = {
+                {{AnyType(all_true)}, UInt8(1)},      // all true  -> true
+                {{AnyType(has_false)}, UInt8(0)},     // has false -> false
+                {{AnyType(with_null)}, Null()},        // has null, rest true 
-> null
+                {{AnyType(all_null)}, Null()},         // all null -> null
+                {{AnyType(empty_arr)}, UInt8(1)},     // empty -> true 
(vacuous)
+        };
+        static_cast<void>(
+                check_function<DataTypeUInt8, true>(func_name, input_types, 
data_set));
+    }
+
+    // array_match_any(Array<Nullable<Boolean>>)
+    {
+        std::string func_name = "array_match_any";
+        InputTypeSet input_types = {PrimitiveType::TYPE_ARRAY, 
PrimitiveType::TYPE_NULL,
+                                    PrimitiveType::TYPE_BOOLEAN};
+        TestArray all_false = {UInt8(0), UInt8(0)};
+        TestArray has_true = {UInt8(0), UInt8(1)};
+        TestArray with_null = {UInt8(0), Null()};
+        TestArray empty_arr;
+        DataSet data_set = {
+                {{AnyType(all_false)}, UInt8(0)},  // all false -> false
+                {{AnyType(has_true)}, UInt8(1)},   // has true  -> true
+                {{AnyType(with_null)}, Null()},     // has null, rest false -> 
null
+                {{AnyType(empty_arr)}, UInt8(0)},  // empty -> false (vacuous)
+        };
+        static_cast<void>(
+                check_function<DataTypeUInt8, true>(func_name, input_types, 
data_set));
+    }
+}
+
+// -----------------------------------------------------------------------
+// 2. Const-column input: the execution framework wraps the result in
+//    ColumnConst because use_default_implementation_for_constants()=true.
+//    Verify results are correct and result is ColumnConst.
+// -----------------------------------------------------------------------
+TEST(ArrayMatchFunctionTest, const_column_input_result_is_column_const) {
+    // Input type: Nullable<Array<Nullable<Boolean>>>
+    auto inner_bool_type = make_nullable(std::make_shared<DataTypeUInt8>());
+    auto array_type = 
make_nullable(std::make_shared<DataTypeArray>(inner_bool_type));
+
+    const size_t N = 5; // number of rows in the block
+
+    for (const std::string& func_name : {"array_match_all", 
"array_match_any"}) {
+        // Build a 1-element ColumnArray: [[true, true]]
+        auto inner_col = make_bool_array_column({{1, 1}});
+        // Wrap it in Nullable (not null at the outer level)
+        auto null_map = ColumnUInt8::create(1, 0);
+        auto nullable_col = ColumnNullable::create(inner_col, 
std::move(null_map));
+
+        // Create ColumnConst: same array repeated N times
+        auto const_col = ColumnConst::create(std::move(nullable_col), N);
+
+        auto result = execute_fn(func_name, array_type, std::move(const_col), 
N);
+        ASSERT_TRUE(result.get() != nullptr) << func_name;
+
+        // The result MUST be ColumnConst when all inputs are const
+        // (guaranteed by use_default_implementation_for_constants()=true)
+        EXPECT_TRUE(is_column_const(*result))
+                << func_name
+                << ": result should be ColumnConst when input is all-const, 
but got size="
+                << result->size();
+
+        // And must have size N
+        EXPECT_EQ(result->size(), N) << func_name;
+    }
+}
+
+// -----------------------------------------------------------------------
+// 3. BUG REPRODUCTION:
+//    is_use_default_implementation_for_constants() currently returns false.
+//    This causes VectorizedFnCall::is_constant() to return false even when
+//    all children are const, so the expression cannot be const-folded at the
+//    VExpr planning level.
+//
+//    The correct value should be true (delegate to
+//    use_default_implementation_for_constants() which is true by default).
+//
+//    This test FAILS with the current code and will PASS after the fix
+//    (removing the is_use_default_implementation_for_constants()=false 
override).
+// -----------------------------------------------------------------------
+TEST(ArrayMatchFunctionTest, 
is_use_default_implementation_for_constants_should_be_true) {
+    auto inner_bool_type = make_nullable(std::make_shared<DataTypeUInt8>());
+    auto array_type = 
make_nullable(std::make_shared<DataTypeArray>(inner_bool_type));
+    ColumnsWithTypeAndName args = {{nullptr, array_type, "arg0"}};
+
+    for (const std::string& func_name : {"array_match_all", 
"array_match_any"}) {
+        auto func = SimpleFunctionFactory::instance().get_function(func_name, 
args,
+                                                                   
make_return_type());
+        ASSERT_NE(func, nullptr) << func_name;
+
+        // This assertion currently FAILS because the function overrides
+        // is_use_default_implementation_for_constants() to return false,
+        // breaking VExpr-level const-folding for all-const inputs.
+        EXPECT_TRUE(func->is_use_default_implementation_for_constants())

Review Comment:
   This PR does not change `array_match_*`, but `be/test/CMakeLists.txt` picks 
up every `*.cpp` under `be/test/`, so this file becomes part of normal BE UT. 
The assertion here is currently false in checked-in code: 
`ArrayMatchFunction::is_use_default_implementation_for_constants()` explicitly 
returns `false` in `be/src/exprs/function/array/varray_match_function.cpp:50`, 
and `DefaultFunction` forwards that value unchanged. As written, the PR adds a 
deterministic BE unit-test failure unrelated to the `collect_*` change. If the 
array-match fix is intentional, the implementation change needs to be included 
here. Otherwise this test file should be dropped.



##########
be/src/exprs/aggregate/aggregate_function_collect_impl_v2.h:
##########
@@ -0,0 +1,82 @@
+// 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.
+
+#pragma once
+
+#include "common/exception.h"
+#include "common/status.h"
+#include "core/call_on_type_index.h"
+#include "exprs/aggregate/aggregate_function_collect.h"
+#include "exprs/aggregate/factory_helpers.h"
+#include "exprs/aggregate/helpers.h"
+
+namespace doris {
+
+// For collect_list_v2: complex types use V2 binary serialization; 
simple/string types
+// use the same data structs as v1 (their serialization is already efficient 
binary).
+template <PrimitiveType T, bool HasLimit>
+AggregateFunctionPtr do_create_agg_function_collect_v2(bool distinct,
+                                                       const DataTypes& 
argument_types,
+                                                       const bool 
result_is_nullable,
+                                                       const 
AggregateFunctionAttr& attr) {
+    if (distinct) {
+        if constexpr (T == INVALID_TYPE) {
+            throw Exception(ErrorCode::INTERNAL_ERROR,

Review Comment:
   `collect_set` now binds to `collect_set_v2` in FE for the same `AnyDataType` 
signature as before, but this `INVALID_TYPE` branch still throws on every 
complex input. A query like `SELECT collect_set(km) FROM 
test_array_agg_complex` where `km` is MAP, ARRAY, or STRUCT will reach this 
path and fail with `unexpected type for collect_set_v2`, so the `collect_set` 
half of the advertised complex-type binary-serde feature is still missing. 
Either keep routing complex inputs to `collect_set_v1` or add a V2 distinct 
implementation and coverage for the `INVALID_TYPE` path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to