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

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

[~julianhyde] the main challenge within 
[#2279|https://github.com/apache/calcite/pull/2279] is this piece of code in 
{{SqlImplementor.convertConditionToSqlNode}}:
{code}
    case NOT:
      final RexNode operand0 = ((RexCall) node).getOperands().get(0);
      final SqlOperator notOperator = 
NOT_KIND_OPERATORS.get(operand0.getKind());
      if (notOperator != null) {
        return convertConditionToSqlNode(
            leftContext.implementor().rexBuilder.makeCall(notOperator,
                ((RexCall) operand0).operands), leftContext, rightContext,
            leftFieldCount, dialect);
      }
{code}
which creates a "notOperator" RexNode (e.g. NOT_LIKE) just before converting it 
into a SqlNode.
This makes e.g. {{RelToSqlConverterTest#testJoinOnNotLike}} to fail with the 
new excpetion thrown by {{SqlLikeOperator#validRexOperands}}:
{noformat}
unsupported negated operator NOT LIKE
java.lang.AssertionError: unsupported negated operator NOT LIKE
        at org.apache.calcite.util.Litmus$1.fail(Litmus.java:31)
        at 
org.apache.calcite.sql.fun.SqlLikeOperator.validRexOperands(SqlLikeOperator.java:134)
        at org.apache.calcite.rex.RexCall.<init>(RexCall.java:83)
        at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:258)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor.convertConditionToSqlNode(SqlImplementor.java:308)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor.convertConditionToSqlNode(SqlImplementor.java:320)
        at 
org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:215)
        ...
{noformat}

I am not familiar with {{SqlImplementor}} or {{RelToSqlConverter}}, so I am not 
sure how to proceed to circumvent this problem.

> SqlStdOperatorTable.NOT_LIKE has a wrong implementor
> ----------------------------------------------------
>
>                 Key: CALCITE-4415
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4415
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Ruben Q L
>            Assignee: Ruben Q L
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.27.0
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> {{SqlStdOperatorTable.NOT_LIKE}}'s implementor defined in {{RexImpTable}} is 
> currently the same as {{LIKE}} (i.e. {{NOT_LIKE}} performs the same operation 
> as {{LIKE}}):
> {code}
> ...
> final MethodImplementor likeImplementor =
>         new MethodImplementor(BuiltInMethod.LIKE.method, NullPolicy.STRICT, 
> false);
> map.put(LIKE, likeImplementor);
> map.put(NOT_LIKE, likeImplementor);
> {code}
> It should be:
> {code}
> ...
> map.put(LIKE, likeImplementor);
> map.put(NOT_LIKE, NotImplementor.of(likeImplementor));
> {code}
> Luckily, SQL queries seem to not suffer the consequences because 
> {{StandardConvertletTable}} expands {{x NOT LIKE y}} into {{NOT (x LIKE y)}}, 
> so the issue is avoided:
> {code}
> // Expand "x NOT LIKE y" into "NOT (x LIKE y)"
> registerOp(SqlStdOperatorTable.NOT_LIKE,
>     (cx, call) -> cx.convertExpression(
>         SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO,
>             SqlStdOperatorTable.LIKE.createCall(SqlParserPos.ZERO,
>                 call.getOperandList()))));
> {code}
> However, creating a plan via RelBuilder using 
> {{SqlStdOperatorTable.NOT_LIKE}} will lead to incorrect results.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to