-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-16826][SQL] Switch to java.net.URI for parse_url() #14488
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| package org.apache.spark.sql.catalyst.expressions | ||
|
|
||
| import java.net.{MalformedURLException, URL} | ||
| import java.net.{URI, URISyntaxException} | ||
| import java.text.{BreakIterator, DecimalFormat, DecimalFormatSymbols} | ||
| import java.util.{HashMap, Locale, Map => JMap} | ||
| import java.util.regex.Pattern | ||
|
|
@@ -749,25 +749,44 @@ case class ParseUrl(children: Seq[Expression]) | |
| Pattern.compile(REGEXPREFIX + key.toString + REGEXSUBFIX) | ||
| } | ||
|
|
||
| private def getUrl(url: UTF8String): URL = { | ||
| private def getUrl(url: UTF8String): URI = { | ||
| try { | ||
| new URL(url.toString) | ||
| new URI(url.toString) | ||
| } catch { | ||
| case e: MalformedURLException => null | ||
| case e: URISyntaxException => null | ||
| } | ||
| } | ||
|
|
||
| private def getExtractPartFunc(partToExtract: UTF8String): URL => String = { | ||
| private def getExtractPartFunc(partToExtract: UTF8String): URI => String = { | ||
|
|
||
| // partToExtract match { | ||
| // case HOST => _.toURL().getHost | ||
| // case PATH => _.toURL().getPath | ||
| // case QUERY => _.toURL().getQuery | ||
| // case REF => _.toURL().getRef | ||
| // case PROTOCOL => _.toURL().getProtocol | ||
| // case FILE => _.toURL().getFile | ||
| // case AUTHORITY => _.toURL().getAuthority | ||
| // case USERINFO => _.toURL().getUserInfo | ||
| // case _ => (url: URI) => null | ||
| // } | ||
|
|
||
| partToExtract match { | ||
| case HOST => _.getHost | ||
| case PATH => _.getPath | ||
| case QUERY => _.getQuery | ||
| case REF => _.getRef | ||
| case PROTOCOL => _.getProtocol | ||
| case FILE => _.getFile | ||
| case AUTHORITY => _.getAuthority | ||
| case USERINFO => _.getUserInfo | ||
| case _ => (url: URL) => null | ||
| case PATH => _.getRawPath | ||
| case QUERY => _.getRawQuery | ||
| case REF => _.getRawFragment | ||
| case PROTOCOL => _.getScheme | ||
| case FILE => | ||
| (url: URI) => | ||
| if (url.getRawQuery ne null) { | ||
|
Member
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. We really need the 'raw' elements in each of these? I'd think they need to be parsed. Your tests show this code not parsing escapes. Is that how it behaved before? then OK.
Contributor
Author
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. It does seem so: |
||
| url.getRawPath + "?" + url.getRawQuery | ||
| } else { | ||
| url.getRawPath | ||
| } | ||
| case AUTHORITY => _.getRawAuthority | ||
| case USERINFO => _.getRawUserInfo | ||
| case _ => (url: URI) => null | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -780,7 +799,7 @@ case class ParseUrl(children: Seq[Expression]) | |
| } | ||
| } | ||
|
|
||
| private def extractFromUrl(url: URL, partToExtract: UTF8String): UTF8String = { | ||
| private def extractFromUrl(url: URI, partToExtract: UTF8String): UTF8String = { | ||
| if (cachedExtractPartFunc ne null) { | ||
| UTF8String.fromString(cachedExtractPartFunc.apply(url)) | ||
| } else { | ||
|
|
||
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.
Don't change this unless you need to make another change anyway, but this can be
case _: ...I know it wasn't like that before