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



##########
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:
       I'm also against magic but in this case the magic is minimal. It only 
influences a plan digest and makes it more deterministic. Most users don't 
parameterize their functions anyway and/or register it under a name which makes 
them non-anonymous anyway.




-- 
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]


Reply via email to