This is an automated email from the ASF dual-hosted git repository.
mbudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new e2183d4896 [CALCITE-7095] Allow MAP<VARIANT, X> to be indexed by any
type of key
e2183d4896 is described below
commit e2183d4896325aa443f3ac43d0ea92823396e1ce
Author: Mihai Budiu <[email protected]>
AuthorDate: Tue Jul 15 18:32:52 2025 -0700
[CALCITE-7095] Allow MAP<VARIANT, X> to be indexed by any type of key
Signed-off-by: Mihai Budiu <[email protected]>
---
.../main/java/org/apache/calcite/sql/fun/SqlItemOperator.java | 4 ++++
core/src/test/resources/sql/variant.iq | 11 +++++++++++
2 files changed, 15 insertions(+)
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
b/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
index 82551e8c00..1a1fb4d2a8 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
@@ -160,6 +160,10 @@ private static SqlSingleOperandTypeChecker
getChecker(SqlCallBinding callBinding
RelDataType keyType =
requireNonNull(operandType.getKeyType(), "operandType.getKeyType()");
SqlTypeName sqlTypeName = keyType.getSqlTypeName();
+ if (sqlTypeName == SqlTypeName.VARIANT) {
+ // Allow any key type to be used when the map keys have a VARIANT type
+ return OperandTypes.family(SqlTypeFamily.ANY);
+ }
return OperandTypes.family(
requireNonNull(sqlTypeName.getFamily(),
() -> "keyType.getSqlTypeName().getFamily() null, type is " +
sqlTypeName));
diff --git a/core/src/test/resources/sql/variant.iq
b/core/src/test/resources/sql/variant.iq
index 5ed3fd989c..172cd2ed59 100644
--- a/core/src/test/resources/sql/variant.iq
+++ b/core/src/test/resources/sql/variant.iq
@@ -20,6 +20,17 @@
!use scott
!set outputformat csv
+# Test case for [CALCITE-7095] Allow MAP<VARIANT, X> to be indexed by any type
of key
+SELECT CAST(MAP['a', 1] AS MAP<VARIANT, VARIANT>)['a'] AS C;
+C
+1
+!ok
+
+SELECT CAST(MAP['a', 1] AS MAP<VARIANT, VARIANT>)[1] AS C;
+C
+null
+!ok
+
SELECT CAST(1 AS VARIANT) as C;
C
1