gemini-code-assist[bot] commented on code in PR #39022:
URL: https://github.com/apache/beam/pull/39022#discussion_r3437252002


##########
sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/AddFiles.java:
##########
@@ -532,17 +532,25 @@ private Table getOrCreateTable(String filePath, 
FileFormat format) throws IOExce
           org.apache.iceberg.Schema schema = getSchema(filePath, format);
           PartitionSpec spec = PartitionUtils.toPartitionSpec(partitionFields, 
schema);
           SortOrder sortOrder = SortOrderUtils.toSortOrder(sortFields, schema);
-
-          Catalog.TableBuilder builder =
-              catalogConfig
-                  .catalog()
-                  .buildTable(tableId, schema)
-                  .withPartitionSpec(spec)
-                  .withSortOrder(sortOrder);
+          Map<String, String> properties = new HashMap<>();
           if (tableProps != null) {
-            builder.withProperties(tableProps);
+            properties.putAll(tableProps);
+          }
+          if (properties.get(TableProperties.DEFAULT_NAME_MAPPING) == null) {
+            // Forces Name based resolution instead of position based 
resolution
+            NameMapping mapping = MappingUtil.create(schema);
+            String mappingJson = NameMappingParser.toJson(mapping);

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   If `tableProps` is an immutable map (which is common for user-provided 
configuration maps in Beam), calling `properties.put()` will throw an 
`UnsupportedOperationException` because `MoreObjects.firstNonNull(tableProps, 
...)` returns the original `tableProps` reference when it is not null.
   
   To prevent this, we should copy the entries of `tableProps` into a new 
mutable `HashMap`. This also allows us to avoid importing `MoreObjects`.
   
   ```java
             Map<String, String> properties = new HashMap<>();
             if (tableProps != null) {
               properties.putAll(tableProps);
             }
             if (properties.get(TableProperties.DEFAULT_NAME_MAPPING) == null) {
               // Forces Name based resolution instead of position based 
resolution
               NameMapping mapping = MappingUtil.create(schema);
               String mappingJson = NameMappingParser.toJson(mapping);
               properties.put(TableProperties.DEFAULT_NAME_MAPPING, 
mappingJson);
             }
   ```



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