-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-50418][SQL] Allow an optional trailing comma at the end of SELECT lists #48961
base: master
Are you sure you want to change the base?
Conversation
158e66d
to
256a5b5
Compare
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.
to help with migration from other legacy databases.
Could you point out a couple such dbms in PR's description that support the feature, please.
@@ -5268,6 +5268,15 @@ object SQLConf { | |||
.booleanConf | |||
.createWithDefault(true) | |||
|
|||
val OPTIONAL_TRAILING_COMMA_IN_NAMED_EXPRESSION_LISTS = | |||
buildConf("spark.sql.optionalTrailingCommaInNamedExpressionLists") |
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.
The config name confuses slightly. I would think if it is true
, the trailing comma is optional otherwise is mandatory ;-).
buildConf("spark.sql.optionalTrailingCommaInNamedExpressionLists") | |
buildConf("spark.sql.allowTrailingCommaInNamedExpressionLists") |
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.
named expression list is not a user-facing concept, how about spark.sql.allowTrailingCommaInSelectList
?
test("SPARK-50418: Support an optional trailing comma at the end of SELECT lists") { | ||
withSQLConf(SQLConf.OPTIONAL_TRAILING_COMMA_IN_NAMED_EXPRESSION_LISTS.key -> "true") { | ||
assertEqual("select 1, ", OneRowRelation().select(1)) | ||
assertEqual("select 1, 2", OneRowRelation().select(1, 2)) |
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.
nit: let's also test select 1, 2,
withSQLConf(SQLConf.OPTIONAL_TRAILING_COMMA_IN_NAMED_EXPRESSION_LISTS.key -> "false") { | ||
assertEqual("select 1, 2", OneRowRelation().select(1, 2)) | ||
checkError( | ||
exception = parseException("select 1,"), |
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.
nit: let's also test select 1, 2,
@@ -425,7 +425,7 @@ org.apache.spark.sql.catalyst.parser.ParseException | |||
"sqlState" : "42601", | |||
"messageParameters" : { | |||
"error" : "'BY'", | |||
"hint" : ": extra input 'BY'" | |||
"hint" : "" |
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.
why do we lose the hint?
What changes were proposed in this pull request?
This PR extends the Spark SQL grammar to allow an optional trailing comma at the end of SELECT lists, and other named expression lists.
This behavior is controlled by the configuration
spark.sql.optionalTrailingCommaInNamedExpressionLists
(SQLConf.get.OPTIONAL_TRAILING_COMMA_IN_NAMED_EXPRESSION_LISTS
). The new configuration is true by default as of its introduction in this PR.For example, this query was not valid syntax before, but is now:
Why are the changes needed?
After deliberation, we decided it was useful to have this support to help with migration from other legacy databases.
Does this PR introduce any user-facing change?
Yes, see above.
How was this patch tested?
This PR adds unit test cases with the configuration enabled and disabled.
Was this patch authored or co-authored using generative AI tooling?
No.