Skip to content

Commit c24bb31

Browse files
Jalpan RanderiJalpan Randeri
authored andcommitted
[Bugfix] Populate table name from the identifier in Iceberge conversion
What is the problem? While converting the iceberg table to other format such as Hudi, the icerberg source table do not populate the table name. This is due to iceberg table's behavior as it is treated as Hadoop tables. This leads to table identified as table-location, leading to confusing conversation. Solution: This commit handles the conversation logic, when icebege table manager provides HadoopTable, it populate the table name from provided input TableIdentifier. This ensures that source table name is carried over to the transformation. Testing: - Added unit test to cover this scenario.
1 parent 14967dd commit c24bb31

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergTableManager.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.apache.hadoop.conf.Configuration;
3131

32+
import org.apache.iceberg.BaseTable;
3233
import org.apache.iceberg.CatalogUtil;
3334
import org.apache.iceberg.PartitionSpec;
3435
import org.apache.iceberg.Schema;
@@ -55,7 +56,7 @@ Table getTable(
5556
IcebergCatalogConfig catalogConfig, TableIdentifier tableIdentifier, String basePath) {
5657
return getCatalog(catalogConfig)
5758
.map(catalog -> catalog.loadTable(tableIdentifier))
58-
.orElseGet(() -> getHadoopTables().load(basePath));
59+
.orElseGet(() -> loadHadoopTables(getHadoopTables(), basePath, tableIdentifier.name()));
5960
}
6061

6162
boolean tableExists(
@@ -100,6 +101,14 @@ Table getOrCreateTable(
100101
}
101102
}
102103

104+
Table loadHadoopTables(HadoopTables hadoopTables, String basePath, String tableName) {
105+
Table table = hadoopTables.load(basePath);
106+
if (table instanceof BaseTable) {
107+
return new BaseTable(((BaseTable) table).operations(), tableName);
108+
}
109+
return table;
110+
}
111+
103112
private Map<String, String> getDefaultMappingProperties(Schema schema) {
104113
return Collections.singletonMap(
105114
TableProperties.DEFAULT_NAME_MAPPING, NameMappingParser.toJson(MappingUtil.create(schema)));

xtable-core/src/test/java/org/apache/xtable/iceberg/TestIcebergTableManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.Map;
3030

3131
import org.apache.hadoop.conf.Configuration;
32+
import org.apache.iceberg.BaseTable;
33+
import org.apache.iceberg.hadoop.HadoopTables;
3234
import org.junit.jupiter.api.Test;
3335

3436
import org.apache.iceberg.PartitionSpec;
@@ -67,6 +69,18 @@ void catalogGetTable() {
6769
verify(mockCatalog).initialize(catalogName, OPTIONS);
6870
}
6971

72+
@Test
73+
void catalogGetTableWithoutCatalogConfig() {
74+
Table hdfsTable = new BaseTable(null, BASE_PATH);
75+
IcebergTableManager tableManager = IcebergTableManager.of(CONFIGURATION);
76+
HadoopTables hadoopTables = mock(HadoopTables.class);
77+
when(hadoopTables.load(BASE_PATH)).thenReturn(hdfsTable);
78+
79+
Table expected = new BaseTable(null, IDENTIFIER.name());
80+
Table actual = tableManager.loadHadoopTables(hadoopTables, BASE_PATH, IDENTIFIER.name());
81+
assertEquals(expected.name(), actual.name());
82+
}
83+
7084
@Test
7185
void catalogGetOrCreateWithExistingTable() {
7286
String catalogName = "catalog2";

0 commit comments

Comments
 (0)