emilie-wang opened a new issue, #624: URL: https://github.com/apache/incubator-xtable/issues/624
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/incubator-xtable/issues?q=is%3Aissue) and found no similar issues. ### Please describe the bug 🐞 ## Error When converting a Delta table to Iceberg table with enabling Delta column mapping(https://docs.delta.io/latest/delta-column-mapping.html), I got this error. ``` java.lang.IllegalArgumentException: Multiple entries with same key: 1=id and 1=info.element at org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap.conflictException(ImmutableMap.java:378) ~[iceberg-bundled-guava-1.4.2.jar:?] at org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap.checkNoConflict(ImmutableMap.java:372) ~[iceberg-bundled-guava-1.4.2.jar:?] ... at org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:587) ~[iceberg-bundled-guava-1.4.2.jar:?] at org.apache.iceberg.types.IndexByName.byId(IndexByName.java:81) ~[iceberg-api-1.4.2.jar:?] at org.apache.iceberg.types.TypeUtil.indexNameById(TypeUtil.java:172) ~[iceberg-api-1.4.2.jar:?] at org.apache.iceberg.Schema.lazyIdToName(Schema.java:183) ~[iceberg-api-1.4.2.jar:?] at org.apache.iceberg.Schema.<init>(Schema.java:112) ~[iceberg-api-1.4.2.jar:?] at org.apache.iceberg.Schema.<init>(Schema.java:91) ~[iceberg-api-1.4.2.jar:?] at org.apache.iceberg.Schema.<init>(Schema.java:83) ~[iceberg-api-1.4.2.jar:?] at org.apache.iceberg.Schema.<init>(Schema.java:79) ~[iceberg-api-1.4.2.jar:?] at org.apache.xtable.iceberg.IcebergSchemaExtractor.toIceberg(IcebergSchemaExtractor.java:79) ~[classes/:?] at org.apache.xtable.iceberg.IcebergConversionTarget.initializeTableIfRequired(IcebergConversionTarget.java:155) ~[classes/:?] at org.apache.xtable.iceberg.IcebergConversionTarget.beginSync(IcebergConversionTarget.java:143) ~[classes/:?] at org.apache.xtable.spi.sync.TableFormatSync.getSyncResult(TableFormatSync.java:154) ~[classes/:?] at org.apache.xtable.spi.sync.TableFormatSync.syncSnapshot(TableFormatSync.java:70) [classes/:?] at org.apache.xtable.conversion.ConversionController.syncSnapshot(ConversionController.java:182) [classes/:?] at org.apache.xtable.conversion.ConversionController.sync(ConversionController.java:118) [classes/:?] at org.apache.xtable.utilities.RunSync.main(RunSync.java:191) [classes/:?] 2025-01-13 14:45:35 ERROR org.apache.xtable.conversion.ConversionController:135 - Sync failed for the following formats ICEBERG ``` ## Details with troubleshooting ### Table schema: ``` scala> df.printSchema root |-- id: integer (nullable = true) |-- name: string (nullable = true) |-- info: array (nullable = true) | |-- element: string (containsNull = true) ``` ### Troubleshooting: While enabling delta column mapping, Delta doesn't assign id for element level for a list type field (similar for map field), here is what looks like in Delta (log from `_delta_log/00000000000000000000.json`) Raw log snippets raw log ``` "schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{\"delta.columnMapping.id\":1,\"delta.columnMapping.physicalName\":\"id\"}},{\"name\":\"name\",\"type\":\"string\",\"nullable\":true,\"metadata\":{\"delta.columnMapping.id\":2,\"delta.columnMapping.physicalName\":\"name\"}},{\"name\":\"info\",\"type\":{\"type\":\"array\",\"elementType\":\"string\",\"containsNull\":true},\"nullable\":true,\"metadata\":{\"delta.columnMapping.id\":3,\"delta.columnMapping.physicalName\":\"info\"}}]}" ``` Readable structure: ``` { "type": "struct", "fields": [ { "name": "id", "type": "integer", "nullable": true, "metadata": { "delta.columnMapping.id": 1, "delta.columnMapping.physicalName": "id" } }, { "name": "name", "type": "string", "nullable": true, "metadata": { "delta.columnMapping.id": 2, "delta.columnMapping.physicalName": "name" } }, { "name": "info", "type": { "type": "array", "elementType": "string", "containsNull": true }, "nullable": true, "metadata": { "delta.columnMapping.id": 3, "delta.columnMapping.physicalName": "info" } } ] } ``` However, Iceberg assigns id for element level when the field is list type. See how Xtable assigns ids for fields whose id is null without checking : https://github.com/apache/incubator-xtable/blob/main/xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergSchemaExtractor.java#L67 https://github.com/apache/incubator-xtable/blob/main/xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergSchemaExtractor.java#L244 ### Are you willing to submit PR? - [ ] I am willing to submit a PR! - [ ] I am willing to submit a PR but need help getting started! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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]
