[ 
https://issues.apache.org/jira/browse/CALCITE-3061?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Volodymyr Vysotskyi resolved CALCITE-3061.
------------------------------------------
    Resolution: Fixed

Fixed in 
[d0a06f7|https://github.com/apache/calcite/commit/d0a06f78644906c2ca73e6fb5ea08f7d17f55dab].

Thanks [~julianhyde] and [~danny0405] for the review!

> Query with WITH clause fails when alias is the same as the table with rolled 
> up column
> --------------------------------------------------------------------------------------
>
>                 Key: CALCITE-3061
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3061
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Volodymyr Vysotskyi
>            Assignee: Volodymyr Vysotskyi
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.20.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> {{SqlValidatorImpl}} incorrectly resolves aliases for CTE when checking 
> rolled up columns when a table with the same name is present.
> It may be observed with the following case: we have table {{emp_r}} which 
> contains rolled up column {{slackingmin}}. The following query:
> {code:sql}
> with emp_r as (select 1 as slackingmin) select slackingmin from emp_r
> {code}
> should pass since it uses CTE, not table.
>  Error for this case:
> {noformat}
> org.apache.calcite.sql.validate.SqlValidatorException: Rolled up column 
> 'SLACKINGMIN' is not allowed in SELECT
>       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.runtime.Resources$ExInst.ex(Resources.java:572)
>       at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:787)
>       at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:772)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:4825)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(SqlValidatorImpl.java:3438)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(SqlValidatorImpl.java:3447)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInSelectList(SqlValidatorImpl.java:3373)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3361)
>       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:994)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:954)
>       at 
> org.apache.calcite.sql.validate.WithNamespace.validateImpl(WithNamespace.java:57)
>       at 
> org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:994)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateWith(SqlValidatorImpl.java:3787)
>       at org.apache.calcite.sql.SqlWith.validate(SqlWith.java:71)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:929)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:633)
> {noformat}



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

Reply via email to