slinkydeveloper commented on a change in pull request #18352:
URL: https://github.com/apache/flink/pull/18352#discussion_r784638813
##########
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:
It is, but on the other hand this is very magic and very hard as a
behavior to predict for the users. I would rather have this kind of logic
enabled behind a flag and default to "if you wanna implement a stateful
function, mark it as such with this interface"
--
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]