This is an automated email from the ASF dual-hosted git repository.
csun5285 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 183d73e778f [fix](fe) Reject complex types as map keys (#69101)
183d73e778f is described below
commit 183d73e778f62533d80b13772e06c973518cee1e
Author: Chenyang Sun <[email protected]>
AuthorDate: Mon Oct 19 14:42:53 2026 +0800
[fix](fe) Reject complex types as map keys (#69101)
### What problem does this PR solve?
```
sql "select map(named_struct('a', 1), 'v')"
exception "MAP key type must be a primitive type"
```
---
.../trees/expressions/functions/scalar/CreateMap.java | 4 ++++
.../functions/scalar/MapConstructionFunctionsTest.java | 16 ++++++++++++++++
.../scalar_function/nereids_scalar_fn_map.groovy | 13 +++++++++++++
3 files changed, 33 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 6fdcccf402b..d5bc6ad9752 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
@@ -88,6 +88,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()) {
throw new AnalysisException("map does not support jsonb type");
}
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
index 89219419db1..2c197c86104 100644
---
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
@@ -126,6 +126,22 @@ public class MapConstructionFunctionsTest {
TinyIntType.INSTANCE, ArrayType.of(TinyIntType.INSTANCE));
}
+ @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)"));
+ }
+
@Test
public void testMapFromEntriesPreservesIndependentPrecision() {
DataType decimalKeyType = DecimalV3Type.createDecimalV3Type(38, 0);
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]