This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 690a4b6b000 branch-4.2: [fix](fe) Reject complex types as map keys
#69101 (#69272)
690a4b6b000 is described below
commit 690a4b6b0005b57a7b94bda58f5a43a392e71bd8
Author: Chenyang Sun <[email protected]>
AuthorDate: Tue Oct 20 10:10:08 2026 +0800
branch-4.2: [fix](fe) Reject complex types as map keys #69101 (#69272)
Backport #69101 to `branch-4.2`.
---
.../expressions/functions/scalar/CreateMap.java | 4 ++
.../scalar/MapConstructionFunctionsTest.java | 52 ++++++++++++++++++++++
.../scalar_function/nereids_scalar_fn_map.groovy | 13 ++++++
3 files changed, 69 insertions(+)
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 d00cfc8e27c..2e054c6e06a 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
@@ -89,6 +89,10 @@ public class CreateMap extends ScalarFunction
for (int i = 0; i < arity(); i++) {
DataType childType = getArgument(i).getDataType();
boolean isKey = i % 2 == 0;
+ if (isKey && childType.isComplexType()) {
+ throw new AnalysisException(
+ "MAP key type must be a primitive type but get " +
childType.toSql());
+ }
if (childType.isJsonType()
|| (isKey && childType.isVariantType())
|| (!isKey && VariantType.isLegacyVariant(childType))) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MapConstructionFunctionsTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MapConstructionFunctionsTest.java
new file mode 100644
index 00000000000..160e4192b3a
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MapConstructionFunctionsTest.java
@@ -0,0 +1,52 @@
+// 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.
+
+package org.apache.doris.nereids.trees.expressions.functions.scalar;
+
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.rules.expression.ExpressionRewriteTestHelper;
+import org.apache.doris.nereids.trees.expressions.Expression;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class MapConstructionFunctionsTest {
+
+ private static final NereidsParser PARSER = new NereidsParser();
+
+ @Test
+ public void testCreateMapRejectsComplexKey() {
+ for (String sql : ImmutableList.of(
+ "map(array(1, 2), 'v')",
+ "map(named_struct('a', 1), 'v')",
+ "map(map(1, 2), 'v')")) {
+ AnalysisException complexKeyException = Assertions.assertThrows(
+ AnalysisException.class, () -> analyze(sql));
+ Assertions.assertTrue(complexKeyException.getMessage().contains(
+ "MAP key type must be a primitive type"),
complexKeyException::getMessage);
+ }
+
+ Assertions.assertDoesNotThrow(() -> analyze("map('k', array(1, 2))"));
+ Assertions.assertDoesNotThrow(() -> analyze("map(NULL, 100)"));
+ }
+
+ private Expression analyze(String sql) {
+ return
ExpressionRewriteTestHelper.typeCoercion(PARSER.parseExpression(sql));
+ }
+}
diff --git
a/regression-test/suites/nereids_function_p0/scalar_function/nereids_scalar_fn_map.groovy
b/regression-test/suites/nereids_function_p0/scalar_function/nereids_scalar_fn_map.groovy
index 2a37e91c36a..90eca7c74ae 100644
---
a/regression-test/suites/nereids_function_p0/scalar_function/nereids_scalar_fn_map.groovy
+++
b/regression-test/suites/nereids_function_p0/scalar_function/nereids_scalar_fn_map.groovy
@@ -335,6 +335,19 @@ suite("nereids_scalar_fn_map") {
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\"}')"
+ test {
+ sql "select map(array(1, 2), 'v')"
+ exception "MAP key type must be a primitive type"
+ }
+ test {
+ sql "select map(named_struct('a', 1), 'v')"
+ exception "MAP key type must be a primitive type"
+ }
+ test {
+ sql "select map(map(1, 2), 'v')"
+ exception "MAP key type must be a primitive type"
+ }
+
sql """ drop table if exists fn_test_element_at_map_date """
sql """
create table fn_test_element_at_map_date (
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]