diff --git a/xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergConversionSource.java b/xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergConversionSource.java index 0d400e28b..2a4b50ae2 100644 --- a/xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergConversionSource.java +++ b/xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergConversionSource.java @@ -120,10 +120,18 @@ public InternalTable getTable(Snapshot snapshot) { irPartitionFields.size() > 0 ? DataLayoutStrategy.HIVE_STYLE_PARTITION : DataLayoutStrategy.FLAT; + // When the table name is not explicitly specified, Iceberg assumes the table is HDFS-based, + // treating the table name as the location in HDFS. This assumption can lead to mismatches + // during metadata conversion. To mitigate this issue, we rely on the table name provided in the + // source configuration of the conversation so target matches the user's expectations. + // See https://github.com/apache/incubator-xtable/issues/494 return InternalTable.builder() .tableFormat(TableFormat.ICEBERG) .basePath(iceTable.location()) - .name(iceTable.name()) + .name( + iceTable.name().contains(iceTable.location()) + ? sourceTableConfig.getName() + : iceTable.name()) .partitioningFields(irPartitionFields) .latestCommitTime(Instant.ofEpochMilli(snapshot.timestampMillis())) .readSchema(irSchema) diff --git a/xtable-core/src/test/java/org/apache/xtable/iceberg/ITIcebergConversionSource.java b/xtable-core/src/test/java/org/apache/xtable/iceberg/ITIcebergConversionSource.java index 210b6f9d6..8945f12f3 100644 --- a/xtable-core/src/test/java/org/apache/xtable/iceberg/ITIcebergConversionSource.java +++ b/xtable-core/src/test/java/org/apache/xtable/iceberg/ITIcebergConversionSource.java @@ -126,7 +126,7 @@ void getCurrentTableTest() { .build(); validateTable( internalTable, - testIcebergTable.getBasePath(), + testIcebergTable.getTableName(), TableFormat.ICEBERG, internalSchema, DataLayoutStrategy.FLAT,