You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/01/13 17:10:50 UTC

[GitHub] [flink] twalthr commented on a change in pull request #18352: [FLINK-15585][table] Improve function identifier string in plan digest

twalthr commented on a change in pull request #18352:
URL: https://github.com/apache/flink/pull/18352#discussion_r784159595



##########
File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/UserDefinedFunctionHelper.java
##########
@@ -243,6 +244,36 @@ public static void prepareInstance(ReadableConfig config, UserDefinedFunction fu
         cleanFunction(config, function);
     }
 
+    /**
+     * Returns whether a {@link UserDefinedFunction} can be easily serialized and identified by only
+     * a fully qualified class name. It must have a default constructor and no serializable fields.
+     */
+    public static boolean isClassNameSerializable(UserDefinedFunction function) {
+        final Class<?> functionClass = function.getClass();
+        if (!InstantiationUtil.hasPublicNullaryConstructor(functionClass)) {
+            // function must be parameterized
+            return false;
+        }
+        Class<?> currentClass = functionClass;
+        while (!currentClass.equals(UserDefinedFunction.class)) {
+            for (Field field : currentClass.getDeclaredFields()) {
+                if (!Modifier.isTransient(field.getModifiers())
+                        && !Modifier.isStatic(field.getModifiers())) {
+                    // function seems to be stateful
+                    return false;
+                }
+            }
+            currentClass = currentClass.getSuperclass();
+        }

Review comment:
       Even with a marker interface you need perform this check. User-defined function might come in various flavors. And the more interfaces, the harder it gets to get the job done.




-- 
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-unsubscribe@flink.apache.org

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