-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-50031][SQL] Add the TryParseUrl
expression
#48500
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4656fbd
Add try_parse_url expression
jovanm-db fbc201b
Fix errors
jovanm-db f49745a
Fix formatting
jovanm-db 5793bff
Fix formatting
jovanm-db 3122ac6
Add tests
jovanm-db a2a1e8c
Fix test and formatting
jovanm-db 5071226
Revert changes and split tasks into a new ticket
jovanm-db 470f446
Merge branch 'apache:master' into invalidUrl
jovanm-db 9f2ccc6
Fix test and docs
jovanm-db 3513600
Fix docs
jovanm-db 6656eaa
Fix docs
jovanm-db 5434b30
Fix lint
jovanm-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,6 +587,7 @@ URL Functions | |
:toctree: api/ | ||
|
||
parse_url | ||
try_parse_url | ||
url_decode | ||
url_encode | ||
try_url_decode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,6 +333,20 @@ def test_rand_functions(self): | |
rndn2 = df.select("key", F.randn(0)).collect() | ||
self.assertEqual(sorted(rndn1), sorted(rndn2)) | ||
|
||
def test_try_parse_url(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we also add a case here that returns null? This is to make sure python works as well with invalid urls. |
||
df = self.spark.createDataFrame( | ||
[("https://spark.apache.org/path?query=1", "QUERY", "query")], | ||
["url", "part", "key"], | ||
) | ||
actual = df.select(F.try_parse_url(df.url, df.part, df.key)).collect() | ||
self.assertEqual(actual, [Row("1")]) | ||
df = self.spark.createDataFrame( | ||
[("inva lid://spark.apache.org/path?query=1", "QUERY", "query")], | ||
["url", "part", "key"], | ||
) | ||
actual = df.select(F.try_parse_url(df.url, df.part, df.key)).collect() | ||
self.assertEqual(actual, [Row(None)]) | ||
|
||
def test_string_functions(self): | ||
string_functions = [ | ||
"upper", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,50 @@ class UrlFunctionsSuite extends QueryTest with SharedSparkSession { | |
} | ||
} | ||
|
||
test("url try_parse_url function") { | ||
|
||
def testUrl(url: String, expected: Row): Unit = { | ||
checkAnswer(Seq[String]((url)).toDF("url").selectExpr( | ||
"try_parse_url(url, 'HOST')", "try_parse_url(url, 'PATH')", | ||
"try_parse_url(url, 'QUERY')", "try_parse_url(url, 'REF')", | ||
"try_parse_url(url, 'PROTOCOL')", "try_parse_url(url, 'FILE')", | ||
"try_parse_url(url, 'AUTHORITY')", "try_parse_url(url, 'USERINFO')", | ||
"try_parse_url(url, 'QUERY', 'query')"), expected) | ||
} | ||
|
||
testUrl( | ||
"http://[email protected]/path?query=1#Ref", | ||
Row("spark.apache.org", "/path", "query=1", "Ref", | ||
"http", "/path?query=1", "[email protected]", "userinfo", "1")) | ||
|
||
testUrl( | ||
"https://use%20r:pas%[email protected]/dir%20/pa%20th.HTML?query=x%20y&q2=2#Ref%20two", | ||
Row("example.com", "/dir%20/pa%20th.HTML", "query=x%20y&q2=2", "Ref%20two", | ||
"https", "/dir%20/pa%20th.HTML?query=x%20y&q2=2", "use%20r:pas%[email protected]", | ||
"use%20r:pas%20s", "x%20y")) | ||
|
||
testUrl( | ||
"http://user:pass@host", | ||
Row("host", "", null, null, "http", "", "user:pass@host", "user:pass", null)) | ||
|
||
testUrl( | ||
"http://user:pass@host/", | ||
Row("host", "/", null, null, "http", "/", "user:pass@host", "user:pass", null)) | ||
|
||
testUrl( | ||
"http://user:pass@host/?#", | ||
Row("host", "/", "", "", "http", "/?", "user:pass@host", "user:pass", null)) | ||
|
||
testUrl( | ||
"http://user:pass@host/file;param?query;p2", | ||
Row("host", "/file;param", "query;p2", null, "http", "/file;param?query;p2", | ||
"user:pass@host", "user:pass", null)) | ||
|
||
testUrl( | ||
"inva lid://user:pass@host/file;param?query;p2", | ||
Row(null, null, null, null, null, null, null, null, null)) | ||
} | ||
|
||
test("url encode/decode function") { | ||
def testUrl(url: String, fn: String, expected: Row): Unit = { | ||
checkAnswer(Seq[String]((url)).toDF("url") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a one unittest in, e.g., test_functions.py? then the tests will be resued in both Spark connect and classic.