Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions docs/sql-ref-ansi-compliance.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ The behavior of some SQL functions can be different under ANSI mode (`spark.sql.
- `element_at`: This function throws `ArrayIndexOutOfBoundsException` if using invalid indices.
- `element_at`: This function throws `NoSuchElementException` if key does not exist in map.
- `elt`: This function throws `ArrayIndexOutOfBoundsException` if using invalid indices.
- `parse_url`: This function throws `IllegalArgumentException` if input string is not a valid url.
Copy link
Member

Choose a reason for hiding this comment

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

nit: input string -> an input string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry missed here. Updated !


### SQL Operators

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,9 @@ case class ParseUrl(children: Seq[Expression])
try {
new URI(url.toString)
} catch {
case e: URISyntaxException => null
case e: URISyntaxException if SQLConf.get.ansiEnabled =>
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed here, updated !

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we follow other expressions and add a failOnError: Boolean parameter? See #30297 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get it !

throw new IllegalArgumentException(s"Find an invaild url string ${url.toString}", e)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To clarify, the raw exception message is something like Illegal character in query at index 33: https://a.b.c/index.php?params1=a|b&params2=x.

case _: URISyntaxException => null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,20 @@ class StringExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
GenerateUnsafeProjection.generate(ParseUrl(Seq(Literal("\"quote"), Literal("\"quote"))) :: Nil)
}

test("SPARK-33468: ParseUrl in ANSI mode should fail if input string is not a valid url") {
withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
val msg = intercept[IllegalArgumentException] {
evaluateWithoutCodegen(
ParseUrl(Seq("https://a.b.c/index.php?params1=a|b&params2=x", "HOST")))
}.getMessage
assert(msg.contains("Find an invaild url string"))
}
withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
checkEvaluation(
ParseUrl(Seq("https://a.b.c/index.php?params1=a|b&params2=x", "HOST")), null)
}
}

test("Sentences") {
val nullString = Literal.create(null, StringType)
checkEvaluation(Sentences(nullString, nullString, nullString), null)
Expand Down