[SPARK-44059][SQL] Add better error messages for SQL named argumnts#42177
[SPARK-44059][SQL] Add better error messages for SQL named argumnts#42177learningchess2003 wants to merge 13 commits intoapache:masterfrom
Conversation
| "BOTH_POSITIONAL_AND_NAMED" : { | ||
| "message" : [ | ||
| "A positional argument and named argument both referred to the same parameter." | ||
| "A positional argument and named argument both referred to the same parameter. Please remove the named argument referring to this parameter." |
There was a problem hiding this comment.
These error message changes are specific to SQL named arguments, can you please update the PR title and description to indicate that?
|
@learningchess2003 There is a LLM based tool to improve error messages: #41711 If possible could you test it out with your PR? |
|
@allisonwang-db Tried the Chat GPT tool. The error messages were basically the same. So, I kept this one. |
| val namedParametersSet = collection.mutable.Set[String]() | ||
|
|
||
| for (arg <- namedArgs) { | ||
| namedArgs.zipWithIndex.foreach { tuple => |
There was a problem hiding this comment.
| namedArgs.zipWithIndex.foreach { tuple => | |
| namedArgs.zipWithIndex.foreach { case (arg, index) => |
|
|
||
| // We rearrange named arguments to match their positional order. | ||
| val rearrangedNamedArgs: Seq[Expression] = namedParameters.map { param => | ||
| val rearrangedNamedArgs: Seq[Expression] = namedParameters.zipWithIndex.map { tuple => |
| } | ||
|
|
||
| def unexpectedPositionalArgument(functionName: String): Throwable = { | ||
| def unexpectedPositionalArgument(functionName: String, parameterName: String): Throwable = { |
There was a problem hiding this comment.
Can we rename parameterName to something like last or preceding named argument?
Co-authored-by: Xinyi <xyyu15@gmail.com>
python/pyspark/worker.py
Outdated
| return result | ||
|
|
||
| return lambda *a: map(lambda res: (res, arrow_return_type), map(verify_result, f(*a))) | ||
| return lambda *a: map(lambda res: (res, arrow_return_type), map(verify_result, f(*a, **kw))) |
docs/sql-error-conditions.md
Outdated
| [SQLSTATE: 4274K](sql-error-conditions-sqlstates.html#class-42-syntax-error-or-access-rule-violation) | ||
|
|
||
| Cannot invoke function `<functionName>` because the parameter named `<parameterName>` is required, but the function call did not supply a value. Please update the function call to supply an argument value (either positionally or by name) and retry the query again. | ||
| Cannot invoke function `<functionName>` because the parameter named `<parameterName>` is required at index `<index>`, but the function call did not supply a value. Please update the function call to supply an argument value (either positionally or by name) and retry the query again. |
There was a problem hiding this comment.
This should be updated as well
|
@anchovYu Fixed! |
|
@MaxGekk All tests are green! Can you merge it when you have time? |
allisonwang-db
left a comment
There was a problem hiding this comment.
Can you add [SQL] in the PR title as well?
|
Hi @MaxGekk @HyukjinKwon the tests for this PR are passing, if everything looks good to you, would one of you mind to merge this PR for us? Thanks :) 🙏 |
|
Merged to master and branch-3.5. |
### What changes were proposed in this pull request? Correct error messages. ### Why are the changes needed? Need to have better quality messages. ### Does this PR introduce _any_ user-facing change? Error messages are more specific. ### How was this patch tested? Tested in SQLQueryTestSuite: named-function-arguments.sql and NamedParameterFunctionSuite. Authored-by: Richard Yu <richard.yudatabricks.com> (cherry picked from commit 228b5db) Closes #42177 from learningchess2003/error-messages. Lead-authored-by: Richard Yu <richard.yu@databricks.com> Co-authored-by: Richard Yu <134337791+learningchess2003@users.noreply.github.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org> (cherry picked from commit b390c9c) Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
What changes were proposed in this pull request?
Correct error messages.
Why are the changes needed?
Need to have better quality messages.
Does this PR introduce any user-facing change?
Error messages are more specific.
How was this patch tested?
Tested in SQLQueryTestSuite: named-function-arguments.sql and NamedParameterFunctionSuite.
Authored-by: Richard Yu richard.yu@databricks.com
(cherry picked from commit 228b5db)