korowa opened a new pull request, #10679:
URL: https://github.com/apache/datafusion/pull/10679
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
Closes #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
While #10591 found that planning for INT literals in GROUP BY clause is
inconsistent. For example:
```sql
EXPLAIN SELECT "URL", COUNT(1) from hits GROUP BY 1, 3, 4, 5
```
produces following logical plan (this is logical plan before any
optimizations):
```sql
Explain
Projection: hits.URL, COUNT(Int64(1))
Aggregate: groupBy=[[hits.URL, Int64(3), Int64(4), Int64(5)]],
aggr=[[COUNT(Int64(1))]]
TableScan: hits
```
`1` resolved as column from select clause, and `3, 4, 5` remain as
constants. Don't think this behavior is intended + there are couple of tests in
`sql_integration.rs` (modified below), for similar cases, expect queries to
fail.
The suggestion is to fail while planning phase for such cases, and return
error, specifying first index which can not be resolved as select column.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
Resolution for positions (integer literals in `GROUP BY` clause) now returns
error on first unresolved position.
SIgnature for `resolve_positions_to_exprs` changed to avoid unnecessary
cloning. `resolve_aliases_to_exprs` signature has similar changes, for the same
reasons (it's been changed just for consistency with resolve_positions_...
function).
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
-->
Added sqllogictests + some test coverage for `resolve_positions_to_exprs`
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
Users might experience query planning failures for `GROUP BY %idx%` where
`idx` is out of bounds of `SELECT` expressions list (which seems to be OK from
SQL semantics point of view -- PG/MySQL handle this case in the same way).
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]