mrhhsg commented on code in PR #59130:
URL: https://github.com/apache/doris/pull/59130#discussion_r2646943957


##########
be/src/vec/functions/function_map.cpp:
##########
@@ -792,6 +793,74 @@ class FunctionDeduplicateMap : public IFunction {
 private:
 };
 
+class FunctionMapConcat : public IFunction {
+public:
+    static constexpr auto name = "map_concat";
+    static FunctionPtr create() { return 
std::make_shared<FunctionMapConcat>(); }
+    String get_name() const override { return name; }
+    bool is_variadic() const override { return true; }
+    size_t get_number_of_arguments() const override { return 0; }
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        DCHECK(arguments.size() > 0)
+                << "function: " << get_name() << ", arguments should not be 
empty";
+        return arguments[0];
+    }
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        const uint32_t result, size_t input_rows_count) const 
override {
+        auto result_col = block.get_by_position(result).type->create_column();
+        ColumnMap* result_map_column = nullptr;
+        ColumnNullable* result_nullable_column = nullptr;
+        if (result_col->is_nullable()) {
+            result_nullable_column = 
reinterpret_cast<ColumnNullable*>(result_col.get());
+            result_map_column =
+                    
check_and_get_column<ColumnMap>(result_nullable_column->get_nested_column());
+        } else {
+            result_map_column = 
check_and_get_column<ColumnMap>(result_col.get());

Review Comment:
   Better using `assert_cast`



##########
regression-test/suites/function_p0/test_map_concat.groovy:
##########
@@ -0,0 +1,134 @@
+// 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("test_map_concat") {
+    sql """ set enable_nereids_planner=true; """
+    sql """ set enable_fallback_to_original_planner=false; """
+
+    def testTable = "test_map_concat_table"
+
+    sql """
+        drop table if exists ${testTable};
+    """
+
+    sql """
+    CREATE TABLE ${testTable} (
+        id INT,
+        map1 MAP<VARCHAR, VARCHAR>,
+        map2 MAP<VARCHAR, INT>,
+        map3 MAP<INT, VARCHAR>
+    ) ENGINE=OLAP
+    DUPLICATE KEY(id)
+    DISTRIBUTED BY HASH(id) BUCKETS 1
+    PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """
+        insert into ${testTable} values
+        (1, {'a': 'apple', 'b': 'banana'}, {'x': 10, 'y': 20}, {1: 'one', 2: 
'two'}),
+        (2, {'c': 'cherry'}, {'z': 30}, {3: 'three'}),
+        (3, {}, {}, {}),
+        (4, NULL, NULL, NULL);
+    """
+
+    qt_sql """
+        select map_concat() as empty_map;
+    """
+
+    qt_sql """
+        select map_concat(map('single', 'argument')) as single_argument;
+    """
+
+    qt_sql """
+        select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}) as 
literal_maps_merged;
+    """
+
+    qt_sql """
+        select id, map_concat(map1, map2, map3) as all_maps_merged from 
${testTable} order by id;
+    """
+
+    qt_sql """
+        select 
+            map_concat(map1, {}) as merged_with_empty,
+            map_concat(map1, NULL) as map_with_null,
+            map_concat(NULL, NULL) as null_with_null
+        from ${testTable} where id = 1;
+    """
+
+    qt_sql """
+        select map_concat({'a': 'apple', 'b': 'banana'}, {'b': 'blueberry', 
'c': 'cherry'}) as conflict_resolution;
+    """
+
+    qt_sql """
+        select 
+            map_size(map_concat(map1, map2)) as two_maps_size,
+            map_keys(map_concat({'x': 10}, {'y': 20})) as keys_result
+        from ${testTable} where id = 1;
+    """
+
+    qt_sql """
+        select 
+            map_concat({1: 'one', 2: 'two'}, {3: 'three', 4: 'four'}) as 
int_key_maps,
+            map_concat(
+                CAST({'bigint1': 10000000000, 'bigint2': 20000000000} AS 
MAP<VARCHAR, BIGINT>),
+                CAST({'bigint3': 30000000000} AS MAP<VARCHAR, BIGINT>)
+            ) as bigint_values,
+            map_concat(
+                CAST({'double1': 1.2345678901, 'double2': 2.3456789012} AS 
MAP<VARCHAR, DOUBLE>),
+                CAST({'double3': 3.4567890123} AS MAP<VARCHAR, DOUBLE>)
+            ) as double_values,
+            map_concat({'flag1': true}, {'flag2': false}) as boolean_values,
+            map_concat({'arr1': [1, 2, 3]}, {'arr2': [4, 5, 6]}) as 
array_values,
+            map_concat(
+                CAST({'decimal1': 123.456, 'decimal2': 789.012} AS 
MAP<VARCHAR, DECIMAL(10,3)>),
+                CAST({'decimal3': 345.678} AS MAP<VARCHAR, DECIMAL(10,3)>)
+            ) as decimal_values,
+            map_concat({'date1': DATE '2023-01-01', 'date2': DATE 
'2023-12-31'}, 
+                      {'timestamp1': TIMESTAMP '2023-01-01 12:00:00'}) as 
timestamp_values,
+            map_concat(
+                CAST({'int_val': 100} AS MAP<VARCHAR, INT>),
+                CAST({'bigint_val': 200} AS MAP<VARCHAR, BIGINT>)
+            ) as int_bigint_mixed,
+            map_concat(
+                CAST({'decimal_val': 123.456} AS MAP<VARCHAR, DECIMAL(10,3)>),
+                CAST({'double_val': 789.012} AS MAP<VARCHAR, DOUBLE>)
+            ) as decimal_double_mixed,
+            map_concat({'中文键': '中文值', 'key with emoji 🔥': 'value with emoji 
🚀'}, 
+                      {'key with accents café': 'value with accents naïve'}) 
as utf8_charset_test;
+    """
+
+    qt_sql """
+        select 
+            map_concat(
+                map_concat({'a': 1}, {'b': 2}),
+                map_concat({'c': 3}, {'d': 4})
+            ) as nested_concat,
+            map_concat(
+                CAST({'a': 1} AS MAP<VARCHAR, INT>),
+                CAST({'b': '2'} AS MAP<VARCHAR, VARCHAR>)
+            ) as type_mismatch;
+    """
+
+    qt_sql """

Review Comment:
   Add case about `map_concat(map3, map1)`



##########
be/src/vec/functions/function_map.cpp:
##########
@@ -792,6 +793,74 @@ class FunctionDeduplicateMap : public IFunction {
 private:
 };
 
+class FunctionMapConcat : public IFunction {
+public:
+    static constexpr auto name = "map_concat";
+    static FunctionPtr create() { return 
std::make_shared<FunctionMapConcat>(); }
+    String get_name() const override { return name; }
+    bool is_variadic() const override { return true; }
+    size_t get_number_of_arguments() const override { return 0; }
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        DCHECK(arguments.size() > 0)
+                << "function: " << get_name() << ", arguments should not be 
empty";
+        return arguments[0];

Review Comment:
   Is return type consistent with the FE logic?



-- 
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