You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "amrishlal (via GitHub)" <gi...@apache.org> on 2023/08/01 22:48:11 UTC
[GitHub] [hudi] amrishlal commented on a diff in pull request #9337: [HUDI-6628] Rely on methods in HoodieBaseFile and HoodieLogFile instead of FSUtils when possible
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: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org