Skip to content

Conversation

@LuciferYang
Copy link
Contributor

@LuciferYang LuciferYang commented Dec 6, 2022

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

@LuciferYang LuciferYang marked this pull request as draft December 6, 2022 15:41
@LuciferYang LuciferYang changed the title [SPARK-41409][CORE][SQL] Reuse WRONG_NUM_ARGS instead of _LEGACY_ERROR_TEMP_1043 [WIP][SPARK-41409][CORE][SQL] Reuse WRONG_NUM_ARGS instead of _LEGACY_ERROR_TEMP_1043 Dec 7, 2022
@LuciferYang LuciferYang changed the title [WIP][SPARK-41409][CORE][SQL] Reuse WRONG_NUM_ARGS instead of _LEGACY_ERROR_TEMP_1043 [WIP][SPARK-41409][CORE][SQL] Rename _LEGACY_ERROR_TEMP_1043 to INVALID_FUNCTION_ARGS Dec 7, 2022
assert(e.getMessage.contains("Invalid arguments for function cast"))
checkError(
exception = intercept[AnalysisException] {
sql("SELECT CAST(1)")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

// 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

Copy link
Contributor Author

@LuciferYang LuciferYang Dec 7, 2022

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 ?

Copy link
Member

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:

case class TimestampAdd(
unit: String,
quantity: Expression,
timestamp: Expression,

@LuciferYang LuciferYang changed the title [WIP][SPARK-41409][CORE][SQL] Rename _LEGACY_ERROR_TEMP_1043 to INVALID_FUNCTION_ARGS [SPARK-41409][CORE][SQL] Rename _LEGACY_ERROR_TEMP_1043 to INVALID_FUNCTION_ARGS Dec 7, 2022
new AnalysisException(
errorClass = "_LEGACY_ERROR_TEMP_1043",
messageParameters = Map("name" -> name))
errorClass = "INVALID_FUNCTION_ARGS",
Copy link
Contributor Author

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?

Copy link
Contributor Author

@LuciferYang LuciferYang Dec 8, 2022

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)") {
Copy link
Member

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)")
Copy link
Member

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:

case class TimestampAdd(
unit: String,
quantity: Expression,
timestamp: Expression,

],
"sqlState" : "22023"
},
"INVALID_FUNCTION_ARGS" : {
Copy link
Member

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>.

@LuciferYang LuciferYang changed the title [SPARK-41409][CORE][SQL] Rename _LEGACY_ERROR_TEMP_1043 to INVALID_FUNCTION_ARGS [SPARK-41409][CORE][SQL] Rename _LEGACY_ERROR_TEMP_1043 to WRONG_NUM_ARGS.WITHOUT_SUGGESTION Dec 13, 2022
@LuciferYang LuciferYang marked this pull request as ready for review December 13, 2022 06:12
"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.",
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@MaxGekk MaxGekk left a comment

Choose a reason for hiding this comment

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

Waiting for CI.

@LuciferYang
Copy link
Contributor Author

GA passed

@MaxGekk
Copy link
Member

MaxGekk commented Dec 14, 2022

+1, LGTM. Merging to master.
Thank you, @LuciferYang.

@MaxGekk MaxGekk closed this in 4e8980e Dec 14, 2022
@LuciferYang
Copy link
Contributor Author

Thanks @MaxGekk

beliefer pushed a commit to beliefer/spark that referenced this pull request Dec 18, 2022
…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]>
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.

2 participants