Skip to content

Commit 6e8573a

Browse files
committed
[SPARK-48806] Pass actual exception when url_decode fails
1 parent 257a788 commit 6e8573a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/urlExpressions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ object UrlCodec {
116116
UTF8String.fromString(URLDecoder.decode(src.toString, enc.toString))
117117
} catch {
118118
case e: IllegalArgumentException =>
119-
throw QueryExecutionErrors.illegalUrlError(src)
119+
throw QueryExecutionErrors.illegalUrlError(src, e)
120120
}
121121
}
122122
}

sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,11 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
365365
cause = e)
366366
}
367367

368-
def illegalUrlError(url: UTF8String): Throwable = {
368+
def illegalUrlError(url: UTF8String, e: IllegalArgumentException): Throwable = {
369369
new SparkIllegalArgumentException(
370370
errorClass = "CANNOT_DECODE_URL",
371-
messageParameters = Map("url" -> url.toString)
371+
messageParameters = Map("url" -> url.toString),
372+
cause = e
372373
)
373374
}
374375

sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark.sql
1919

20-
import org.apache.spark.{SPARK_DOC_ROOT, SparkRuntimeException}
20+
import org.apache.spark.{SPARK_DOC_ROOT, SparkIllegalArgumentException, SparkRuntimeException}
2121
import org.apache.spark.sql.catalyst.expressions.Cast._
2222
import org.apache.spark.sql.execution.FormattedMode
2323
import org.apache.spark.sql.functions._
@@ -1273,4 +1273,14 @@ class StringFunctionsSuite extends QueryTest with SharedSparkSession {
12731273
)
12741274
)
12751275
}
1276+
1277+
test("url_decode exception") {
1278+
val e = intercept[SparkIllegalArgumentException] {
1279+
sql("select url_decode('https%3A%2F%2spark.apache.org')").collect()
1280+
}
1281+
e.printStackTrace()
1282+
assert(e.getCause.isInstanceOf[IllegalArgumentException] &&
1283+
e.getCause.getMessage
1284+
.startsWith("URLDecoder: Illegal hex characters in escape (%) pattern - "))
1285+
}
12761286
}

0 commit comments

Comments
 (0)