You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Ruben Q L (Jira)" <ji...@apache.org> on 2023/08/29 16:24:00 UTC

[jira] [Commented] (CALCITE-5967) UnsupportedOperationException while implementing call that requires a special collator

    [ https://issues.apache.org/jira/browse/CALCITE-5967?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17760020#comment-17760020 ] 

Ruben Q L commented on CALCITE-5967:
------------------------------------

Problem can be reproduced by adding this test into {{EnumerableStringComparisonTest}}:

{code}
  @Test void testFilterStringSpecialCollation() {
    tester()
        .withRel(builder -> builder
            .values(
                createRecordVarcharSpecialCollation(builder),
                "Legal", "presales", "hr", "Administration", "MARKETING")
            .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");
  }
{code}

which fails with:
{noformat}
...
	Suppressed: java.lang.UnsupportedOperationException
		at java.base/java.util.AbstractList.add(AbstractList.java:153)
		at java.base/java.util.AbstractList.add(AbstractList.java:111)
		at org.apache.calcite.adapter.enumerable.RexImpTable$BinaryImplementor.implementSafe(RexImpTable.java:2876)
		at org.apache.calcite.adapter.enumerable.RexImpTable$AbstractRexCallImplementor.genValueStatement(RexImpTable.java:3768)
		at org.apache.calcite.adapter.enumerable.RexImpTable$AbstractRexCallImplementor.implement(RexImpTable.java:3730)
		at org.apache.calcite.adapter.enumerable.RexToLixTranslator.visitCall(RexToLixTranslator.java:1184)
...
{noformat}

> UnsupportedOperationException while implementing call that requires a special collator 
> ---------------------------------------------------------------------------------------
>
>                 Key: CALCITE-5967
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5967
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Ruben Q L
>            Assignee: Ruben Q L
>            Priority: Major
>             Fix For: 1.36.0
>
>
> Regression introduced by a minor change within CALCITE-5914, detected while testing a downstream project with the latest Calcite main.
> CALCITE-5914 (see [2a96512c|https://github.com/apache/calcite/commit/2a96512c352bda4a5d9c0c80730f5c115ac363d6]) introduced this apparently innocuous change in {{RexImpTable#AbstractRexCallImplementor#unboxIfNecessary}}:
> {code}
> // old
> argValueList.stream()
>             .map(AbstractRexCallImplementor::unboxExpression)
>             .collect(Collectors.toList());
> =>
> // new
> Util.transform(argValueList,
>             AbstractRexCallImplementor::unboxExpression);
> {code}
> Both expressions seem equivalent, however there is a subtle difference: the old one returns an {{ArrayList}} (where we can add new elements); wheres the new one returns a {{TransformingList}} that extends {{AbstractList}} and that does not support {{List#add}}.
> After calling {{unboxIfNecessary}}, we might need to modify the argument list if we need a special collator to perform the operation:
> {code}
>     private ParameterExpression genValueStatement(...) {
>       ...
>       optimizedArgValueList = unboxIfNecessary(optimizedArgValueList);
>       final Expression callValue =
>           implementSafe(translator, call, optimizedArgValueList);
>       ...
>     }
>     @Override Expression implementSafe(...) {
>       ...
>       final Expression fieldComparator =
>           generateCollatorExpression(relDataType0.getCollation());
>       if (fieldComparator != null) {
>         argValueList.add(fieldComparator);  // <--- UnsupportedOperationException!
>       }
>       ...
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)