yihua commented on code in PR #17659:
URL: https://github.com/apache/hudi/pull/17659#discussion_r2677979641


##########
hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/realtime/HoodieMergeOnReadTableInputFormat.java:
##########
@@ -419,14 +420,19 @@ private static Option<HoodieVirtualKeyInfo> 
getHoodieVirtualKeyInfo(HoodieTableM
     }
     TableSchemaResolver tableSchemaResolver = new 
TableSchemaResolver(metaClient);
     try {
-      Schema schema = tableSchemaResolver.getTableAvroSchema();
-      boolean isNonPartitionedKeyGen = 
StringUtils.isNullOrEmpty(tableConfig.getPartitionFieldProp());
+      HoodieSchema schema = tableSchemaResolver.getTableSchema();
+      String partitionFieldProp = tableConfig.getPartitionFieldProp();
+      boolean isNonPartitionedKeyGen = 
StringUtils.isNullOrEmpty(partitionFieldProp);
       return Option.of(
           new HoodieVirtualKeyInfo(
               tableConfig.getRecordKeyFieldProp(),
-              isNonPartitionedKeyGen ? Option.empty() : 
Option.of(tableConfig.getPartitionFieldProp()),
-              schema.getField(tableConfig.getRecordKeyFieldProp()).pos(),
-              isNonPartitionedKeyGen ? Option.empty() : 
Option.of(schema.getField(tableConfig.getPartitionFieldProp()).pos())));
+              isNonPartitionedKeyGen ? Option.empty() : 
Option.of(partitionFieldProp),
+              schema.getField(tableConfig.getRecordKeyFieldProp())
+                  .orElseThrow(() -> new HoodieSchemaException("Field: " + 
partitionFieldProp + " not found"))

Review Comment:
   ```suggestion
                     .orElseThrow(() -> new HoodieSchemaException("Field: " + 
tableConfig.getRecordKeyFieldProp() + " not found"))
   ```



##########
hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java:
##########
@@ -107,185 +104,116 @@ public TableSchemaResolver(HoodieTableMetaClient 
metaClient) {
     this.hasOperationField = Lazy.lazily(this::hasOperationField);
   }
 
-  public Schema getTableAvroSchemaFromDataFile() throws Exception {
-    return 
getTableAvroSchemaFromDataFileInternal().orElseThrow(schemaNotFoundError());
-  }
-
   /**
    * Gets full schema (user + metadata) for a hoodie table from data file as 
HoodieSchema.
-   * Delegates to getTableAvroSchemaFromDataFile and wraps the result in a 
HoodieSchema.
    *
    * @return HoodieSchema for this table from data file
    * @throws Exception
    */
   public HoodieSchema getTableSchemaFromDataFile() throws Exception {
-    Schema avroSchema = getTableAvroSchemaFromDataFile();
-    return HoodieSchema.fromAvroSchema(avroSchema);
+    return 
getTableSchemaFromDataFileInternal().orElseThrow(schemaNotFoundError());
   }
 
-  private Option<Schema> getTableAvroSchemaFromDataFileInternal() {
+  private Option<HoodieSchema> getTableSchemaFromDataFileInternal() {
     return getTableParquetSchemaFromDataFile();
   }
 
   /**
-   * Gets full schema (user + metadata) for a hoodie table as HoodieSchema.
-   * Delegates to getTableAvroSchema and wraps the result in a HoodieSchema.
+   * Gets full schema (user + metadata) for a hoodie table.
    *
    * @return HoodieSchema for this table
    * @throws Exception
    */
   public HoodieSchema getTableSchema() throws Exception {
-    Schema avroSchema = 
getTableAvroSchema(metaClient.getTableConfig().populateMetaFields());
-    return HoodieSchema.fromAvroSchema(avroSchema);
+    return getTableSchema(metaClient.getTableConfig().populateMetaFields());
   }
 
   /**
-   * Gets full schema (user + metadata) for a hoodie table as HoodieSchema.
-   * Delegates to getTableAvroSchema and wraps the result in a HoodieSchema.
+   * Gets schema for a hoodie table, can choose if include metadata fields 
should be included.
    *
    * @param includeMetadataFields choice if include metadata fields
-   * @return HoodieSchema for this table
+   * @return Hoodie schema for this table

Review Comment:
   ```suggestion
      * @return schema for this table
   ```



##########
hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java:
##########
@@ -476,10 +367,10 @@ public Option<String> 
getTableHistorySchemaStrFromCommitMetadata() {
    */
   public boolean hasOperationField() {
     try {
-      Schema tableAvroSchema = getTableAvroSchemaFromDataFile();
-      return tableAvroSchema.getField(HoodieRecord.OPERATION_METADATA_FIELD) 
!= null;
+      HoodieSchema tableSchema = getTableSchemaFromDataFile();
+      return 
tableSchema.getField(HoodieRecord.OPERATION_METADATA_FIELD).isPresent();
     } catch (Exception e) {
-      LOG.info("Failed to read operation field from avro schema ({})", 
e.getMessage());
+      LOG.info("Failed to read operation field from hoodie schema ({})", 
e.getMessage());

Review Comment:
   ```suggestion
         LOG.info("Failed to read operation field from schema ({})", 
e.getMessage());
   ```



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