-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-17016][SQL] Improve group-by/order-by ordinal error reporting #14594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -538,39 +538,6 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { | |
| sql("SELECT 1, 2, sum(b) FROM testData2")) | ||
| } | ||
|
|
||
| test("Group By Ordinal - negative cases") { | ||
| intercept[UnresolvedException[Aggregate]] { | ||
| sql("SELECT a, b FROM testData2 GROUP BY -1") | ||
| } | ||
|
|
||
| intercept[UnresolvedException[Aggregate]] { | ||
| sql("SELECT a, b FROM testData2 GROUP BY 3") | ||
| } | ||
|
|
||
| var e = intercept[UnresolvedException[Aggregate]]( | ||
| sql("SELECT SUM(a) FROM testData2 GROUP BY 1")) | ||
| assert(e.getMessage contains | ||
| "Invalid call to Group by position: the '1'th column in the select contains " + | ||
| "an aggregate function") | ||
|
|
||
| e = intercept[UnresolvedException[Aggregate]]( | ||
| sql("SELECT SUM(a) + 1 FROM testData2 GROUP BY 1")) | ||
| assert(e.getMessage contains | ||
| "Invalid call to Group by position: the '1'th column in the select contains " + | ||
| "an aggregate function") | ||
|
|
||
| var ae = intercept[AnalysisException]( | ||
| sql("SELECT a, rand(0), sum(b) FROM testData2 GROUP BY a, 2")) | ||
| assert(ae.getMessage contains | ||
| "nondeterministic expression rand(0) should not appear in grouping expression") | ||
|
|
||
| ae = intercept[AnalysisException]( | ||
| sql("SELECT * FROM testData2 GROUP BY a, b, 1")) | ||
| assert(ae.getMessage contains | ||
| "Group by position: star is not allowed to use in the select list " + | ||
| "when using ordinals in group by") | ||
| } | ||
|
|
||
| test("Group By Ordinal: spark.sql.groupByOrdinal=false") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How difficult is it to port the SQLQueryTestSuite harness back to branch-2.0? |
||
| withSQLConf(SQLConf.GROUP_BY_ORDINAL.key -> "false") { | ||
| // If spark.sql.groupByOrdinal=false, ignore the position number. | ||
|
|
@@ -2467,18 +2434,6 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { | |
| Seq(Row(1, 1), Row(1, 2), Row(2, 1), Row(2, 2), Row(3, 1), Row(3, 2))) | ||
| } | ||
|
|
||
| test("order by ordinal number - negative cases") { | ||
| intercept[UnresolvedException[SortOrder]] { | ||
| sql("SELECT * FROM testData2 ORDER BY 0") | ||
| } | ||
| intercept[UnresolvedException[SortOrder]] { | ||
| sql("SELECT * FROM testData2 ORDER BY -1 DESC, b ASC") | ||
| } | ||
| intercept[UnresolvedException[SortOrder]] { | ||
| sql("SELECT * FROM testData2 ORDER BY 3 DESC, b ASC") | ||
| } | ||
| } | ||
|
|
||
| test("order by ordinal number with conf spark.sql.orderByOrdinal=false") { | ||
| withSQLConf(SQLConf.ORDER_BY_ORDINAL.key -> "false") { | ||
| // If spark.sql.orderByOrdinal=false, ignore the position number. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @cloud-fan / @gatorsmile do you know why star is not allowed here? I checked Postgres does allow star.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #10731 (comment)
I think it's not about group by ordinal, but about general group by
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but now we do support star in aggregation, cc @rxin
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the original discussion: #10731 (comment)
uh... one hour delay. I did not see @cloud-fan 's answer.