amrishlal commented on code in PR #9337:
URL: https://github.com/apache/hudi/pull/9337#discussion_r1281221181


##########
hudi-common/src/main/java/org/apache/hudi/common/model/HoodieBaseFile.java:
##########
@@ -52,14 +59,39 @@ public HoodieBaseFile(String filePath) {
   public HoodieBaseFile(String filePath, BaseFile bootstrapBaseFile) {
     super(filePath);
     this.bootstrapBaseFile = Option.ofNullable(bootstrapBaseFile);
+    String[] fileIdAndCommitTime = getFileIdAndCommitTimeFromFileName();
+    this.fileId = fileIdAndCommitTime[0];
+    this.commitTime = fileIdAndCommitTime[1];
+  }
+
+  private String[] getFileIdAndCommitTimeFromFileName() {
+    String[] values = new String[2];
+    short underscoreCount = 0;
+    short lastUnderscoreIndex = 0;
+    for (int i = 0; i < fileName.length(); i++) {
+      char c = fileName.charAt(i);
+      if (c == '_') {
+        if (underscoreCount == 0) {
+          values[0] = fileName.substring(0, i);
+        }
+        lastUnderscoreIndex = (short) i;
+        underscoreCount++;
+      } else if (c == '.') {
+        if (underscoreCount == 2) {
+          values[1] = fileName.substring(lastUnderscoreIndex + 1, i);
+          break;
+        }
+      }
+    }
+    return values;

Review Comment:
   I am wondering if this code can be refactored a bit to make it more readable 
as to what is happening. 'File Id' is a UUID, so should not contain a dot. 
Would the following work:
   
    ```
    /** @return {@link String} array where first element is file id and second 
element is commit time. */
    private String[] getFileIdAndCommitTimeFromFileName() {
       int endOfFileId = fileName.lastIndexOf('-');
       int endOfCommitTime = fileName.indexOf('.', endOfFileId + 1);
   
       if (endOfFileId >= 0 && endOfCommitTime >= 0) {
         return new String[]{fileName.substring(0, endOfFileId), 
fileName.substring(endOfFileId + 1, endOfCommitTime)};
       }
   
       return new String[]{null, null};
     }
   ```



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