deniskuzZ commented on code in PR #5047:
URL: https://github.com/apache/hive/pull/5047#discussion_r1483096529


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java:
##########
@@ -803,12 +818,34 @@ private Schema schema(Properties properties, 
org.apache.hadoop.hive.metastore.ap
       // Add partitioning columns to the original column list before creating 
the Iceberg Schema
       List<FieldSchema> cols = Lists.newArrayList(hmsTable.getSd().getCols());
       cols.addAll(hmsTable.getPartitionKeys());
-      return HiveSchemaUtil.convert(cols, autoConversion);
+      Schema schema = HiveSchemaUtil.convert(cols, autoConversion);
+      return getSchemaWithIdentifierFields(schema, identifierFields);
     } else {
-      return HiveSchemaUtil.convert(hmsTable.getSd().getCols(), 
autoConversion);
+      Schema schema = HiveSchemaUtil.convert(hmsTable.getSd().getCols(), 
autoConversion);
+      return getSchemaWithIdentifierFields(schema, identifierFields);
     }
   }
 
+  private Schema getSchemaWithIdentifierFields(Schema schema, Set<String> 
identifierFields) {
+    if (identifierFields == null || identifierFields.isEmpty()) {
+      return schema;
+    }
+    Set<Integer> identifierFieldIds = identifierFields.stream()
+            .map(column -> {
+              Types.NestedField field = schema.findField(column);
+              Preconditions.checkNotNull(field,
+                      "Cannot find identifier field ID for the column %s in 
schema %s", column, schema);
+              return field.fieldId();
+            })
+            .collect(Collectors.toSet());
+
+    List<Types.NestedField> cols = schema.columns().stream()

Review Comment:
   why do we need 2 scans?
   ````
   List<Types.NestedField> cols = Lists.transform(schema.columns(),
           column -> identifierFields.contains(column.name()) ? 
column.asRequired() : column);
   ````



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to