hudi-agent commented on code in PR #19255:
URL: https://github.com/apache/hudi/pull/19255#discussion_r3686049840


##########
hudi-common/src/main/java/org/apache/hudi/core/io/storage/HoodieFileWriterFactory.java:
##########
@@ -92,6 +74,58 @@ protected <T, I, K, O> HoodieFileWriter 
getFileWriterByFormat(HoodieFileFormat f
     }
   }
 
+  /**
+   * Single dispatch point mapping a {@link HoodieFileFormat} to the 
corresponding writer creation hook.
+   *
+   * <p>Support for a new file format must be added HERE, and only here, by 
adding a case that calls
+   * the corresponding {@code newXxxFileWriter} hook; the path-based {@code 
getFileWriter} entry
+   * points funnel through this switch. The only dispatch outside this method 
is the
+   * {@link OutputStream}-based entry point, which only supports Parquet.
+   *
+   * @param format              the base file format to create a writer for.
+   * @param instantTime         instant time of the write.
+   * @param path                the file path.
+   * @param config              Hudi configs.
+   * @param schema              schema to write the file with.
+   * @param taskContextSupplier task context supplier.
+   * @return a new file writer for the given format.
+   * @throws IOException upon writer creation error.
+   */
+  private HoodieFileWriter newWriterByFormat(
+      HoodieFileFormat format, String instantTime, StoragePath path, 
HoodieConfig config, HoodieSchema schema,
+      TaskContextSupplier taskContextSupplier) throws IOException {
+    switch (format) {
+      case PARQUET:
+        return newParquetFileWriter(instantTime, path, config, schema, 
taskContextSupplier);
+      case HFILE:
+        return newHFileFileWriter(instantTime, path, config, schema, 
taskContextSupplier);
+      case ORC:
+        return newOrcFileWriter(instantTime, path, config, schema, 
taskContextSupplier);
+      case LANCE:
+        return newLanceFileWriter(instantTime, path, config, schema, 
taskContextSupplier);
+      case VORTEX:
+        return newVortexFileWriter(instantTime, path, config, schema, 
taskContextSupplier);
+      default:
+        throw new UnsupportedOperationException(format + " format not 
supported yet.");
+    }
+  }
+
+  /**
+   * Maps a base file extension to its {@link HoodieFileFormat}. This mapping 
is format-agnostic,
+   * so new formats do not require any change here.
+   *
+   * @param extension the file extension including the leading dot, e.g. 
".parquet".
+   * @return the matching base file format.
+   */
+  private static HoodieFileFormat getFormatByFileExtension(String extension) {
+    for (HoodieFileFormat format : HoodieFileFormat.values()) {
+      if (format != HOODIE_LOG && format.getFileExtension().equals(extension)) 
{

Review Comment:
   🤖 nit: `getFormatByFileExtension` is byte-for-byte identical to the same 
private method added in `HoodieFileReaderFactory`. Could you move it to 
`HoodieFileFormat` as a static helper (e.g. 
`HoodieFileFormat.fromExtension(String)`) so there's a single place to update 
when a new format lands?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



-- 
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