Skip to content

Commit

Permalink
[FLINK-36503][table] Remove deprecated method FunctionDefinitionFacto…
Browse files Browse the repository at this point in the history
…ry#createFunctionDefinition
  • Loading branch information
xuyangzhong committed Jan 14, 2025
1 parent 4a6f84b commit 6de4d92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,23 @@
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.table.catalog.CatalogFunction;
import org.apache.flink.table.functions.FunctionDefinition;
import org.apache.flink.util.TemporaryClassLoaderContext;

/** A factory to create {@link FunctionDefinition}. */
@PublicEvolving
public interface FunctionDefinitionFactory {

/**
* Creates a {@link FunctionDefinition} from given {@link CatalogFunction}.
*
* @param name name of the {@link CatalogFunction}
* @param catalogFunction the catalog function
* @return a {@link FunctionDefinition}
* @deprecated Please implement {@link #createFunctionDefinition(String, CatalogFunction,
* Context)} instead.
*/
@Deprecated
default FunctionDefinition createFunctionDefinition(
String name, CatalogFunction catalogFunction) {
throw new RuntimeException(
"Please implement FunctionDefinitionFactory#createFunctionDefinition(String, CatalogFunction, Context) instead.");
}

/**
* Creates a {@link FunctionDefinition} from given {@link CatalogFunction} with the given {@link
* Context} containing the class loader of the current session, which is useful when it's needed
* to load class from class name.
*
* <p>The default implementation will call {@link #createFunctionDefinition(String,
* CatalogFunction)} directly.
*
* @param name name of the {@link CatalogFunction}
* @param catalogFunction the catalog function
* @param context the {@link Context} for creating function definition
* @return a {@link FunctionDefinition}
*/
default FunctionDefinition createFunctionDefinition(
String name, CatalogFunction catalogFunction, Context context) {
try (TemporaryClassLoaderContext ignored =
TemporaryClassLoaderContext.of(context.getClassLoader())) {
return createFunctionDefinition(name, catalogFunction);
}
}
FunctionDefinition createFunctionDefinition(
String name, CatalogFunction catalogFunction, Context context);

/** Context provided when a function definition is created. */
@PublicEvolving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

/**
* Use TestFunctionDefinitionFactory to test loading function to ensure the function can be loaded
* correctly if only implement legacy interface {@link
* FunctionDefinitionFactory#createFunctionDefinition(String, CatalogFunction)}.
* correctly with the classloader provided by {@link Context}.
*/
public class TestFunctionDefinitionFactory implements FunctionDefinitionFactory {

@Override
public FunctionDefinition createFunctionDefinition(
String name, CatalogFunction catalogFunction) {
String name, CatalogFunction catalogFunction, Context context) {
return UserDefinedFunctionHelper.instantiateFunction(
Thread.currentThread().getContextClassLoader(), null, name, catalogFunction);
context.getClassLoader(), null, name, catalogFunction);
}
}

0 comments on commit 6de4d92

Please sign in to comment.