Skip to content

Commit 0a45229

Browse files
review feedback - moved to iceberg source converter
1 parent c24bb31 commit 0a45229

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import org.apache.hadoop.conf.Configuration;
3737

38+
import org.apache.iceberg.BaseTable;
3839
import org.apache.iceberg.DataFile;
3940
import org.apache.iceberg.FileScanTask;
4041
import org.apache.iceberg.PartitionSpec;
@@ -93,10 +94,15 @@ private Table initSourceTable() {
9394
namespace == null
9495
? TableIdentifier.of(tableName)
9596
: TableIdentifier.of(Namespace.of(namespace), tableName);
96-
return tableManager.getTable(
97+
Table table = tableManager.getTable(
9798
(IcebergCatalogConfig) sourceTableConfig.getCatalogConfig(),
9899
tableIdentifier,
99100
sourceTableConfig.getBasePath());
101+
if (sourceTableConfig.getCatalogConfig() == null && table instanceof BaseTable) {
102+
table = new BaseTable(((BaseTable) table).operations(), tableIdentifier.name());
103+
}
104+
105+
return table;
100106
}
101107

102108
private FileIO initTableOps() {

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Table getTable(
5656
IcebergCatalogConfig catalogConfig, TableIdentifier tableIdentifier, String basePath) {
5757
return getCatalog(catalogConfig)
5858
.map(catalog -> catalog.loadTable(tableIdentifier))
59-
.orElseGet(() -> loadHadoopTables(getHadoopTables(), basePath, tableIdentifier.name()));
59+
.orElseGet(() -> getHadoopTables().load(basePath));
6060
}
6161

6262
boolean tableExists(
@@ -101,14 +101,6 @@ Table getOrCreateTable(
101101
}
102102
}
103103

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-
112104
private Map<String, String> getDefaultMappingProperties(Schema schema) {
113105
return Collections.singletonMap(
114106
TableProperties.DEFAULT_NAME_MAPPING, NameMappingParser.toJson(MappingUtil.create(schema)));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void getCurrentTableTest() {
126126
.build();
127127
validateTable(
128128
internalTable,
129-
testIcebergTable.getBasePath(),
129+
testIcebergTable.getTableName(),
130130
TableFormat.ICEBERG,
131131
internalSchema,
132132
DataLayoutStrategy.FLAT,

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,6 @@ void catalogGetTable() {
6969
verify(mockCatalog).initialize(catalogName, OPTIONS);
7070
}
7171

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-
8472
@Test
8573
void catalogGetOrCreateWithExistingTable() {
8674
String catalogName = "catalog2";

0 commit comments

Comments
 (0)