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

Join on range causes AssertionError in RelToSqlConverter

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • None
    • 1.27.0
    • core
    • None

    Description

       

      @Test void testSargGeneratingJoinCondition() {
        final String sql = "SELECT v1.deptno, v2.deptno\n"
            + "FROM dept v1 LEFT JOIN emp v2 ON v1.deptno = v2.deptno AND v1.deptno < 15 AND v1.deptno > 10\n"
            + "WHERE v2.job LIKE 'PRESIDENT'";
        // note: not quite the right expected SQL, but the point is this test just blows up
        final String expected = "SELECT \"DEPT\".\"DEPTNO\","
            + " \"EMP\".\"DEPTNO\" AS \"DEPTNO0\"\n"
            + "FROM \"SCOTT\".\"DEPT\"\n"
            + "LEFT JOIN \"SCOTT\".\"EMP\""
            + " ON \"DEPT\".\"DEPTNO\" = \"EMP\".\"DEPTNO\"\n"
            + "WHERE \"EMP\".\"JOB\" LIKE 'PRESIDENT'";
        sql(sql)
            .schema(CalciteAssert.SchemaSpec.JDBC_SCOTT)
            .ok(expected);
      }
      

      ^^ test in RelToSqlConverterTest.java

      I'm not entirely sure where in the flow between the parse into RelNode and the conversion from RelNode->SqlNode the Sarg is supposed to be expanded, but clearly, by the time it hits the RelToSqlConverter, it's too late.

       

      Stack trace:

       

      SEARCH($0, Sarg[(10..15)])SEARCH($0, Sarg[(10..15)])java.lang.AssertionError: SEARCH($0, Sarg[(10..15)]) at org.apache.calcite.rel.rel2sql.SqlImplementor.convertConditionToSqlNode(SqlImplementor.java:379) at org.apache.calcite.rel.rel2sql.SqlImplementor.convertConditionToSqlNode(SqlImplementor.java:320) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:215) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:525) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:131) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitInput(RelToSqlConverter.java:139) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:186) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:180) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:326) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:525) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:131) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitInput(RelToSqlConverter.java:139) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:186) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:180) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:336) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:525) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:131) at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitInput(RelToSqlConverter.java:139) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:186) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:174) at org.apache.calcite.rel.rel2sql.SqlImplementor.visitRoot(SqlImplementor.java:154) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.toSql(RelToSqlConverterTest.java:197) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.access$300(RelToSqlConverterTest.java:99) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.exec(RelToSqlConverterTest.java:5723) at org.apache.calcite.rel.rel2sql.RelToSqlConverterTest$Sql.ok(RelToSqlConverterTest.java:5693)

       

       

      Attachments

        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:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment