-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-41409][CORE][SQL] Rename _LEGACY_ERROR_TEMP_1043 to WRONG_NUM_ARGS.WITHOUT_SUGGESTION
#38940
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
Conversation
WRONG_NUM_ARGS instead of _LEGACY_ERROR_TEMP_1043WRONG_NUM_ARGS instead of _LEGACY_ERROR_TEMP_1043
WRONG_NUM_ARGS instead of _LEGACY_ERROR_TEMP_1043_LEGACY_ERROR_TEMP_1043 to INVALID_FUNCTION_ARGS
| assert(e.getMessage.contains("Invalid arguments for function cast")) | ||
| checkError( | ||
| exception = intercept[AnalysisException] { | ||
| sql("SELECT CAST(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.
spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
Lines 137 to 144 in 37453ad
| // Otherwise, find a constructor method that matches the number of arguments, and use that. | |
| val params = Seq.fill(expressions.size)(classOf[Expression]) | |
| val f = constructors.find(_.getParameterTypes.toSeq == params).getOrElse { | |
| val validParametersCount = constructors | |
| .filter(_.getParameterTypes.forall(_ == classOf[Expression])) | |
| .map(_.getParameterCount).distinct.sorted | |
| throw QueryCompilationErrors.invalidFunctionArgumentNumberError( | |
| validParametersCount, name, params.length) |
In this scenario, the validParametersCount is also empty, so WRONG_NUM_ARGS cannot be reused now
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.
Do you have any suggestions on the calculation way of validParametersCount @MaxGekk ?
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 code above is not correct actually in some cases. One more example is TimestampAdd:
Lines 3156 to 3159 in a3a755d
| case class TimestampAdd( | |
| unit: String, | |
| quantity: Expression, | |
| timestamp: Expression, |
_LEGACY_ERROR_TEMP_1043 to INVALID_FUNCTION_ARGS_LEGACY_ERROR_TEMP_1043 to INVALID_FUNCTION_ARGS
| new AnalysisException( | ||
| errorClass = "_LEGACY_ERROR_TEMP_1043", | ||
| messageParameters = Map("name" -> name)) | ||
| errorClass = "INVALID_FUNCTION_ARGS", |
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.
@MaxGekk This should be an internal exception?
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.
This may be triggered by the user action, such as SELECT CAST(1) in UDFSuite.scala
| assert(spark.range(2).select(nonDeterministicJavaUDF()).distinct().count() == 2) | ||
| } | ||
|
|
||
| test("SPARK-28521 error message for CAST(parameter types contains DataType)") { |
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.
Let's move this test to QueryCompilationsErrorsSuite
| assert(e.getMessage.contains("Invalid arguments for function cast")) | ||
| checkError( | ||
| exception = intercept[AnalysisException] { | ||
| sql("SELECT CAST(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.
The code above is not correct actually in some cases. One more example is TimestampAdd:
Lines 3156 to 3159 in a3a755d
| case class TimestampAdd( | |
| unit: String, | |
| quantity: Expression, | |
| timestamp: Expression, |
| ], | ||
| "sqlState" : "22023" | ||
| }, | ||
| "INVALID_FUNCTION_ARGS" : { |
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.
How about to introduce sub-classes of WRONG_NUM_ARGS:
- WITHOUT_SUGGESTION
- WITH_SUGGESTION
And declare in the common message template that
Invalid number of arguments for the function <funcName>.
_LEGACY_ERROR_TEMP_1043 to INVALID_FUNCTION_ARGS_LEGACY_ERROR_TEMP_1043 to WRONG_NUM_ARGS.WITHOUT_SUGGESTION
| "messageParameters" : { | ||
| "arguments" : "integer, integer, integer, integer, integer", | ||
| "details" : "[WRONG_NUM_ARGS] The `range` requires [1, 2, 3, 4] parameters but the actual number is 5.", | ||
| "details" : "[WRONG_NUM_ARGS.WITH_SUGGESTION] Invalid number of arguments for the function `range`. The function requires [1, 2, 3, 4] parameters but the actual number is 5.", |
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.
I think we should bypass the error. Could you open an separate PR and check if the exception is SparkThrowable then re-throw it, please.
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.
Co-authored-by: Maxim Gekk <[email protected]>
Co-authored-by: Maxim Gekk <[email protected]>
MaxGekk
left a comment
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.
Waiting for CI.
|
GA passed |
|
+1, LGTM. Merging to master. |
|
Thanks @MaxGekk |
…UM_ARGS.WITHOUT_SUGGESTION` ### What changes were proposed in this pull request? This pr introduces sub-classes of `WRONG_NUM_ARGS`: - WITHOUT_SUGGESTION - WITH_SUGGESTION then replace existing `WRONG_NUM_ARGS` to `WRONG_NUM_ARGS.WITH_SUGGESTION` and rename error class `_LEGACY_ERROR_TEMP_1043` to `WRONG_NUM_ARGS.WITHOUT_SUGGESTION` ### Why are the changes needed? Proper names of error classes to improve user experience with Spark SQL. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Add new test case Closes apache#38940 from LuciferYang/legacy-1043. Lead-authored-by: yangjie01 <[email protected]> Co-authored-by: YangJie <[email protected]> Signed-off-by: Max Gekk <[email protected]>
What changes were proposed in this pull request?
This pr introduces sub-classes of
WRONG_NUM_ARGS:then replace existing
WRONG_NUM_ARGStoWRONG_NUM_ARGS.WITH_SUGGESTIONand rename error class_LEGACY_ERROR_TEMP_1043toWRONG_NUM_ARGS.WITHOUT_SUGGESTIONWhy are the changes needed?
Proper names of error classes to improve user experience with Spark SQL.
Does this PR introduce any user-facing change?
No
How was this patch tested?
Add new test case