alexeykudinkin commented on a change in pull request #4773:
URL: https://github.com/apache/hudi/pull/4773#discussion_r808477618



##########
File path: 
hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java
##########
@@ -523,10 +518,29 @@ public boolean isHasOperationField() {
 
   private boolean hasOperationField() {
     try {
-      Schema tableAvroSchema = getTableAvroSchemaFromDataFile();
-      return tableAvroSchema.getField(HoodieRecord.OPERATION_METADATA_FIELD) 
!= null;
+      Option<String> dataFilePath = getValidDataFilePath();
+      if (dataFilePath.isPresent()) {
+        Schema tableAvroSchema = 
getTableAvroSchemaFromDataFile(dataFilePath.get());
+        return tableAvroSchema.getField(HoodieRecord.OPERATION_METADATA_FIELD) 
!= null;
+      } else {
+        LOG.info("No data file found from last commit");
+        return false;
+      }
     } catch (Exception e) {
       return false;
     }
   }
+
+  private Option<String> getValidDataFilePath() {
+    HoodieActiveTimeline activeTimeline = metaClient.getActiveTimeline();
+    Option<Pair<HoodieInstant, HoodieCommitMetadata>> instantAndCommitMetadata 
=
+        activeTimeline.getLastCommitMetadataWithValidData();
+    if (instantAndCommitMetadata.isPresent()) {

Review comment:
       No need to branch, you can simply do `.map` on the Option

##########
File path: 
hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java
##########
@@ -70,43 +71,36 @@ public TableSchemaResolver(HoodieTableMetaClient 
metaClient) {
     this.hasOperationField = hasOperationField();
   }
 
+  private MessageType getTableParquetSchemaFromDataFile() {
+    Option<String> dataFilePath = getValidDataFilePath();
+    if (dataFilePath.isPresent()) {

Review comment:
       More idiomatic would be 
   
   ```
   String dataFilePath = getValidDataFilePath().orElseThrow(() -> throw ...);
   ```

##########
File path: 
hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java
##########
@@ -523,10 +518,29 @@ public boolean isHasOperationField() {
 
   private boolean hasOperationField() {
     try {
-      Schema tableAvroSchema = getTableAvroSchemaFromDataFile();
-      return tableAvroSchema.getField(HoodieRecord.OPERATION_METADATA_FIELD) 
!= null;
+      Option<String> dataFilePath = getValidDataFilePath();
+      if (dataFilePath.isPresent()) {

Review comment:
       Same here, `return opt.map(...).getOrElse(false)` would be more idiomatic




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