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

Join on range causes AssertionError in RelToSqlConverter

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.27.0
    • Component/s: core
    • Labels:
      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

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              swtalbot Steven Talbot
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: