davidradl commented on code in PR #24773:
URL: https://github.com/apache/flink/pull/24773#discussion_r1611921523


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/UrlDecodeFunction.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.flink.table.runtime.functions.scalar;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.functions.SpecializedFunction;
+
+import javax.annotation.Nullable;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+/** Implementation of {@link BuiltInFunctionDefinitions#URL_DECODE}. */
+@Internal
+public class UrlDecodeFunction extends BuiltInScalarFunction {
+
+    public UrlDecodeFunction(SpecializedFunction.SpecializedContext context) {
+        super(BuiltInFunctionDefinitions.URL_DECODE, context);
+    }
+
+    public @Nullable StringData eval(StringData value) {
+        final Charset charset = StandardCharsets.UTF_8;
+        try {
+            return StringData.fromString(URLDecoder.decode(value.toString(), 
charset.name()));
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(
+                    "Failed to decode value: " + value + " with charset: " + 
charset.name(), e);
+        } catch (RuntimeException e) {
+            return value;
+        }

Review Comment:
   @snuyanzin @MartijnVisser thankyou very much for your feedback.
   
   Sergey:
   Sorry if I was not clear, I did not mean to imply that JAVA runtime 
Exceptions and errors are the same.  
   you ask `How are you going to even detect this row with such behavior?` I 
guess this is not possible for the cast, if we had an error message that 
included the string that we fails to encode or decode - this could help. 
   
   For the null pointer- I was not thinking of a java NullPointerException, 
just an unexpected null in subsequent processing,  maybe if this value ended up 
being attempted to be written to a non nullable column. 
   Martjin:
   I like your examples of cast and try_cast that was helpful for me. In 
addition to element (which does not look like a runtime exception) there are 
also json functions that produce errors (these also do not look like runtime 
errors).
   
   It seems to me if we can produce a useful error message in the error 
including the string we could not encode / decode then this could be very 
helpful to be able to diagnose the issue. If not then returning null looks 
preferable. Either way I think we should log the runtime error.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to