Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4249

JDBC adapter cannot translate NOT LIKE in join condition

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.26.0
    • None
    • None

    Description

      JDBC adapter cannot translate NOT LIKE in join condition. Rel2SqlConverter throws assertion error for NOT operator in join condition.

      The following test shows the bug if you put it in RelToSqlConverter

      @Test void testJoinWithNotLikeConditionRel2Sql() {
        final Function<RelBuilder, RelNode> relFn = b -> b
            .scan("EMP")
            .scan("DEPT")
            .join(JoinRelType.LEFT,
                b.and(
                    b.call(SqlStdOperatorTable.EQUALS,
                        b.field(2, 0, "DEPTNO"),
                        b.field(2, 1, "DEPTNO")),
                    b.call(SqlStdOperatorTable.NOT,
                        b.call(SqlStdOperatorTable.LIKE,
                            b.field(2, 1, "DNAME"),
                            b.literal("ACCOUNTING_FOO"))
                    )
                ))
            .build();
        final String expectedSql = "SELECT *\n"
            + "FROM \"scott\".\"EMP\"\n"
            + "LEFT JOIN \"scott\".\"DEPT\" "
            + "ON \"EMP\".\"DEPTNO\" = \"DEPT\".\"DEPTNO\" "
            + "AND \"DEPT\".\"DNAME\" NOT LIKE 'ACCOUNTING'";
        relFn(relFn).ok(expectedSql);
      }
      

      It blows up with the following stacktrace top:

      java.lang.AssertionError: NOT(LIKE($9, 'ACCOUNTING_FOO'))
              at org.apache.calcite.rel.rel2sql.SqlImplementor.convertConditionToSqlNode(SqlImplementor.java:350)
              at org.apache.calcite.rel.rel2sql.SqlImplementor.convertConditionToSqlNode(SqlImplementor.java:286)
              at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:213)
              at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524)
              at org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:131)
              at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitInput(RelToSqlConverter.java:139)

       

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            julianhyde Julian Hyde
            swtalbot Steven Talbot
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment