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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]