Skip to content
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

[SPARK-48806][SQL] Pass actual exception when url_decode fails #47211

Closed
wants to merge 2 commits into from
Closed
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 @@ -116,7 +116,7 @@ object UrlCodec {
UTF8String.fromString(URLDecoder.decode(src.toString, enc.toString))
} catch {
case e: IllegalArgumentException =>
throw QueryExecutionErrors.illegalUrlError(src)
throw QueryExecutionErrors.illegalUrlError(src, e)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,11 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
cause = e)
}

def illegalUrlError(url: UTF8String): Throwable = {
def illegalUrlError(url: UTF8String, e: IllegalArgumentException): Throwable = {
new SparkIllegalArgumentException(
errorClass = "CANNOT_DECODE_URL",
messageParameters = Map("url" -> url.toString)
messageParameters = Map("url" -> url.toString),
cause = e
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.spark.sql

import org.apache.spark.{SPARK_DOC_ROOT, SparkRuntimeException}
import org.apache.spark.{SPARK_DOC_ROOT, SparkIllegalArgumentException, SparkRuntimeException}
import org.apache.spark.sql.catalyst.expressions.Cast._
import org.apache.spark.sql.execution.FormattedMode
import org.apache.spark.sql.functions._
Expand Down Expand Up @@ -1273,4 +1273,13 @@ class StringFunctionsSuite extends QueryTest with SharedSparkSession {
)
)
}

test("SPARK-48806: url_decode exception") {
val e = intercept[SparkIllegalArgumentException] {
sql("select url_decode('https%3A%2F%2spark.apache.org')").collect()
}
assert(e.getCause.isInstanceOf[IllegalArgumentException] &&
e.getCause.getMessage
.startsWith("URLDecoder: Illegal hex characters in escape (%) pattern - "))
}
}