You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (JIRA)" <ji...@apache.org> on 2018/05/24 16:39:00 UTC

[jira] [Commented] (CALCITE-2325) Calcite can not verify a explicit cast column in some scenario

    [ https://issues.apache.org/jira/browse/CALCITE-2325?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16489341#comment-16489341 ] 

Julian Hyde commented on CALCITE-2325:
--------------------------------------

This is not a bug. Calcite will only recognize that an expression occurred in GROUP BY if it matches structurally. If I write {{GROUP BY x + y}} then {{x + y + z}} is a structural match (the parse tree {{((x + y) + z)}} contains {{x + y}} as a sub-expression) but {{x + 0 + y}} is not (the matcher does not know about mathematical identities) and neither is {{y + x}} (the matcher does not know that "+" is commutative).

In your case, the matcher does not know that {{CAST(deptno AS DECIMAL) / 2 + 1}} can be rewritten as {{CAST(deptno AS DECIMAL / 2 + 1)}}.

> Calcite can not verify a explicit cast column in some scenario
> --------------------------------------------------------------
>
>                 Key: CALCITE-2325
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2325
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.17.0
>            Reporter: Yuzhao Chen
>            Assignee: Julian Hyde
>            Priority: Major
>             Fix For: 1.17.0
>
>
> In now calcite core, there is a test case in agg.ig in line467:
> {code:java}
> select deptno / 2 + 1 as half1, count(*) as c
> from emp
> group by rollup(deptno / 2, gender), rollup(substring(ename FROM 1 FOR 1));{code}
> But if we add in an explicit cast:
> {code:java}
> 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));{code}
> it will throw an error:
>  
> {code:java}
> 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
> {code}
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)