You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by lz...@apache.org on 2022/07/06 12:45:19 UTC

[flink-table-store] branch master updated: [hotfix] FileFormat.fromIdentifier should search FileFormat ClassLoader too

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

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git


The following commit(s) were added to refs/heads/master by this push:
     new b5c73257 [hotfix] FileFormat.fromIdentifier should search FileFormat ClassLoader too
b5c73257 is described below

commit b5c73257e8c2ad6735dba9e475e44850de5a7397
Author: JingsongLi <lz...@aliyun.com>
AuthorDate: Wed Jul 6 20:45:09 2022 +0800

    [hotfix] FileFormat.fromIdentifier should search FileFormat ClassLoader too
---
 .../flink/table/store/format/FileFormat.java       | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/flink-table-store-common/src/main/java/org/apache/flink/table/store/format/FileFormat.java b/flink-table-store-common/src/main/java/org/apache/flink/table/store/format/FileFormat.java
index 8bfcd2dd..98fd4103 100644
--- a/flink-table-store-common/src/main/java/org/apache/flink/table/store/format/FileFormat.java
+++ b/flink-table-store-common/src/main/java/org/apache/flink/table/store/format/FileFormat.java
@@ -91,17 +91,31 @@ public abstract class FileFormat {
     }
 
     /** Create a {@link FileFormat} from format identifier and format options. */
-    public static FileFormat fromIdentifier(String formatIdentifier, Configuration formatOptions) {
+    public static FileFormat fromIdentifier(String identifier, Configuration options) {
+        Optional<FileFormat> format =
+                fromIdentifier(identifier, options, Thread.currentThread().getContextClassLoader());
+        return format.orElseGet(
+                () ->
+                        fromIdentifier(identifier, options, FileFormat.class.getClassLoader())
+                                .orElseThrow(
+                                        () ->
+                                                new ValidationException(
+                                                        String.format(
+                                                                "Could not find any factories that implement '%s' in the classpath.",
+                                                                FileFormatFactory.class
+                                                                        .getName()))));
+    }
+
+    private static Optional<FileFormat> fromIdentifier(
+            String formatIdentifier, Configuration formatOptions, ClassLoader classLoader) {
         ServiceLoader<FileFormatFactory> serviceLoader =
-                ServiceLoader.load(FileFormatFactory.class);
+                ServiceLoader.load(FileFormatFactory.class, FileFormat.class.getClassLoader());
         for (FileFormatFactory factory : serviceLoader) {
             if (factory.identifier().equals(formatIdentifier.toLowerCase())) {
-                return factory.create(formatOptions);
+                return Optional.of(factory.create(formatOptions));
             }
         }
-        throw new ValidationException(
-                String.format(
-                        "Could not find any factories that implement '%s' in the classpath.",
-                        FileFormatFactory.class.getName()));
+
+        return Optional.empty();
     }
 }