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-33468][SQL] ParseUrl in ANSI mode should fail if input string is not a valid url #30399

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -1404,7 +1404,10 @@ case class ParseUrl(children: Seq[Expression])
try {
new URI(url.toString)
} catch {
case e: URISyntaxException => null
// We fail on error if in ansi mode.
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this comment.

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,21 @@ class StringExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
GenerateUnsafeProjection.generate(ParseUrl(Seq(Literal("\"quote"), Literal("\"quote"))) :: Nil)
}

test("SPARK-33468: ParseUrl should fail 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.

ParseUrl -> ParseUrl in ANSI mode?

// fail on error if in ansi mode.
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this.

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