Skip to content

Commit 62bf87f

Browse files
committed
init
1 parent 9283484 commit 62bf87f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,10 @@ case class ParseUrl(children: Seq[Expression])
14041404
try {
14051405
new URI(url.toString)
14061406
} catch {
1407-
case e: URISyntaxException => null
1407+
// We fail on error if in ansi mode.
1408+
case e: URISyntaxException if SQLConf.get.ansiEnabled =>
1409+
throw new IllegalArgumentException(s"Find an invaild url string ${url.toString}", e)
1410+
case _: URISyntaxException => null
14081411
}
14091412
}
14101413

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/StringExpressionsSuite.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,21 @@ class StringExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
943943
GenerateUnsafeProjection.generate(ParseUrl(Seq(Literal("\"quote"), Literal("\"quote"))) :: Nil)
944944
}
945945

946+
test("SPARK-33468: ParseUrl should fail if input string is not a valid url") {
947+
// fail on error if in ansi mode.
948+
withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
949+
val msg = intercept[IllegalArgumentException] {
950+
evaluateWithoutCodegen(
951+
ParseUrl(Seq("https://a.b.c/index.php?params1=a|b&params2=x", "HOST")))
952+
}.getMessage
953+
assert(msg.contains("Find an invaild url string"))
954+
}
955+
withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
956+
checkEvaluation(
957+
ParseUrl(Seq("https://a.b.c/index.php?params1=a|b&params2=x", "HOST")), null)
958+
}
959+
}
960+
946961
test("Sentences") {
947962
val nullString = Literal.create(null, StringType)
948963
checkEvaluation(Sentences(nullString, nullString, nullString), null)

0 commit comments

Comments
 (0)