You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ro...@apache.org on 2025/01/15 04:06:08 UTC

(flink) branch master updated: [FLINK-36504][table-common]Remove all deprecated methods ModuleFactory (#25963)

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

ron 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 8af02592472 [FLINK-36504][table-common]Remove all deprecated methods ModuleFactory (#25963)
8af02592472 is described below

commit 8af02592472e2a85eb3eeb81457ac3e6660d27e4
Author: XuShuai <ye...@alibaba-inc.com>
AuthorDate: Wed Jan 15 12:06:00 2025 +0800

    [FLINK-36504][table-common]Remove all deprecated methods ModuleFactory (#25963)
    
    Co-authored-by: shiwei10 <sh...@staff.weibo.com>
---
 .../apache/flink/table/factories/FactoryUtil.java  | 58 +++++++++-----------
 .../flink/table/factories/ModuleFactory.java       | 62 ++--------------------
 .../factories/module/LegacyDummyModuleFactory.java | 49 -----------------
 ...pache.flink.table.legacy.factories.TableFactory |  1 -
 .../flink/table/api/TableEnvironmentTest.scala     |  6 ---
 5 files changed, 28 insertions(+), 148 deletions(-)

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 ff034945231..e443bf186c7 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
@@ -53,7 +53,6 @@ import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -427,41 +426,32 @@ public final class FactoryUtil {
                             MODULE_TYPE.key(), options.get(MODULE_TYPE.key())));
         }
 
+        final DefaultModuleContext discoveryContext =
+                new DefaultModuleContext(options, configuration, classLoader);
         try {
-            final Map<String, String> optionsWithType = new HashMap<>(options);
-            optionsWithType.put(MODULE_TYPE.key(), moduleName);
-
-            final ModuleFactory legacyFactory =
-                    TableFactoryService.find(ModuleFactory.class, optionsWithType, classLoader);
-            return legacyFactory.createModule(optionsWithType);
-        } catch (NoMatchingTableFactoryException e) {
-            final DefaultModuleContext discoveryContext =
+            final ModuleFactory factory =
+                    discoverFactory(
+                            ((ModuleFactory.Context) discoveryContext).getClassLoader(),
+                            ModuleFactory.class,
+                            moduleName);
+
+            final DefaultModuleContext context =
                     new DefaultModuleContext(options, configuration, classLoader);
-            try {
-                final ModuleFactory factory =
-                        discoverFactory(
-                                ((ModuleFactory.Context) discoveryContext).getClassLoader(),
-                                ModuleFactory.class,
-                                moduleName);
-
-                final DefaultModuleContext context =
-                        new DefaultModuleContext(options, configuration, classLoader);
-                return factory.createModule(context);
-            } catch (Throwable t) {
-                throw new ValidationException(
-                        String.format(
-                                "Unable to create module '%s'.%n%nModule options are:%n%s",
-                                moduleName,
-                                options.entrySet().stream()
-                                        .map(
-                                                optionEntry ->
-                                                        stringifyOption(
-                                                                optionEntry.getKey(),
-                                                                optionEntry.getValue()))
-                                        .sorted()
-                                        .collect(Collectors.joining("\n"))),
-                        t);
-            }
+            return factory.createModule(context);
+        } catch (Throwable t) {
+            throw new ValidationException(
+                    String.format(
+                            "Unable to create module '%s'.%n%nModule options are:%n%s",
+                            moduleName,
+                            options.entrySet().stream()
+                                    .map(
+                                            optionEntry ->
+                                                    stringifyOption(
+                                                            optionEntry.getKey(),
+                                                            optionEntry.getValue()))
+                                    .sorted()
+                                    .collect(Collectors.joining("\n"))),
+                    t);
         }
     }
 
diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/ModuleFactory.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/ModuleFactory.java
index 6a668bd7041..796003c2839 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/ModuleFactory.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/ModuleFactory.java
@@ -25,7 +25,6 @@ import org.apache.flink.table.legacy.factories.TableFactory;
 import org.apache.flink.table.module.Module;
 import org.apache.flink.table.module.ModuleException;
 
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -38,20 +37,7 @@ import java.util.Set;
  * instead.
  */
 @PublicEvolving
