Skip to content

[SPARK-44059][SQL] Add better error messages for SQL named argumnts#42177

Closed
learningchess2003 wants to merge 13 commits intoapache:masterfrom
learningchess2003:error-messages
Closed

[SPARK-44059][SQL] Add better error messages for SQL named argumnts#42177
learningchess2003 wants to merge 13 commits intoapache:masterfrom
learningchess2003:error-messages

Conversation

@learningchess2003
Copy link
Contributor

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)

@github-actions github-actions bot added the SQL label Jul 26, 2023
"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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These error message changes are specific to SQL named arguments, can you please update the PR title and description to indicate that?

@learningchess2003 learningchess2003 changed the title [SPARK-44059] Add better error messages [SPARK-44059] Add better error messages for SQL named argumnts Jul 27, 2023
@allisonwang-db
Copy link
Contributor

@learningchess2003 There is a LLM based tool to improve error messages: #41711 If possible could you test it out with your PR?

@github-actions github-actions bot added the DOCS label Jul 28, 2023
@learningchess2003
Copy link
Contributor Author

@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 =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}

def unexpectedPositionalArgument(functionName: String): Throwable = {
def unexpectedPositionalArgument(functionName: String, parameterName: String): Throwable = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename parameterName to something like last or preceding named argument?

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)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change?

[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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated as well

@learningchess2003
Copy link
Contributor Author

@anchovYu Fixed!

Copy link
Contributor

@anchovYu anchovYu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@github-actions github-actions bot added the INFRA label Aug 2, 2023
@github-actions github-actions bot removed the INFRA label Aug 2, 2023
@github-actions github-actions bot added the INFRA label Aug 2, 2023
@github-actions github-actions bot removed the INFRA label Aug 2, 2023
@learningchess2003
Copy link
Contributor Author

@MaxGekk All tests are green! Can you merge it when you have time?

Copy link
Contributor

@allisonwang-db allisonwang-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add [SQL] in the PR title as well?

@learningchess2003 learningchess2003 changed the title [SPARK-44059] Add better error messages for SQL named argumnts [SPARK-44059][SQL] Add better error messages for SQL named argumnts Aug 2, 2023
@dtenedor
Copy link
Contributor

dtenedor commented Aug 2, 2023

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 :) 🙏

@HyukjinKwon
Copy link
Member

Merged to master and branch-3.5.

HyukjinKwon pushed a commit that referenced this pull request Aug 3, 2023
### 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants