You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by sh...@apache.org on 2025/05/26 11:54:07 UTC

(flink) branch master updated: [FLINK-37849][table] Support model provider factory discovery (#26596)

This is an automated email from the ASF dual-hosted git repository.

shengkai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new 1863d242ccb [FLINK-37849][table] Support model provider factory discovery (#26596)
1863d242ccb is described below

commit 1863d242ccb9807417cf6bac9794d03843e2bc14
Author: Hao Li <11...@users.noreply.github.com>
AuthorDate: Mon May 26 04:54:01 2025 -0700

    [FLINK-37849][table] Support model provider factory discovery (#26596)
---
 .../apache/flink/table/factories/FactoryUtil.java  | 139 +++++++++++++++++++
 .../table/factories/ModelProviderFactory.java      |   2 +-
 .../flink/table/factories/FactoryUtilTest.java     | 147 +++++++++++++++++++++
 .../TestConflictingModelProviderFactory1.java      |  51 +++++++
 .../TestConflictingModelProviderFactory2.java      |  49 +++++++
 .../table/factories/TestModelProviderFactory.java  | 106 +++++++++++++++
 .../flink/table/factories/utils/FactoryMocks.java  |  45 +++++++
 .../org.apache.flink.table.factories.Factory       |   3 +
 8 files changed, 541 insertions(+), 1 deletion(-)

diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/FactoryUtil.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/FactoryUtil.java
index e443bf186c7..691397c08d4 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/FactoryUtil.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/FactoryUtil.java
@@ -33,12 +33,14 @@ import org.apache.flink.table.catalog.Catalog;
 import org.apache.flink.table.catalog.CatalogTable;
 import org.apache.flink.table.catalog.CommonCatalogOptions;
 import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ResolvedCatalogModel;
 import org.apache.flink.table.catalog.ResolvedCatalogTable;
 import org.apache.flink.table.connector.format.DecodingFormat;
 import org.apache.flink.table.connector.format.EncodingFormat;
 import org.apache.flink.table.connector.sink.DynamicTableSink;
 import org.apache.flink.table.connector.source.DynamicTableSource;
 import org.apache.flink.table.legacy.factories.TableFactory;
+import org.apache.flink.table.ml.ModelProvider;
 import org.apache.flink.table.module.Module;
 import org.apache.flink.table.utils.EncodingUtils;
 import org.apache.flink.table.watermark.WatermarkEmitStrategy;
@@ -95,6 +97,14 @@ public final class FactoryUtil {
                             "Uniquely identifies the connector of a dynamic table that is used for accessing data in "
                                     + "an external system. Its value is used during table source and table sink discovery.");
 
+    public static final ConfigOption<String> PROVIDER =
+            ConfigOptions.key("provider")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Uniquely identifies the provider of a model that is used for model inference."
+                                    + " Its value is used during model provider discovery.");
+
     public static final ConfigOption<String> FORMAT =
             ConfigOptions.key("format")
                     .stringType()
@@ -290,6 +300,46 @@ public final class FactoryUtil {
         }
     }
 
+    /**
+     * Creates a {@link ModelProvider} from a {@link ResolvedCatalogModel}.
+     *
+     * <p>If {@param preferredFactory} is passed, the model provider is created from that factory.
+     * Otherwise, an attempt is made to discover a matching factory using Java SPI (see {@link
+     * Factory} for details).
+     */
+    public static ModelProvider createModelProvider(
+            @Nullable ModelProviderFactory preferredFactory,
+            ObjectIdentifier objectIdentifier,
+            ResolvedCatalogModel catalogModel,
+            ReadableConfig configuration,
+            ClassLoader classLoader,
+            boolean isTemporary) {
+        final DefaultModelProviderContext context =
+                new DefaultModelProviderContext(
+                        objectIdentifier, catalogModel, configuration, classLoader, isTemporary);
+
+        try {
+            final ModelProviderFactory factory =
+                    preferredFactory != null
+                            ? preferredFactory
+                            : discoverModelProviderFactory(context);
+
+            return factory.createModelProvider(context);
+        } catch (Throwable t) {
+            throw new ValidationException(
+                    String.format(
+                            "Unable to create a model provider for model '%s'.\n\n"
+                                    + "Model options are:\n\n"
+                                    + "%s",
+                            objectIdentifier.asSummaryString(),
+                            catalogModel.getOptions().entrySet().stream()
+                                    .map(e -> stringifyOption(e.getKey(), e.getValue()))
+                                    .sorted()
+                                    .collect(Collectors.joining("\n"))),
+                    t);
+        }
+    }
+
     /**
      * Creates a utility that helps validating options for a {@link CatalogFactory}.
      *
@@ -358,6 +408,16 @@ public final class FactoryUtil {
         return new TableFactoryHelper(factory, context);
     }
 
+    /**
+     * Creates a utility that helps validate options for a {@link ModelProviderFactory}.
+     *
+     * <p>Note: This utility checks for left-over options in the final step.
+     */
+    public static ModelProviderFactoryHelper createModelProviderFactoryHelper(
+            ModelProviderFactory factory, ModelProviderFactory.Context context) {
+        return new ModelProviderFactoryHelper(factory, context);
+    }
+
     /**
      * Attempts to discover an appropriate catalog factory and creates an instance of the catalog.
      *
@@ -658,6 +718,19 @@ public final class FactoryUtil {
         }
     }
 
+    private static ModelProviderFactory discoverModelProviderFactory(
+            ModelProviderFactory.Context context) {
+        final String providerOption = context.getCatalogModel().getOptions().get(PROVIDER.key());
+        if (providerOption == null) {
+            throw new ValidationException(
+                    String.format(
+                            "Model options do not contain an option key '%s' for discovering a provider.",
+                            PROVIDER.key()));
+        }
+        return discoverFactory(
+                context.getClassLoader(), ModelProviderFactory.class, providerOption);
+    }
+
     private static CatalogFactory getCatalogFactory(CatalogFactory.Context context) {
         final String catalogType =
                 context.getOptions().get(CommonCatalogOptions.CATALOG_TYPE.key());
@@ -900,6 +973,23 @@ public final class FactoryUtil {
         }
     }
 
+    /**
+     * Helper utility for validating all options for a {@link ModelProviderFactory}.
+     *
+     * @see #createModelProviderFactoryHelper(ModelProviderFactory, ModelProviderFactory.Context)
+     */
+    @PublicEvolving
+    public static class ModelProviderFactoryHelper extends FactoryHelper<ModelProviderFactory> {
+        public ModelProviderFactoryHelper(
+                ModelProviderFactory modelProviderFactory, ModelProviderFactory.Context context) {
+            super(
+                    modelProviderFactory,
+                    context.getCatalogModel().getOptions(),
+                    PROPERTY_VERSION,
+                    PROVIDER);
+        }
+    }
+
     /**
      * Helper utility for validating all options for a {@link ModuleFactory}.
      *
@@ -1140,6 +1230,55 @@ public final class FactoryUtil {
         }
     }
 
+    /** Default implementation of {@link ModelProviderFactory.Context}. */
+    @Internal
+    public static class DefaultModelProviderContext implements ModelProviderFactory.Context {
+
+        private final ObjectIdentifier objectIdentifier;
+        private final ResolvedCatalogModel catalogModel;
+        private final ReadableConfig configuration;
+        private final ClassLoader classLoader;
+        private final boolean isTemporary;
+
+        public DefaultModelProviderContext(
+                ObjectIdentifier objectIdentifier,
+                ResolvedCatalogModel catalogModel,
+                ReadableConfig configuration,
+                ClassLoader classLoader,
+                boolean isTemporary) {
+            this.objectIdentifier = objectIdentifier;
+            this.catalogModel = catalogModel;
+            this.configuration = configuration;
+            this.classLoader = classLoader;
+            this.isTemporary = isTemporary;
+        }
+
+        @Override
+        public ObjectIdentifier getObjectIdentifier() {
+            return objectIdentifier;
+        }
+
+        @Override
+        public ResolvedCatalogModel getCatalogModel() {
+            return catalogModel;
+        }
+
+        @Override
+        public ReadableConfig getConfiguration() {
+            return configuration;
+        }
+
+        @Override
+        public ClassLoader getClassLoader() {
+            return classLoader;
+        }
+
+        @Override
+        public boolean isTemporary() {
+            return isTemporary;
+        }
+    }
+
     /** Default implementation of {@link DynamicTableFactory.Context}. */
     @Internal
     public static class DefaultDynamicTableContext implements DynamicTableFactory.Context {
diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/ModelProviderFactory.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/ModelProviderFactory.java
index 7b2b1d1c88c..16d1a22b74e 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/ModelProviderFactory.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/ModelProviderFactory.java
@@ -34,7 +34,7 @@ import org.apache.flink.table.ml.ModelProvider;
  * <p>See {@link Factory} for more information about the general design of a factory.
  */
 @PublicEvolving
-public interface ModelProviderFactory {
+public interface ModelProviderFactory extends Factory {
 
     /** Create ModelProvider based on provider. */
     ModelProvider createModelProvider(Context context);
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/FactoryUtilTest.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/FactoryUtilTest.java
index c792029080f..5f7bfe61797 100644
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/FactoryUtilTest.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/FactoryUtilTest.java
@@ -22,17 +22,22 @@ import org.apache.flink.configuration.ConfigOption;
 import org.apache.flink.configuration.ConfigOptions;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.core.testutils.FlinkAssertions;
+import org.apache.flink.table.api.Schema;
 import org.apache.flink.table.api.ValidationException;
 import org.apache.flink.table.catalog.Catalog;
+import org.apache.flink.table.catalog.CatalogModel;
 import org.apache.flink.table.catalog.CatalogStore;
 import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.catalog.ResolvedCatalogModel;
 import org.apache.flink.table.connector.sink.DynamicTableSink;
 import org.apache.flink.table.connector.source.DynamicTableSource;
 import org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSinkMock;
 import org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSourceMock;
 import org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock;
 import org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock;
+import org.apache.flink.table.factories.TestModelProviderFactory.TestModelProviderMock;
 import org.apache.flink.table.factories.utils.FactoryMocks;
+import org.apache.flink.table.ml.ModelProvider;
 import org.apache.flink.testutils.ClassLoaderUtils;
 import org.apache.flink.util.FlinkUserCodeClassLoaders;
 import org.apache.flink.util.MutableURLClassLoader;
@@ -54,7 +59,9 @@ import java.util.Set;
 import java.util.function.Consumer;
 
 import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
+import static org.apache.flink.table.factories.utils.FactoryMocks.OUTPUT_SCHEMA;
 import static org.apache.flink.table.factories.utils.FactoryMocks.SCHEMA;
+import static org.apache.flink.table.factories.utils.FactoryMocks.createModelProvider;
 import static org.apache.flink.table.factories.utils.FactoryMocks.createTableSink;
 import static org.apache.flink.table.factories.utils.FactoryMocks.createTableSource;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -737,6 +744,122 @@ class FactoryUtilTest {
                                         + "configuration 'classloader.check-leaked-classloader'"));
     }
 
+    @Test
+    public void testMissingModelProvider() {
+        assertCreateModelProviderWithOptionModifier(
+                options -> options.remove("provider"),
+                "Model options do not contain an option key 'provider' for discovering a provider.");
+    }
+
+    @Test
+    void testInvalidModelProvider() {
+        assertCreateModelProviderWithOptionModifier(
+                options -> options.put("provider", "FAIL"),
+                "Could not find any factory for identifier 'FAIL' that implements '"
+                        + ModelProviderFactory.class.getName()
+                        + "' in the classpath.\n\n"
+                        + "Available factory identifiers are:\n\n"
+                        + "conflicting-model\n"
+                        + "test-model");
+    }
+
+    @Test
+    void testMissingModelProviderOption() {
+        assertCreateModelProviderWithOptionModifier(
+                options -> options.remove("endpoint"),
+                "One or more required options are missing.\n\n"
+                        + "Missing required options are:\n\n"
+                        + "endpoint");
+    }
+
+    @Test
+    void testInvalidModelProviderOption() {
+        assertCreateModelProviderWithOptionModifier(
+                options -> options.put("version", "FAIL"), "Invalid value for option 'version'.");
+    }
+
+    @Test
+    void testUnconsumedModelOption() {
+        assertCreateModelProviderWithOptionModifier(
+                options -> {
+                    options.put("this-is-not-consumed", "42");
+                    options.put("this-is-also-not-consumed", "true");
+                },
+                "Unsupported options found for 'test-model'.\n\n"
+                        + "Unsupported options:\n\n"
+                        + "this-is-also-not-consumed\n"
+                        + "this-is-not-consumed\n\n"
+                        + "Supported options:\n\n"
+                        + "endpoint\n"
+                        + "property-version\n"
+                        + "provider\n"
+                        + "task\n"
+                        + "version");
+    }
+
+    @Test
+    void testAllModelOptions() {
+        final Map<String, String> options = createAllModelOptions();
+        final ModelProvider actualProvider = createModelProvider(SCHEMA, OUTPUT_SCHEMA, options);
+        final ModelProvider expectedProvider =
+                new TestModelProviderMock(
+                        ResolvedCatalogModel.of(
+                                CatalogModel.of(
+                                        Schema.newBuilder().fromResolvedSchema(SCHEMA).build(),
+                                        Schema.newBuilder()
+                                                .fromResolvedSchema(OUTPUT_SCHEMA)
+                                                .build(),
+                                        options,
+                                        "mock model"),
+                                SCHEMA,
+                                OUTPUT_SCHEMA));
+        assertThat(actualProvider).isEqualTo(expectedProvider);
+    }
+
+    @Test
+    void testModelProviderFactoryHelper() {
+        final Map<String, String> options = new HashMap<>();
+        options.put("endpoint", "https://openai.com");
+        options.put("task", "text_generation");
+
+        final FactoryUtil.ModelProviderFactoryHelper helper =
+                FactoryUtil.createModelProviderFactoryHelper(
+                        new TestModelProviderFactory(),
+                        FactoryMocks.createModelContext(SCHEMA, OUTPUT_SCHEMA, options));
+
+        // No error
+        helper.validate();
+
+        final Map<String, String> invalidOptions = new HashMap<>(options);
+        invalidOptions.put("invalid-option", "value");
+
+        final FactoryUtil.ModelProviderFactoryHelper invalidHelper =
+                FactoryUtil.createModelProviderFactoryHelper(
+                        new TestModelProviderFactory(),
+                        FactoryMocks.createModelContext(SCHEMA, OUTPUT_SCHEMA, invalidOptions));
+
+        assertThatThrownBy(invalidHelper::validate)
+                .satisfies(
+                        anyCauseMatches(
+                                ValidationException.class,
+                                "Unsupported options found for 'test-model'"));
+    }
+
+    @Test
+    void testConflictingModelProvider() {
+        assertCreateModelProviderWithOptionModifier(
+                options -> options.put("provider", TestConflictingModelProviderFactory1.IDENTIFIER),
+                "Multiple factories for identifier 'conflicting-model' that implement '"
+                        + ModelProviderFactory.class.getName()
+                        + "' found in the classpath.\n"
+                        + "\n"
+                        + "Ambiguous factory classes are:\n"
+                        + "\n"
+                        + TestConflictingModelProviderFactory1.class.getName()
+                        + "\n"
+                        + TestConflictingModelProviderFactory2.class.getName());
+    }
+
     // --------------------------------------------------------------------------------------------
     // Helper methods
     // --------------------------------------------------------------------------------------------
@@ -756,6 +879,30 @@ class FactoryUtilTest {
         }
     }
 
+    private static void assertCreateModelProviderWithOptionModifier(
+            Consumer<Map<String, String>> optionModifier, String... messages) {
+        AbstractThrowableAssert<?, ? extends Throwable> assertion =
+                assertThatThrownBy(
+                        () -> {
+                            final Map<String, String> options = createAllModelOptions();
+                            optionModifier.accept(options);
+                            createModelProvider(SCHEMA, OUTPUT_SCHEMA, options);
+                        });
+
+        for (String message : messages) {
+            assertion.satisfies(anyCauseMatches(ValidationException.class, message));
+        }
+    }
+
+    private static Map<String, String> createAllModelOptions() {
+        final Map<String, String> options = new HashMap<>();
+        options.put("provider", TestModelProviderFactory.IDENTIFIER);
+        options.put("endpoint", "https://openai.com");
+        options.put("task", "text_generation");
+        options.put("version", "1");
+        return options;
+    }
+
     private static Map<String, String> createAllOptions() {
         final Map<String, String> options = new HashMap<>();
         // we use strings here to test realistic parsing
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestConflictingModelProviderFactory1.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestConflictingModelProviderFactory1.java
new file mode 100644
index 00000000000..1969b53ce85
--- /dev/null
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestConflictingModelProviderFactory1.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.factories;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.table.ml.ModelProvider;
+
+import java.util.Collections;
+import java.util.Set;
+
+/** First test implementation for conflicting {@link ModelProviderFactory}. */
+public class TestConflictingModelProviderFactory1 implements ModelProviderFactory {
+
+    public static final String IDENTIFIER = "conflicting-model";
+
+    @Override
+    public ModelProvider createModelProvider(Context context) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String factoryIdentifier() {
+        return IDENTIFIER;
+    }
+
+    @Override
+    public Set<ConfigOption<?>> requiredOptions() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public Set<ConfigOption<?>> optionalOptions() {
+        return Collections.emptySet();
+    }
+}
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestConflictingModelProviderFactory2.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestConflictingModelProviderFactory2.java
new file mode 100644
index 00000000000..b7a1d3ba888
--- /dev/null
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestConflictingModelProviderFactory2.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.factories;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.table.ml.ModelProvider;
+
+import java.util.Collections;
+import java.util.Set;
+
+/** Second test implementation for conflicting {@link ModelProviderFactory}. */
+public class TestConflictingModelProviderFactory2 implements ModelProviderFactory {
+
+    @Override
+    public ModelProvider createModelProvider(Context context) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String factoryIdentifier() {
+        return TestConflictingModelProviderFactory1.IDENTIFIER;
+    }
+
+    @Override
+    public Set<ConfigOption<?>> requiredOptions() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public Set<ConfigOption<?>> optionalOptions() {
+        return Collections.emptySet();
+    }
+}
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestModelProviderFactory.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestModelProviderFactory.java
new file mode 100644
index 00000000000..725e25df24a
--- /dev/null
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestModelProviderFactory.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.factories;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.table.catalog.ResolvedCatalogModel;
+import org.apache.flink.table.factories.FactoryUtil.ModelProviderFactoryHelper;
+import org.apache.flink.table.ml.ModelProvider;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/** Test implementation for {@link ModelProviderFactory}. */
+public final class TestModelProviderFactory implements ModelProviderFactory {
+
+    public static final String IDENTIFIER = "test-model";
+
+    public static final ConfigOption<String> TASK =
+            ConfigOptions.key("task")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription("Task of the test model.");
+
+    public static final ConfigOption<String> ENDPOINT =
+            ConfigOptions.key("endpoint")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription("Endpoint of the test model.");
+
+    public static final ConfigOption<Integer> MODEL_VERSION =
+            ConfigOptions.key("version")
+                    .intType()
+                    .defaultValue(1)
+                    .withDescription("Version of the test model.");
+
+    @Override
+    public ModelProvider createModelProvider(Context context) {
+        final ModelProviderFactoryHelper helper =
+                FactoryUtil.createModelProviderFactoryHelper(this, context);
+        helper.validate();
+        return new TestModelProviderMock(context.getCatalogModel());
+    }
+
+    @Override
+    public String factoryIdentifier() {
+        return IDENTIFIER;
+    }
+
+    @Override
+    public Set<ConfigOption<?>> requiredOptions() {
+        final Set<ConfigOption<?>> options = new HashSet<>();
+        options.add(TASK);
+        options.add(ENDPOINT);
+        return options;
+    }
+
+    @Override
+    public Set<ConfigOption<?>> optionalOptions() {
+        Set<ConfigOption<?>> options = new HashSet<>();
+        options.add(MODEL_VERSION);
+        return options;
+    }
+
+    /** Test implementation of {@link ModelProvider} for testing purposes. */
+    public static class TestModelProviderMock implements ModelProvider {
+
+        private final ResolvedCatalogModel catalogModel;
+
+        public TestModelProviderMock(ResolvedCatalogModel catalogModel) {
+            this.catalogModel = catalogModel;
+        }
+
+        @Override
+        public ModelProvider copy() {
+            return new TestModelProviderMock(catalogModel);
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+            return catalogModel.equals(((TestModelProviderMock) o).catalogModel);
+        }
+    }
+}
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/utils/FactoryMocks.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/utils/FactoryMocks.java
index 6e8611d65ae..95ad0ffdcff 100644
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/utils/FactoryMocks.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/utils/FactoryMocks.java
@@ -22,15 +22,19 @@ import org.apache.flink.configuration.Configuration;
 import org.apache.flink.configuration.ReadableConfig;
 import org.apache.flink.table.api.DataTypes;
 import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.CatalogModel;
 import org.apache.flink.table.catalog.CatalogTable;
 import org.apache.flink.table.catalog.Column;
 import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ResolvedCatalogModel;
 import org.apache.flink.table.catalog.ResolvedCatalogTable;
 import org.apache.flink.table.catalog.ResolvedSchema;
 import org.apache.flink.table.connector.sink.DynamicTableSink;
 import org.apache.flink.table.connector.source.DynamicTableSource;
 import org.apache.flink.table.factories.DynamicTableFactory;
 import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.factories.ModelProviderFactory;
+import org.apache.flink.table.ml.ModelProvider;
 import org.apache.flink.table.types.DataType;
 import org.apache.flink.table.types.logical.RowType;
 
@@ -51,9 +55,33 @@ public final class FactoryMocks {
 
     public static final RowType PHYSICAL_TYPE = (RowType) PHYSICAL_DATA_TYPE.getLogicalType();
 
+    public static final ResolvedSchema OUTPUT_SCHEMA =
+            ResolvedSchema.of(Column.physical("output", DataTypes.STRING()));
+
     public static final ObjectIdentifier IDENTIFIER =
             ObjectIdentifier.of("default", "default", "t1");
 
+    public static final ObjectIdentifier MODEL_IDENTIFIER =
+            ObjectIdentifier.of("default", "default", "m1");
+
+    public static ModelProvider createModelProvider(
+            ResolvedSchema inputSchema, ResolvedSchema outputSchema, Map<String, String> options) {
+        return FactoryUtil.createModelProvider(
+                null,
+                MODEL_IDENTIFIER,
+                ResolvedCatalogModel.of(
+                        CatalogModel.of(
+                                Schema.newBuilder().fromResolvedSchema(inputSchema).build(),
+                                Schema.newBuilder().fromResolvedSchema(outputSchema).build(),
+                                options,
+                                "mock model"),
+                        inputSchema,
+                        outputSchema),
+                new Configuration(),
+                FactoryMocks.class.getClassLoader(),
+                false);
+    }
+
     public static DynamicTableSource createTableSource(
             ResolvedSchema schema, Map<String, String> options) {
         return createTableSource(schema, options, new Configuration());
@@ -101,6 +129,23 @@ public final class FactoryMocks {
                 false);
     }
 
+    public static ModelProviderFactory.Context createModelContext(
+            ResolvedSchema schema, ResolvedSchema outputSchema, Map<String, String> options) {
+        return new FactoryUtil.DefaultModelProviderContext(
+                MODEL_IDENTIFIER,
+                ResolvedCatalogModel.of(
+                        CatalogModel.of(
+                                Schema.newBuilder().fromResolvedSchema(schema).build(),
+                                Schema.newBuilder().fromResolvedSchema(outputSchema).build(),
+                                options,
+                                "mock model"),
+                        schema,
+                        outputSchema),
+                new Configuration(),
+                FactoryMocks.class.getClassLoader(),
+                false);
+    }
+
     public static DynamicTableFactory.Context createTableContext(
             ResolvedSchema schema, Map<String, String> options) {
         return createTableContext(schema, options, Collections.emptyMap());
diff --git a/flink-table/flink-table-common/src/test/resources/META-INF/services/org.apache.flink.table.factories.Factory b/flink-table/flink-table-common/src/test/resources/META-INF/services/org.apache.flink.table.factories.Factory
index 60d84ab0904..bf2382c7310 100644
--- a/flink-table/flink-table-common/src/test/resources/META-INF/services/org.apache.flink.table.factories.Factory
+++ b/flink-table/flink-table-common/src/test/resources/META-INF/services/org.apache.flink.table.factories.Factory
@@ -23,5 +23,8 @@ org.apache.flink.table.factories.TestConflictingDynamicTableFactory1
 org.apache.flink.table.factories.TestConflictingDynamicTableFactory2
 org.apache.flink.table.factories.TestCatalogFactory
 org.apache.flink.table.factories.TestCatalogStoreFactory
+org.apache.flink.table.factories.TestModelProviderFactory
+org.apache.flink.table.factories.TestConflictingModelProviderFactory1
+org.apache.flink.table.factories.TestConflictingModelProviderFactory2
 org.apache.flink.table.factories.module.DummyModuleFactory
 org.apache.flink.table.factories.workflow.TestWorkflowSchedulerFactory