dylanhz commented on code in PR #27351:
URL: https://github.com/apache/flink/pull/27351#discussion_r2919694728
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/UrlDecodeFunction.java:
##########
@@ -30,22 +31,78 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
-/** Implementation of {@link BuiltInFunctionDefinitions#URL_DECODE}. */
+/**
+ * Implementation of {@link BuiltInFunctionDefinitions#URL_DECODE} and {@link
+ * BuiltInFunctionDefinitions#URL_DECODE_RECURSIVE}.
+ */
@Internal
public class UrlDecodeFunction extends BuiltInScalarFunction {
+ private static final int DEFAULT_MAX_DECODE_DEPTH = 10;
+
+ private final boolean recursive;
+
public UrlDecodeFunction(SpecializedFunction.SpecializedContext context) {
- super(BuiltInFunctionDefinitions.URL_DECODE, context);
+ super(resolveDefinition(context), context);
+ this.recursive =
+ resolveDefinition(context) ==
BuiltInFunctionDefinitions.URL_DECODE_RECURSIVE;
+ }
+
+ private static BuiltInFunctionDefinition resolveDefinition(
+ SpecializedFunction.SpecializedContext context) {
+ if (context.getCallContext()
+ .getFunctionDefinition()
+ .equals(BuiltInFunctionDefinitions.URL_DECODE_RECURSIVE)) {
+ return BuiltInFunctionDefinitions.URL_DECODE_RECURSIVE;
+ }
+ return BuiltInFunctionDefinitions.URL_DECODE;
}
public @Nullable StringData eval(StringData value) {
if (value == null) {
return null;
}
final Charset charset = StandardCharsets.UTF_8;
+ if (!recursive) {
+ try {
+ return
StringData.fromString(URLDecoder.decode(value.toString(), charset.name()));
+ } catch (UnsupportedEncodingException | RuntimeException e) {
+ return null;
+ }
+ }
+
+ // Recursive with default max depth
+ return eval(value, DEFAULT_MAX_DECODE_DEPTH);
+ }
+
+ public @Nullable StringData eval(StringData value, Integer maxDepth) {
Review Comment:
What if input is `TINYINT/SMALLINT/BIGINT`?
--
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]