[
https://issues.apache.org/jira/browse/CALCITE-5653?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17717862#comment-17717862
]
Julian Hyde commented on CALCITE-5653:
--------------------------------------
Looks good. Notes:
* Can you move the test case to {{testOrderDistinct}}? That seems to describe
the case better.
* Can you add a test to {{agg.iq}}? (Don't worry about setting
IdentifierExpansion, but let's just make sure it works in SQL.)
* Please fix the checkerframework errors.
* In the subject, capitalize ORDER BY and mention that it is a DISTINCT query
> Validation error when using aggregation from the select list in order by
> ------------------------------------------------------------------------
>
> Key: CALCITE-5653
> URL: https://issues.apache.org/jira/browse/CALCITE-5653
> Project: Calcite
> Issue Type: Bug
> Reporter: Itiel Sadeh
> Priority: Major
> Labels: pull-request-available
> Time Spent: 20m
> Remaining Estimate: 0h
>
> When using aggregation expression from the SELECT list in the ORDER BY
> clause in a DISTINCT query, there is a validation error of "expression is not
> in the select clause".
>
> The issue happens when casts are added the aggregation expression in
> {{{}SqlValidator{}}}, as they are not part of the select.
> For example, the following query:
> {code:java}
> SELECT distinct sum(deptno + '1') FROM dept ORDER BY 1
> {code}
> will lead to:
> {code:java}
> From line 1, column 21 to line 1, column 54: Expression 'SUM(`DEPT`.`DEPTNO`
> + CAST('1' AS INTEGER))' is not in the select clause
> org.apache.calcite.runtime.CalciteContextException: From line 1, column 21 to
> line 1, column 54: Expression 'SUM(`DEPT`.`DEPTNO` + CAST('1' AS INTEGER))'
> is not in the select clause
> at
> [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> at
> [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
> at
> [email protected]/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> at
> [email protected]/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
> at
> [email protected]/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
> at
> app//org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:505)
> at
> app//org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:945)
> at
> app//org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:930)
> at
> app//org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:5464)
> at
> app//org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:168)
> at
> app//org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:45)
> at app//org.apache.calcite.sql.SqlCall.accept(SqlCall.java:161)
> at
> app//org.apache.calcite.sql.validate.AggregatingSelectScope.checkAggregateExpr(AggregatingSelectScope.java:233)
> at
> app//org.apache.calcite.sql.validate.AggregatingSelectScope.validateExpr(AggregatingSelectScope.java:242)
> at
> app//org.apache.calcite.sql.validate.OrderByScope.validateExpr(OrderByScope.java:128)
> at
> app//org.apache.calcite.sql.validate.SqlValidatorImpl.validateExpr(SqlValidatorImpl.java:4676)
> at
> app//org.apache.calcite.sql.validate.SqlValidatorImpl.validateOrderItem(SqlValidatorImpl.java:4398)
> at
> app//org.apache.calcite.sql.validate.SqlValidatorImpl.validateOrderList(SqlValidatorImpl.java:4341)
> at
> app//org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3786)
> at
> app//org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:61)
> at
> app//org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:88)
> at
> app//org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1135)
> at
> app//org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:1106)
> at app//org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:282)
> at
> app//org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:1081)
> at
> app//org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:787)
> {code}
> The issue is that the code in\{{ AggChecker}} will search for the expanded
> node (with the CAST) in the select list, but the select list contains only
> the unexpanded node.
> This can be solved through setting\{{ identifierExpansion }}to true, but I
> don't think it should be related, as it's not an identifier expansion here.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)