yihua commented on code in PR #11192:
URL: https://github.com/apache/hudi/pull/11192#discussion_r1597281157


##########
hudi-common/src/main/java/org/apache/hudi/io/storage/HoodieFileWriterFactory.java:
##########
@@ -43,39 +40,18 @@
 
 public class HoodieFileWriterFactory {
 
-  private static HoodieFileWriterFactory 
getWriterFactory(HoodieRecord.HoodieRecordType recordType) {

Review Comment:
   Let's create a JIRA ticket to make the `HoodieFileReaderFactory` and 
`HoodieFileWriterFactory` interface or abstract class so APIs to create new 
reader and writer should be abstract.



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/io/storage/HoodieSparkIOFactory.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.hudi.io.storage;
+
+import org.apache.hudi.common.model.HoodieRecord;
+
+public class HoodieSparkIOFactory extends HoodieHadoopIOFactory {
+

Review Comment:
   nit: empty line



##########
hudi-common/src/main/java/org/apache/hudi/common/config/HoodieStorageConfig.java:
##########
@@ -235,6 +235,13 @@ public class HoodieStorageConfig extends HoodieConfig {
           + "and it is loaded at runtime. This is only required when trying to 
"
           + "override the existing write context when 
`hoodie.datasource.write.row.writer.enable=true`.");
 
+  public static final ConfigProperty<String> HOODIE_IO_FACTORY_CLASS = 
ConfigProperty
+      .key("hoodie.io.factory.class")
+      .defaultValue("org.apache.hudi.io.storage.HoodieHadoopIOFactory")
+      .markAdvanced()
+      .sinceVersion("0.15.0")
+      .withDocumentation("Provided class should implement 
`org.apache.hudi.io.storage.HoodieIOFactory`");

Review Comment:
   ```suggestion
         .withDocumentation("The fully-qualified class name of the factory 
class to return readers and writers of files used by Hudi. The provided class 
should implement `org.apache.hudi.io.storage.HoodieIOFactory`");
   ```



##########
hudi-common/src/main/java/org/apache/hudi/io/storage/HoodieIOFactory.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.hudi.io.storage;
+
+import org.apache.hudi.common.config.HoodieStorageConfig;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.ReflectionUtils;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.storage.StorageConfiguration;
+
+/**
+ * Base class to get HoodieFileReaderFactory and HoodieFileWriterFactory
+ */
+public abstract class HoodieIOFactory {
+
+  public static HoodieIOFactory getIOFactory(StorageConfiguration<?> 
storageConf) {
+    String ioFactoryClass = 
storageConf.getString(HoodieStorageConfig.HOODIE_IO_FACTORY_CLASS.key())
+        .orElse(HoodieStorageConfig.HOODIE_IO_FACTORY_CLASS.defaultValue());
+    return getIOFactory(ioFactoryClass);
+  }
+
+  private static HoodieIOFactory getIOFactory(String ioFactoryClass) {
+    try {
+      Class<?> clazz =
+          ReflectionUtils.getClass(ioFactoryClass);
+      return (HoodieIOFactory) clazz.newInstance();
+    } catch (IllegalArgumentException | IllegalAccessException | 
InstantiationException e) {
+      throw new HoodieException("Unable to create " + ioFactoryClass, e);
+    }

Review Comment:
   Use `ReflectionUtils#loadClass`



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/clustering/run/strategy/MultipleSparkJobExecutionStrategy.java:
##########
@@ -385,7 +385,7 @@ private HoodieData<HoodieRecord<T>> 
readRecordsForGroupBaseFiles(JavaSparkContex
 
   private HoodieFileReader 
getBaseOrBootstrapFileReader(StorageConfiguration<?> storageConf, String 
bootstrapBasePath, Option<String[]> partitionFields, ClusteringOperation 
clusteringOp)
       throws IOException {
-    HoodieFileReader baseFileReader = 
HoodieFileReaderFactory.getReaderFactory(recordType)
+    HoodieFileReader baseFileReader = (new 
HoodieSparkIOFactory()).getReaderFactory(recordType)

Review Comment:
   Create a util to return a static `HoodieSparkIOFactory` instance for Spark 
engine?



##########
hudi-common/src/main/java/org/apache/hudi/io/storage/HoodieIOFactory.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.hudi.io.storage;
+
+import org.apache.hudi.common.config.HoodieStorageConfig;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.ReflectionUtils;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.storage.StorageConfiguration;
+
+/**
+ * Base class to get HoodieFileReaderFactory and HoodieFileWriterFactory
+ */
+public abstract class HoodieIOFactory {
+
+  public static HoodieIOFactory getIOFactory(StorageConfiguration<?> 
storageConf) {
+    String ioFactoryClass = 
storageConf.getString(HoodieStorageConfig.HOODIE_IO_FACTORY_CLASS.key())
+        .orElse(HoodieStorageConfig.HOODIE_IO_FACTORY_CLASS.defaultValue());
+    return getIOFactory(ioFactoryClass);
+  }
+
+  private static HoodieIOFactory getIOFactory(String ioFactoryClass) {
+    try {
+      Class<?> clazz =
+          ReflectionUtils.getClass(ioFactoryClass);
+      return (HoodieIOFactory) clazz.newInstance();
+    } catch (IllegalArgumentException | IllegalAccessException | 
InstantiationException e) {
+      throw new HoodieException("Unable to create " + ioFactoryClass, e);
+    }
+  }
+
+  public HoodieFileReaderFactory 
getReaderFactory(HoodieRecord.HoodieRecordType recordType) {
+    throw new UnsupportedOperationException(recordType + " record type not 
supported");
+  }
+
+  public HoodieFileWriterFactory 
getWriterFactory(HoodieRecord.HoodieRecordType recordType) {
+    throw new UnsupportedOperationException(recordType + " record type not 
supported");
+  }

Review Comment:
   Make these abstract?



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/io/storage/HoodieSparkIOFactory.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.hudi.io.storage;
+
+import org.apache.hudi.common.model.HoodieRecord;
+
+public class HoodieSparkIOFactory extends HoodieHadoopIOFactory {

Review Comment:
   Javadocs: explaining what readers and writers are returned for Spark.



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/action/bootstrap/ParquetBootstrapMetadataHandler.java:
##########
@@ -82,7 +82,7 @@ protected void executeBootstrap(HoodieBootstrapHandle<?, ?, 
?, ?> bootstrapHandl
                                   Schema schema) throws Exception {
     HoodieRecord.HoodieRecordType recordType = 
table.getConfig().getRecordMerger().getRecordType();
 
-    HoodieFileReader reader = 
HoodieFileReaderFactory.getReaderFactory(recordType)
+    HoodieFileReader reader = (new 
HoodieSparkIOFactory()).getReaderFactory(recordType)

Review Comment:
   Similar here and all places creating a new instance of 
`HoodieSparkIOFactory`.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to