-public interface ModuleFactory extends TableFactory, Factory {
-
-    /**
-     * Creates and configures a {@link Module} using the given properties.
-     *
-     * @param properties normalized properties describing a module.
-     * @return the configured module.
-     * @deprecated Use {@link #createModule(Context)} instead and implement {@link Factory} instead
-     *     of {@link TableFactory}.
-     */
-    @Deprecated
-    default Module createModule(Map<String, String> properties) {
-        throw new ModuleException("Module factories must implement createModule().");
-    }
+public interface ModuleFactory extends Factory {
 
     /** Creates and configures a {@link Module}. */
     default Module createModule(Context context) {
@@ -79,49 +65,9 @@ public interface ModuleFactory extends TableFactory, Factory {
         ClassLoader getClassLoader();
     }
 
-    default String factoryIdentifier() {
-        if (requiredContext() == null || supportedProperties() == null) {
-            throw new ModuleException("Module factories must implement factoryIdentifier()");
-        }
-
-        return null;
-    }
-
-    default Set<ConfigOption<?>> requiredOptions() {
-        if (requiredContext() == null || supportedProperties() == null) {
-            throw new ModuleException("Module factories must implement requiredOptions()");
-        }
-
-        return null;
-    }
+    String factoryIdentifier();
 
-    default Set<ConfigOption<?>> optionalOptions() {
-        if (requiredContext() == null || supportedProperties() == null) {
-            throw new ModuleException("Module factories must implement optionalOptions()");
-        }
+    Set<ConfigOption<?>> requiredOptions();
 
-        return null;
-    }
-
-    // --------------------------------------------------------------------------------------------
-    // Default implementations for legacy {@link TableFactory} stack.
-    // --------------------------------------------------------------------------------------------
-
-    /**
-     * @deprecated Implement the {@link Factory} based stack instead.
-     */
-    @Deprecated
-    default Map<String, String> requiredContext() {
-        // Default implementation for modules implementing the new {@link Factory} stack instead.
-        return null;
-    }
-
-    /**
-     * @deprecated Implement the {@link Factory} based stack instead.
-     */
-    @Deprecated
-    default List<String> supportedProperties() {
-        // Default implementation for modules implementing the new {@link Factory} stack instead.
-        return null;
-    }
+    Set<ConfigOption<?>> optionalOptions();
 }
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/module/LegacyDummyModuleFactory.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/module/LegacyDummyModuleFactory.java
deleted file mode 100644
index 26664f5566c..00000000000
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/module/LegacyDummyModuleFactory.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.module;
-
-import org.apache.flink.table.factories.ModuleFactory;
-import org.apache.flink.table.module.CommonModuleOptions;
-import org.apache.flink.table.module.Module;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-/** Test implementation of a {@link ModuleFactory} using the legacy stack. */
-@Deprecated
-public class LegacyDummyModuleFactory implements ModuleFactory {
-
-    public static final String IDENTIFIER = "LegacyModule";
-
-    @Override
-    public Map<String, String> requiredContext() {
-        return Collections.singletonMap(CommonModuleOptions.MODULE_TYPE.key(), IDENTIFIER);
-    }
-
-    @Override
-    public List<String> supportedProperties() {
-        return Collections.emptyList();
-    }
-
-    @Override
-    public Module createModule(Map<String, String> options) {
-        return new Module() {};
-    }
-}
diff --git a/flink-table/flink-table-common/src/test/resources/META-INF/services/org.apache.flink.table.legacy.factories.TableFactory b/flink-table/flink-table-common/src/test/resources/META-INF/services/org.apache.flink.table.legacy.factories.TableFactory
index 8664f58ca68..109471382f5 100644
--- a/flink-table/flink-table-common/src/test/resources/META-INF/services/org.apache.flink.table.legacy.factories.TableFactory
+++ b/flink-table/flink-table-common/src/test/resources/META-INF/services/org.apache.flink.table.legacy.factories.TableFactory
@@ -14,4 +14,3 @@
 # limitations under the License.
 
 org.apache.flink.table.factories.TestTableSinkFactory
-org.apache.flink.table.factories.module.LegacyDummyModuleFactory
diff --git a/flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentTest.scala b/flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentTest.scala
index 2700188b532..225af8444a8 100644
--- a/flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentTest.scala
+++ b/flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentTest.scala
@@ -1631,12 +1631,6 @@ class TableEnvironmentTest {
     validateShowModules(("core", false))
   }
 
-  @Test
-  def testLegacyModule(): Unit = {
-    tableEnv.executeSql("LOAD MODULE LegacyModule")
-    validateShowModules(("core", true), ("LegacyModule", true))
-  }
-
   @Test
   def testExecuteSqlWithCreateDropView(): Unit = {
     createTableForTests()