Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ case class RaiseError(errorClass: Expression, errorParms: Expression, dataType:

override def prettyName: String = "raise_error"

override def sql: String = {
// When constructed from the single-argument form (just an error message string),
// output only the original message to produce valid, roundtrippable SQL.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shall we check the errorClass as well? to be _LEGACY_ERROR_USER_RAISED_EXCEPTION or USER_RAISED_EXCEPTION

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed and tests are re-run:

image

(errorClass, errorParms) match {
case (Literal(cls, _), CreateMap(Seq(Literal(key, _), msg), _))
if cls != null &&
(cls.toString == "USER_RAISED_EXCEPTION" ||
cls.toString == "_LEGACY_ERROR_USER_RAISED_EXCEPTION") &&
key != null && key.toString == "errorMessage" =>
s"$prettyName(${msg.sql})"
case _ =>
super.sql
}
}

override def eval(input: InternalRow): Any = {
val error = errorClass.eval(input).asInstanceOf[UTF8String]
val parms: MapData = errorParms.eval(input).asInstanceOf[MapData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ class MiscExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
)
}

test("SPARK-55109: RaiseError.sql uses single-argument form only for known error classes") {
assert(RaiseError(Literal("error!")).sql === "raise_error('error!')")

// A custom errorClass should NOT produce the single-argument form
val customError = RaiseError(
Literal("CUSTOM_ERROR"),
CreateMap(Seq(Literal("errorMessage"), Literal("error!"))))
assert(customError.sql === "raise_error('CUSTOM_ERROR', map('errorMessage', 'error!'))")
}

test("uuid") {
checkEvaluation(Length(Uuid(Some(0))), 36)
val r = new Random()
Expand Down