You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "herunkang2018 (via GitHub)" <gi...@apache.org> on 2023/07/10 23:58:17 UTC
[GitHub] [calcite] herunkang2018 commented on a diff in pull request #3300: [CALCITE-5820] Add PARSE_URL function (enabled in Hive and Spark library)
herunkang2018 commented on code in PR #3300:
URL: https://github.com/apache/calcite/pull/3300#discussion_r1259018434
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -875,6 +878,70 @@ public static String translateWithCharset(String s, String transcodingName) {
}
}
+ /** SQL {@code PARSE_URL(urlStr, partToExtract [, keyToExtract])} function. */
+ public static @Nullable String parseUrl(@Nullable String urlStr,
+ @Nullable String partToExtract) {
+ if (urlStr == null || partToExtract == null) {
+ return null;
+ }
+
+ URI uri;
+ try {
+ uri = new URI(urlStr);
+ } catch (URISyntaxException e) {
+ return null;
+ }
+
+ if (partToExtract.equals("HOST")) {
+ return uri.getHost();
+ }
+ if (partToExtract.equals("PATH")) {
+ return uri.getRawPath();
+ }
+ if (partToExtract.equals("QUERY")) {
+ return uri.getRawQuery();
+ }
+ if (partToExtract.equals("REF")) {
+ return uri.getRawFragment();
+ }
+ if (partToExtract.equals("PROTOCOL")) {
+ return uri.getScheme();
+ }
+ if (partToExtract.equals("FILE")) {
+ if (uri.getRawQuery() != null) {
+ return uri.getRawPath() + "?" + uri.getRawQuery();
+ }
+ return uri.getRawPath();
+ }
+ if (partToExtract.equals("AUTHORITY")) {
+ return uri.getRawAuthority();
+ }
+ if (partToExtract.equals("USERINFO")) {
+ return uri.getRawUserInfo();
+ }
+
+ return null;
+ }
+
+ public static @Nullable String parseUrl(@Nullable String urlStr,
+ @Nullable String partToExtract, @Nullable String keyToExtract) {
+ if (!partToExtract.equals("QUERY")) {
Review Comment:
I will fix it soon.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org