herunkang2018 commented on code in PR #3318: URL: https://github.com/apache/calcite/pull/3318#discussion_r1334901753
########## core/src/main/java/org/apache/calcite/runtime/UrlFunctions.java: ########## @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.calcite.runtime; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import static org.apache.calcite.util.Static.RESOURCE; + +/** + * A collection of functions used in Url processing. + */ +public class UrlFunctions { + + private UrlFunctions() { + } + + private static final Charset UTF_8 = StandardCharsets.UTF_8; + + /** The "URL_DECODE(string)" function. */ + public static String urlDecode(String value) { + String url; + try { + url = URLDecoder.decode(value, UTF_8.name()); + } catch (UnsupportedEncodingException e) { Review Comment: Thanks for remind. `RuntimeException` is not need to explicitly throw, so easy to forget to handle it. I check the`RuntimeException` in `URLDecoder.decode`, there will be `IllegalArgumentException` when encounter the unencoded `%`. The next I will do are two things: 1. Keep current exception handling way. Since `IllegalArgumentException` exception messages are very diverse, I think that not handling with it explicitly here is reasonable, and just throws `IllegalArgumentException` when it encountered. 2. Add exception test cases to cover `IllegalArgumentException`. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
