You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "danny0405 (via GitHub)" <gi...@apache.org> on 2023/04/19 04:28:13 UTC

[GitHub] [hudi] danny0405 commented on a diff in pull request #8493: [HUDI-6098] Use bulk insert prepped for the initial write into MDT.

danny0405 commented on code in PR #8493:
URL: https://github.com/apache/hudi/pull/8493#discussion_r1170793841


##########
hudi-common/src/main/java/org/apache/hudi/metadata/HoodieTableMetadataUtil.java:
##########
@@ -1004,6 +1004,44 @@ public static int mapRecordKeyToFileGroupIndex(String recordKey, int numFileGrou
     return Math.abs(Math.abs(h) % numFileGroups);
   }
 
+  /**
+   * Return the complete fileID for a file group within a MDT partition.
+   *
+   * MDT fileGroups have the format <fileIDPrefix>-<index>. The fileIDPrefix is hardcoded for each MDT partition and index is an integer.
+   *
+   * @param partitionType The type of the MDT partition
+   * @param index Index of the file group within the partition
+   * @return The fileID
+   */
+  public static String getFileIDForFileGroup(MetadataPartitionType metadataPartition, int index) {
+    return String.format("%s%04d", metadataPartition.getFileIdPrefix(), index);
+  }
+
+  /**
+   * Extract the index from the fileID of a file group in the MDT partition. See {@code getFileIDForFileGroup} for the format of the fileID.
+   *
+   * @param fileId fileID of a file group.
+   * @return The index of file group
+   */
+  public static int getFileGroupIndexFromFileId(String fileId) {
+    // 0.10 version MDT code added -0 (0th fileIndex) to the fileID
+    int endIndex = fileId.endsWith("-0") ? fileId.length() - 2 : fileId.length();
+    int fromIndex = fileId.lastIndexOf("-", endIndex);

Review Comment:
   Can we abstract this code as separate method:
   
   ```java
       // 0.10 version MDT code added -0 (0th fileIndex) to the fileID
       int endIndex = fileId.endsWith("-0") ? fileId.length() - 2 : fileId.length()
   ```



-- 
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: commits-unsubscribe@hudi.apache.org

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