This is an automated email from the ASF dual-hosted git repository.

rubenql 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 164ff0a27e [CALCITE-5967] UnsupportedOperationException while 
implementing a call that requires a special collator
164ff0a27e is described below

commit 164ff0a27e243850d294908dc5cff90760d0a35a
Author: rubenada <rube...@gmail.com>
AuthorDate: Tue Aug 29 17:49:20 2023 +0100

    [CALCITE-5967] UnsupportedOperationException while implementing a call that 
requires a special collator
---
 .../calcite/adapter/enumerable/RexImpTable.java    |  6 ++++--
 .../enumerable/EnumerableStringComparisonTest.java | 23 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index 93203afe3c..91a7aed9b0 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -44,6 +44,7 @@ import org.apache.calcite.rex.RexInputRef;
 import org.apache.calcite.rex.RexLiteral;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.rex.RexPatternFieldRef;
+import org.apache.calcite.runtime.FlatLists;
 import org.apache.calcite.runtime.SqlFunctions;
 import org.apache.calcite.schema.FunctionContext;
 import org.apache.calcite.schema.ImplementableAggFunction;
@@ -2865,7 +2866,7 @@ public class RexImpTable {
     @Override Expression implementSafe(
         final RexToLixTranslator translator,
         final RexCall call,
-        final List<Expression> argValueList) {
+        List<Expression> argValueList) {
       // neither nullable:
       //   return x OP y
       // x nullable
@@ -2892,7 +2893,8 @@ public class RexImpTable {
       final Expression fieldComparator =
           generateCollatorExpression(relDataType0.getCollation());
       if (fieldComparator != null) {
-        argValueList.add(fieldComparator);
+        // We need to add the comparator, the argValueList might be 
non-mutable, so create a new one
+        argValueList = FlatLists.append(argValueList, fieldComparator);
       }
 
       final Primitive primitive = Primitive.ofBoxOr(type0);
diff --git 
a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
index fd12311b49..d7f40b4dc5 100644
--- 
a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
+++ 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
@@ -137,6 +137,29 @@ class EnumerableStringComparisonTest {
             "name=presales");
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5967";>[CALCITE-5967]
+   * UnsupportedOperationException while implementing a call that requires a 
special collator</a>.
+   */
+  @Test void testFilterStringSpecialCollation() {
+    tester()
+        .withRel(builder -> builder
+            .values(
+                createRecordVarcharSpecialCollation(builder),
+                "Legal", "presales", "hr", "Administration", "MARKETING")
+            // Filter on a field with special collation:
+            // a special comparator needs to be used inside the eq operation
+            .filter(
+                builder.equals(
+                    builder.field(1, 0, "name"),
+                    builder.literal("MARKETING")))
+            .build())
+        .explainHookMatches(""
+            + "EnumerableCalc(expr#0=[{inputs}], expr#1=['MARKETING'], 
expr#2=[=($t0, $t1)], name=[$t0], $condition=[$t2])\n"
+            + "  EnumerableValues(tuples=[[{ 'Legal' }, { 'presales' }, { 'hr' 
}, { 'Administration' }, { 'MARKETING' }]])\n")
+        .returnsUnordered("name=MARKETING");
+  }
+
   @Test void testMergeJoinOnStringSpecialCollation() {
     tester()
         .withHook(Hook.PLANNER, (Consumer<RelOptPlanner>) planner -> {

Reply via email to