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

Calcite can not verify a explicit cast column in some scenario

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.17.0
    • Fix Version/s: 1.21.0
    • Component/s: core
    • Labels:
      None

      Description

      In now calcite core, there is a test case in agg.ig in line467:

      select deptno / 2 + 1 as half1, count(*) as c
      from emp
      group by rollup(deptno / 2, gender), rollup(substring(ename FROM 1 FOR 1));

      But if we add in an explicit cast:

      select cast(deptno as decimal) / 2 + 1 as half1, count(*) as c
      from emp
      group by rollup(deptno / 2, gender), rollup(substring(ename FROM 1 FOR 1));

      it will throw an error:

       

      Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1, column 13 to line 1, column 18: Expression 'DEPTNO' is not being grouped
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
      at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:810)
      at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:795)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:4749)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:117)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:41)
      at org.apache.calcite.sql.SqlIdentifier.accept(SqlIdentifier.java:344)
      at org.apache.calcite.sql.util.SqlBasicVisitor$ArgHandlerImpl.visitChild(SqlBasicVisitor.java:123)
      at org.apache.calcite.sql.SqlOperator.acceptCall(SqlOperator.java:859)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:212)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:41)
      at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
      at org.apache.calcite.sql.util.SqlBasicVisitor$ArgHandlerImpl.visitChild(SqlBasicVisitor.java:123)
      at org.apache.calcite.sql.SqlOperator.acceptCall(SqlOperator.java:859)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:212)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:41)
      at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
      at org.apache.calcite.sql.util.SqlBasicVisitor$ArgHandlerImpl.visitChild(SqlBasicVisitor.java:123)
      at org.apache.calcite.sql.SqlOperator.acceptCall(SqlOperator.java:859)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:212)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:41)
      at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
      at org.apache.calcite.sql.util.SqlBasicVisitor$ArgHandlerImpl.visitChild(SqlBasicVisitor.java:123)
      at org.apache.calcite.sql.SqlAsOperator.acceptCall(SqlAsOperator.java:121)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:212)
      at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:41)
      at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
      at org.apache.calcite.sql.validate.AggregatingSelectScope.checkAggregateExpr(AggregatingSelectScope.java:231)
      at org.apache.calcite.sql.validate.AggregatingSelectScope.validateExpr(AggregatingSelectScope.java:240)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.validateExpr(SqlValidatorImpl.java:4071)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4045)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3259)
      at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
      at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:972)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:948)
      at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:226)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:923)
      at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:633)
      at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:554)
      at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
      at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230)
      at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
      at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
      at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
      at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
      at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
      at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
      at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
      ... 36 more
      

       

       

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                danny0405 Danny Chen
                Reporter:
                danny0405 Danny Chen
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: