rdblue commented on a change in pull request #1618:
URL: https://github.com/apache/iceberg/pull/1618#discussion_r509521009
##########
File path: core/src/main/java/org/apache/iceberg/CatalogUtil.java
##########
@@ -117,4 +120,42 @@ private static void deleteFiles(FileIO io,
Set<ManifestFile> allManifests) {
}
});
}
+
+ /**
+ * Load FileIO, default to HadoopFileIO
+ * @param tableMetadata table metadata
+ * @param conf Hadoop configuration
+ * @return FileIO class
+ * @throws IllegalArgumentException if class path not found or
+ * right constructor not found or
+ * the loaded class cannot be casted to the given interface type
+ */
+ public static FileIO loadFileIO(TableMetadata tableMetadata, Configuration
conf) {
+ if (tableMetadata != null) {
+ Map<String, String> properties = tableMetadata.properties();
+ if (properties.containsKey(TableProperties.WRITE_FILE_IO_IMPL)) {
+ String impl = properties.get(TableProperties.WRITE_FILE_IO_IMPL);
+ LOG.info("Loading custom FileIO implementation: {}", impl);
+ DynConstructors.Ctor<FileIO> ctor;
+ try {
+ ctor = DynConstructors.builder(FileIO.class)
+ .impl(impl, Configuration.class)
+ .impl(impl) // fall back to no-arg constructor
+ .buildChecked();
+ } catch (NoSuchMethodException e) {
+ throw new IllegalArgumentException(String.format(
+ "Cannot initialize FiloIO, please make sure %s has a constructor
taking %s, or a no-arg constructor",
+ impl, Configuration.class), e);
+ }
+ try {
+ return ctor.newInstance(conf);
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException(
+ String.format("Cannot initialize FileIO, fail to cast %s to
class %s.",
+ impl, FileIO.class), e);
Review comment:
Style: does this need to be on a separate line?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]