You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/01/17 04:02:20 UTC

[GitHub] [iceberg] yittg opened a new pull request #3906: Fix context classloader usage for avro reader

yittg opened a new pull request #3906:
URL: https://github.com/apache/iceberg/pull/3906


   parts of #3776 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] yittg commented on a change in pull request #3906: Fix context classloader usage for avro reader

Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #3906:
URL: https://github.com/apache/iceberg/pull/3906#discussion_r786373533



##########
File path: core/src/main/java/org/apache/iceberg/avro/Avro.java
##########
@@ -553,15 +558,20 @@ public static ReadBuilder read(InputFile file) {
   public static class ReadBuilder {
     private final InputFile file;
     private final Map<String, String> renames = Maps.newLinkedHashMap();
-    private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+    private ClassLoader loader = null;
     private NameMapping nameMapping;
     private boolean reuseContainers = false;
     private org.apache.iceberg.Schema schema = null;
     private Function<Schema, DatumReader<?>> createReaderFunc = null;
     private BiFunction<org.apache.iceberg.Schema, Schema, DatumReader<?>> createReaderBiFunc = null;
     private final Function<Schema, DatumReader<?>> defaultCreateReaderFunc = readSchema -> {
       GenericAvroReader<?> reader = new GenericAvroReader<>(readSchema);
-      reader.setClassLoader(loader);
+      ClassLoader classLoader = loader;
+      if (classLoader == null) {
+        LOG.warn("Classloader for avro reader not set, use the thread context classloader.");
+        classLoader = Thread.currentThread().getContextClassLoader();
+      }
+      reader.setClassLoader(classLoader);

Review comment:
       Adding warning mainly to prevent forgetting to set classloader if required. I've to permit that it is not perfect, but have no better idea.
   It's ok to not change the behavior of this class.
   
   I'll remove changes in this file.
   
   




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on pull request #3906: Fix context classloader usage for avro reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on pull request #3906:
URL: https://github.com/apache/iceberg/pull/3906#issuecomment-1015586069


   Thanks, @yittg! I'll merge when tests are passing.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] yittg commented on a change in pull request #3906: Fix context classloader usage for avro reader

Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #3906:
URL: https://github.com/apache/iceberg/pull/3906#discussion_r785623253



##########
File path: core/src/main/java/org/apache/iceberg/avro/Avro.java
##########
@@ -553,15 +558,20 @@ public static ReadBuilder read(InputFile file) {
   public static class ReadBuilder {
     private final InputFile file;
     private final Map<String, String> renames = Maps.newLinkedHashMap();
-    private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+    private ClassLoader loader = null;
     private NameMapping nameMapping;
     private boolean reuseContainers = false;
     private org.apache.iceberg.Schema schema = null;
     private Function<Schema, DatumReader<?>> createReaderFunc = null;
     private BiFunction<org.apache.iceberg.Schema, Schema, DatumReader<?>> createReaderBiFunc = null;
     private final Function<Schema, DatumReader<?>> defaultCreateReaderFunc = readSchema -> {
       GenericAvroReader<?> reader = new GenericAvroReader<>(readSchema);
-      reader.setClassLoader(loader);
+      ClassLoader classLoader = loader;
+      if (classLoader == null) {
+        LOG.warn("Classloader for avro reader not set, use the thread context classloader.");
+        classLoader = Thread.currentThread().getContextClassLoader();
+      }
+      reader.setClassLoader(classLoader);

Review comment:
       @rdblue I'm not sure if we should just requireNonNull(loader) here.




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #3906: Fix context classloader usage for avro reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #3906:
URL: https://github.com/apache/iceberg/pull/3906#discussion_r786244912



##########
File path: core/src/main/java/org/apache/iceberg/avro/Avro.java
##########
@@ -553,15 +558,20 @@ public static ReadBuilder read(InputFile file) {
   public static class ReadBuilder {
     private final InputFile file;
     private final Map<String, String> renames = Maps.newLinkedHashMap();
-    private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+    private ClassLoader loader = null;
     private NameMapping nameMapping;
     private boolean reuseContainers = false;
     private org.apache.iceberg.Schema schema = null;
     private Function<Schema, DatumReader<?>> createReaderFunc = null;
     private BiFunction<org.apache.iceberg.Schema, Schema, DatumReader<?>> createReaderBiFunc = null;
     private final Function<Schema, DatumReader<?>> defaultCreateReaderFunc = readSchema -> {
       GenericAvroReader<?> reader = new GenericAvroReader<>(readSchema);
-      reader.setClassLoader(loader);
+      ClassLoader classLoader = loader;
+      if (classLoader == null) {
+        LOG.warn("Classloader for avro reader not set, use the thread context classloader.");
+        classLoader = Thread.currentThread().getContextClassLoader();
+      }
+      reader.setClassLoader(classLoader);

Review comment:
       I don't think that we need to change any behavior in this class. The current behavior is adequate and setting the classloader is only needed if you are attempting to load a custom class or if the context classloader throws an unexpected exception, as in the Flink case.




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #3906: Fix context classloader usage for avro reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #3906:
URL: https://github.com/apache/iceberg/pull/3906#discussion_r786244485



##########
File path: core/src/main/java/org/apache/iceberg/avro/Avro.java
##########
@@ -553,15 +558,20 @@ public static ReadBuilder read(InputFile file) {
   public static class ReadBuilder {
     private final InputFile file;
     private final Map<String, String> renames = Maps.newLinkedHashMap();
-    private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+    private ClassLoader loader = null;
     private NameMapping nameMapping;
     private boolean reuseContainers = false;
     private org.apache.iceberg.Schema schema = null;
     private Function<Schema, DatumReader<?>> createReaderFunc = null;
     private BiFunction<org.apache.iceberg.Schema, Schema, DatumReader<?>> createReaderBiFunc = null;
     private final Function<Schema, DatumReader<?>> defaultCreateReaderFunc = readSchema -> {
       GenericAvroReader<?> reader = new GenericAvroReader<>(readSchema);
-      reader.setClassLoader(loader);
+      ClassLoader classLoader = loader;
+      if (classLoader == null) {
+        LOG.warn("Classloader for avro reader not set, use the thread context classloader.");

Review comment:
       I don't think that this warning is necessary. This is a how Avro has always worked, so there is nothing new happening when we use the thread context loader.




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue merged pull request #3906: Fix context classloader usage for avro reader

Posted by GitBox <gi...@apache.org>.
rdblue merged pull request #3906:
URL: https://github.com/apache/iceberg/pull/3906


   


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org