This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 718ab8a0d80 branch-3.0: [fix](map) fix createMap function #52231
(#52400)
718ab8a0d80 is described below
commit 718ab8a0d8034216828d8d783d5fbeb407164af3
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sat Jun 28 17:28:01 2025 +0800
branch-3.0: [fix](map) fix createMap function #52231 (#52400)
Cherry-picked from #52231
Co-authored-by: amory <[email protected]>
---
.../expressions/functions/scalar/CreateMap.java | 20 ++++++++++++++-
.../nereids_function_p0/scalar_function/Map.out | Bin 25901 -> 28172 bytes
.../nereids_function_p0/scalar_function/Map.groovy | 27 +++++++++++++++++++++
3 files changed, 46 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CreateMap.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CreateMap.java
index fe966f4e38d..da18ad6480f 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CreateMap.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CreateMap.java
@@ -24,11 +24,13 @@ import
org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.ArrayType;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.MapType;
import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -51,7 +53,23 @@ public class CreateMap extends ScalarFunction
@Override
public DataType getDataType() {
if (arity() >= 2) {
- return MapType.of(child(0).getDataType(), child(1).getDataType());
+ // use Array function to get the common key and value type
+ // first collect all key types in odd position, and value types in
even position
+ // then get the common type of key and value
+ List<Expression> keyExpressions = new ArrayList<>();
+ List<Expression> valueExpressions = new ArrayList<>();
+ for (int i = 0; i < children.size(); i++) {
+ if (i % 2 == 0) {
+ keyExpressions.add(children.get(i));
+ } else {
+ valueExpressions.add(children.get(i));
+ }
+ }
+ Array keyArr = new Array().withChildren(keyExpressions);
+ DataType keyType = ((ArrayType)
keyArr.getDataType()).getItemType();
+ Array valueArr = new Array().withChildren(valueExpressions);
+ DataType valueType = ((ArrayType)
valueArr.getDataType()).getItemType();
+ return MapType.of(keyType, valueType);
}
return MapType.SYSTEM_DEFAULT;
}
diff --git a/regression-test/data/nereids_function_p0/scalar_function/Map.out
b/regression-test/data/nereids_function_p0/scalar_function/Map.out
index a272d3cf2c3..1da11a27f96 100644
Binary files a/regression-test/data/nereids_function_p0/scalar_function/Map.out
and b/regression-test/data/nereids_function_p0/scalar_function/Map.out differ
diff --git
a/regression-test/suites/nereids_function_p0/scalar_function/Map.groovy
b/regression-test/suites/nereids_function_p0/scalar_function/Map.groovy
index f8b28c8da9a..301841e8a44 100644
--- a/regression-test/suites/nereids_function_p0/scalar_function/Map.groovy
+++ b/regression-test/suites/nereids_function_p0/scalar_function/Map.groovy
@@ -286,5 +286,32 @@ suite("nereids_scalar_fn_map") {
order_qt_map_contains_value_tint_date_notnull """ select
map_contains_value(km_tint_date, kdt) from fn_test_not_nullable """
order_qt_map_contains_value_tint_dtm_notnull """ select
map_contains_value(km_tint_dtm, kdtm) from fn_test_not_nullable """
+ // map constructor function tests - bugfix for CreateMap with args not
deducible
+ sql """ set enable_fold_constant_by_be=true;"""
+ sql """ set debug_skip_fold_constant=false;"""
+ qt_map_constructor_basic "select map('name', 'John', 'age', 30, 'city',
'NY', 'zip', 10001)"
+ qt_map_constructor_string_values "select map('key1', 'value1', 'key2',
'value2', 'key3', 'value3')"
+ qt_map_constructor_mixed_types "select map('string_key', 'string_value',
'int_key', 12345, 'float_key', 3.14159)"
+ qt_map_constructor_large_numbers "select map('small', 100, 'medium',
10000, 'large', 100000, 'very_large', 1000000)"
+ qt_map_constructor_json_strings "select map('{\"name\":\"John\"}',
'{\"age\":30}', '{\"city\":\"NY\"}', '{\"zip\":10001}')"
+ qt_map_constructor_nested_json "select
map('{\"user\":{\"name\":\"John\",\"age\":30}}',
'{\"address\":{\"city\":\"NY\",\"zip\":10001}}')"
+ qt_map_constructor_special_chars "select map('key with spaces', 'value
with spaces', 'key-with-dashes', 'value-with-dashes')"
+ qt_map_constructor_unicode "select map('中文键', '中文值', 'key_中文', 'value_中文')"
+ qt_map_constructor_empty_strings "select map('empty_key', '', 'key_empty',
'value', 'empty_both', '')"
+ qt_map_constructor_null_values "select map('null_key', null, 'key_null',
'value', 'both_null', null)"
+ qt_map_constructor_boolean_values "select map('true_key', true,
'false_key', false, 'mixed_key', 123)"
+ qt_map_constructor_decimal_values "select map('decimal_key', 123.456,
'integer_key', 789, 'mixed_decimal', 10001.0)"
+ qt_map_constructor_date_values "select map('date_key', '2023-01-01',
'datetime_key', '2023-01-01 12:00:00', 'string_key', 'text')"
+ qt_map_constructor_array_values "select map('array_key', '[1,2,3]',
'string_key', 'text', 'number_key', 10001)"
+ qt_map_constructor_object_values "select map('object_key',
'{\"nested\":\"value\"}', 'simple_key', 'simple_value')"
+ qt_map_constructor_long_strings "select map('long_key', 'this is a very
long string value that should not be truncated', 'short_key', 'short')"
+ qt_map_constructor_numeric_strings "select map('numeric_string', '10001',
'actual_number', 10001, 'mixed', 'text')"
+ qt_map_constructor_escape_chars "select map('quoted_key', 'value with
\"quotes\"', 'backslash_key', 'value with \\ backslash')"
+ qt_map_constructor_whitespace "select map(' spaced_key ', '
spaced_value ', 'normal_key', 'normal_value')"
+
+ qt_sql "select map('{\"name\":\"John\"}', '{\"age\":30}',
'{\"city\":\"NY\"}', '{\"zip\":10001}')"
+ qt_sql "select map('zip', 10001, 'code', 10002, 'number', 10003)"
+ qt_sql "select map('postal_code', 10001, 'area_code', 10002, 'zip_plus_4',
10003)"
+ qt_sql "select map('{\"zip\":10001}', '{\"city\":\"NY\"}',
'{\"code\":10002}', '{\"state\":\"NY\"}')"
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]