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

IN clause in CASE in GROUP BY gives AssertionError

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.0-incubating, 0.9.1-incubating
    • Fix Version/s: 1.2.0-incubating
    • Component/s: None
    • Labels:
      None

      Description

      hi, i'm using the latest optiq-csv(which depends on calcite 0.9.1).
      I even tried changing 0.9.1 to 0.9.2 in optiq-csv's pom, but it will fail "mvn clean install"

      here's my problem:

      ==============================================
      select (CASE WHEN (GENDER = 'F') THEN 'woman' ELSE GENDER END), min(EMPID) from EMPS group by (CASE WHEN (GENDER = 'F') THEN 'woman' ELSE GENDER END)

      >>> this works

      select (CASE WHEN (GENDER IN ('M','F')) THEN 'known' ELSE GENDER END), min(EMPID) from EMPS group by (CASE WHEN (GENDER IN ('M','F')) THEN 'known' ELSE GENDER END)

      >>> this will not work with exception:
      java.lang.AssertionError: Internal error: while converting CASE WHEN `EMPS`.`GENDER` IN ('M', 'F') THEN 'known' ELSE `EMPS`.`GENDER` END
      at org.eigenbase.util.Util.newInternal(Util.java:753)
      at org.eigenbase.sql2rel.ReflectiveConvertletTable$1.convertCall(ReflectiveConvertletTable.java:92)
      at org.eigenbase.sql2rel.SqlNodeToRexConverterImpl.convertCall(SqlNodeToRexConverterImpl.java:51)
      at org.eigenbase.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4162)
      at org.eigenbase.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3610)
      at org.eigenbase.sql.SqlCall.accept(SqlCall.java:124)
      at org.eigenbase.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4055)
      at org.eigenbase.sql2rel.SqlToRelConverter$AggConverter.addGroupExpr(SqlToRelConverter.java:4343)
      at org.eigenbase.sql2rel.SqlToRelConverter.createAggImpl(SqlToRelConverter.java:2433)
      at org.eigenbase.sql2rel.SqlToRelConverter.convertAgg(SqlToRelConverter.java:2384)
      at org.eigenbase.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:491)
      at org.eigenbase.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:451)
      at org.eigenbase.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:2803)
      at org.eigenbase.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:409)
      at net.hydromatic.optiq.prepare.Prepare.prepareSql(Prepare.java:211)
      at net.hydromatic.optiq.prepare.Prepare.prepareSql(Prepare.java:178)
      at net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepare2_(OptiqPrepareImpl.java:412)
      at net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepare_(OptiqPrepareImpl.java:318)
      at net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepareSql(OptiqPrepareImpl.java:287)
      at net.hydromatic.optiq.jdbc.OptiqConnectionImpl.parseQuery(OptiqConnectionImpl.java:170)
      at net.hydromatic.optiq.jdbc.MetaImpl.prepare(MetaImpl.java:617)
      at net.hydromatic.avatica.AvaticaStatement.execute(AvaticaStatement.java:67)
      at sqlline.Commands.execute(Commands.java:822)
      at sqlline.Commands.sql(Commands.java:732)
      at sqlline.SqlLine.dispatch(SqlLine.java:808)
      at sqlline.SqlLine.begin(SqlLine.java:681)
      at sqlline.SqlLine.start(SqlLine.java:398)
      at sqlline.SqlLine.main(SqlLine.java:292)
      Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.eigenbase.sql2rel.ReflectiveConvertletTable$1.convertCall(ReflectiveConvertletTable.java:83)
      ... 26 more
      Caused by: java.lang.NullPointerException
      at org.eigenbase.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4045)
      at org.eigenbase.sql2rel.StandardConvertletTable.convertCase(StandardConvertletTable.java:254)
      ... 31 more

        Issue Links

          Activity

          Hide
          julianhyde Julian Hyde added a comment -

          Resolved in release 1.2.0-incubating (2015-04-16)

          Show
          julianhyde Julian Hyde added a comment - Resolved in release 1.2.0-incubating (2015-04-16)
          Show
          julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/321217dd .
          Hide
          julianhyde Julian Hyde added a comment -

          I have a fix for this in my master branch. It won't go into Apache master until after release 1.1.

          https://github.com/julianhyde/incubator-calcite/commit/1bf2c276ee7f921cc7f11b144c09b50bca6efdce

          Show
          julianhyde Julian Hyde added a comment - I have a fix for this in my master branch. It won't go into Apache master until after release 1.1. https://github.com/julianhyde/incubator-calcite/commit/1bf2c276ee7f921cc7f11b144c09b50bca6efdce
          Hide
          julianhyde Julian Hyde added a comment - - edited

          Re-opening. I can reproduce it on the latest. Add the following to SqlToRelConverterTest and you get the same AssertionError:

            @Test public void testGroupByCaseIn() {
              sql("select (CASE WHEN (deptno IN (10, 20)) THEN 0 ELSE deptno END),\n"
                  + " min(empno) from EMP\n"
                  + "group by (CASE WHEN (deptno IN (10, 20)) THEN 0 ELSE deptno END)")
                  .convertsTo("${plan}");
            }
          
          Show
          julianhyde Julian Hyde added a comment - - edited Re-opening. I can reproduce it on the latest. Add the following to SqlToRelConverterTest and you get the same AssertionError: @Test public void testGroupByCaseIn() { sql( "select (CASE WHEN (deptno IN (10, 20)) THEN 0 ELSE deptno END),\n" + " min(empno) from EMP\n" + "group by (CASE WHEN (deptno IN (10, 20)) THEN 0 ELSE deptno END)" ) .convertsTo( "${plan}" ); }
          Hide
          mahongbin hongbin ma added a comment -

          hi Julian

          I'm using 1.0.0, but this time I'm facing a different error:

          java.lang.AssertionError
          at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.getRootField(SqlToRelConverter.java:4043)
          at org.apache.calcite.sql2rel.SqlToRelConverter.adjustInputRef(SqlToRelConverter.java:3349)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertIdentifier(SqlToRelConverter.java:3324)
          at org.apache.calcite.sql2rel.SqlToRelConverter.access$1400(SqlToRelConverter.java:178)
          at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4291)
          at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3729)
          at org.apache.calcite.sql.SqlIdentifier.accept(SqlIdentifier.java:271)
          at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4174)
          at org.apache.calcite.sql2rel.SqlToRelConverter.substituteSubquery(SqlToRelConverter.java:979)
          at org.apache.calcite.sql2rel.SqlToRelConverter.replaceSubqueries(SqlToRelConverter.java:937)
          at org.apache.calcite.sql2rel.SqlToRelConverter.createAggImpl(SqlToRelConverter.java:2683)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertAgg(SqlToRelConverter.java:2525)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:608)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:568)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:2929)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:526)
          at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:224)
          at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:191)
          at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:506)
          at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:402)
          at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:371)
          at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:174)
          at org.apache.calcite.jdbc.CalciteMetaImpl.prepare(CalciteMetaImpl.java:458)
          at org.apache.calcite.avatica.AvaticaStatement.execute(AvaticaStatement.java:95)
          at sqlline.Commands.execute(Commands.java:822)
          at sqlline.Commands.sql(Commands.java:732)
          at sqlline.SqlLine.dispatch(SqlLine.java:808)
          at sqlline.SqlLine.begin(SqlLine.java:681)
          at sqlline.SqlLine.start(SqlLine.java:398)
          at sqlline.SqlLine.main(SqlLine.java:292)

          Show
          mahongbin hongbin ma added a comment - hi Julian I'm using 1.0.0, but this time I'm facing a different error: java.lang.AssertionError at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.getRootField(SqlToRelConverter.java:4043) at org.apache.calcite.sql2rel.SqlToRelConverter.adjustInputRef(SqlToRelConverter.java:3349) at org.apache.calcite.sql2rel.SqlToRelConverter.convertIdentifier(SqlToRelConverter.java:3324) at org.apache.calcite.sql2rel.SqlToRelConverter.access$1400(SqlToRelConverter.java:178) at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4291) at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3729) at org.apache.calcite.sql.SqlIdentifier.accept(SqlIdentifier.java:271) at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4174) at org.apache.calcite.sql2rel.SqlToRelConverter.substituteSubquery(SqlToRelConverter.java:979) at org.apache.calcite.sql2rel.SqlToRelConverter.replaceSubqueries(SqlToRelConverter.java:937) at org.apache.calcite.sql2rel.SqlToRelConverter.createAggImpl(SqlToRelConverter.java:2683) at org.apache.calcite.sql2rel.SqlToRelConverter.convertAgg(SqlToRelConverter.java:2525) at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:608) at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:568) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:2929) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:526) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:224) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:191) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:506) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:402) at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:371) at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:174) at org.apache.calcite.jdbc.CalciteMetaImpl.prepare(CalciteMetaImpl.java:458) at org.apache.calcite.avatica.AvaticaStatement.execute(AvaticaStatement.java:95) at sqlline.Commands.execute(Commands.java:822) at sqlline.Commands.sql(Commands.java:732) at sqlline.SqlLine.dispatch(SqlLine.java:808) at sqlline.SqlLine.begin(SqlLine.java:681) at sqlline.SqlLine.start(SqlLine.java:398) at sqlline.SqlLine.main(SqlLine.java:292)
          Hide
          julianhyde Julian Hyde added a comment -

          Very likely a duplicate of https://issues.apache.org/jira/browse/CALCITE-516.

          Note that optiq-csv is now in Calcite, as the example/csv module. Try the latest version of calcite-example-csv and let us know whether this issue is fixed.

          Show
          julianhyde Julian Hyde added a comment - Very likely a duplicate of https://issues.apache.org/jira/browse/CALCITE-516 . Note that optiq-csv is now in Calcite, as the example/csv module. Try the latest version of calcite-example-csv and let us know whether this issue is fixed.

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              mahongbin hongbin ma
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development