Skip to content

Commit 2e680ee

Browse files
committed
fix other issue with hudi partitiong when iceberg is source, and fix UT
1 parent 02e4150 commit 2e680ee

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

xtable-service/src/main/java/org/apache/xtable/service/ConversionService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,8 @@ public ConvertTableResponse convertTable(ConvertTableRequest convertTableRequest
192192
Properties sourceProperties = new Properties();
193193
if (convertTableRequest.getConfigurations() != null) {
194194
String partitionSpec =
195-
convertTableRequest.getConfigurations().getOrDefault("partition-spec", null);
196-
if (partitionSpec != null
197-
&& (HUDI.equals(convertTableRequest.getSourceFormat())
198-
|| convertTableRequest.getTargetFormats().contains(HUDI))) {
195+
convertTableRequest.getConfigurations().getOrDefault("partition-spec", null);
196+
if (partitionSpec != null) {
199197
sourceProperties.put(PARTITION_FIELD_SPEC_CONFIG, partitionSpec);
200198
}
201199
}
@@ -204,6 +202,7 @@ public ConvertTableResponse convertTable(ConvertTableRequest convertTableRequest
204202
SourceTable.builder()
205203
.name(convertTableRequest.getSourceTableName())
206204
.basePath(convertTableRequest.getSourceTablePath())
205+
.dataPath(convertTableRequest.getSourceDataPath())
207206
.formatName(convertTableRequest.getSourceFormat())
208207
.additionalProperties(sourceProperties)
209208
.build();
@@ -213,7 +212,8 @@ public ConvertTableResponse convertTable(ConvertTableRequest convertTableRequest
213212
TargetTable targetTable =
214213
TargetTable.builder()
215214
.name(convertTableRequest.getSourceTableName())
216-
.basePath(convertTableRequest.getSourceTablePath())
215+
// set the metadata path to the data path as the default (required by Hudi)
216+
.basePath(convertTableRequest.getSourceDataPath())
217217
.formatName(targetFormat)
218218
.additionalProperties(sourceProperties)
219219
.build();

xtable-service/src/main/java/org/apache/xtable/service/models/ConvertTableRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class ConvertTableRequest {
3939
@JsonProperty("source-table-path")
4040
private String sourceTablePath;
4141

42+
@JsonProperty("source-data-path")
43+
private String sourceDataPath;
44+
4245
@JsonProperty("target-formats")
4346
private List<String> targetFormats;
4447

@@ -52,12 +55,14 @@ public ConvertTableRequest(
5255
@JsonProperty("source-format") String sourceFormat,
5356
@JsonProperty("source-table-name") String sourceTableName,
5457
@JsonProperty("source-table-path") String sourceTablePath,
58+
@JsonProperty("source-data-path") String sourceDataPath,
5559
@JsonProperty("target-format") List<String> targetFormat,
5660
@JsonProperty("configurations") Map<String, String> configurations) {
5761

5862
this.sourceFormat = sourceFormat;
5963
this.sourceTableName = sourceTableName;
6064
this.sourceTablePath = sourceTablePath;
65+
this.sourceDataPath = sourceDataPath;
6166
this.targetFormats = targetFormat;
6267
this.configurations = configurations;
6368
}

xtable-service/src/test/java/org/apache/xtable/service/TestConversionService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
class TestConversionService {
6060
private static final String SOURCE_NAME = "users";
6161
private static final String SOURCE_PATH = "s3://bucket/tables/users";
62+
private static final String SOURCE_DATA_PATH = "s3://bucket/tables/users/data";
6263
private static final String HUDI_META_PATH = "s3://bucket/tables/users/.hoodie";
6364
private static final String ICEBERG_META_PATH =
6465
"s3://bucket/tables/users/metadata/v1.metadata.json";
@@ -111,6 +112,7 @@ void convertToTargetHudi() {
111112
.sourceFormat(TableFormat.DELTA)
112113
.sourceTableName(SOURCE_NAME)
113114
.sourceTablePath(SOURCE_PATH)
115+
.sourceDataPath(SOURCE_DATA_PATH)
114116
.targetFormats(Collections.singletonList(TableFormat.HUDI))
115117
.build();
116118

@@ -120,7 +122,7 @@ void convertToTargetHudi() {
120122
when(provider.getConversionSourceInstance(any())).thenReturn(conversionSrc);
121123
when(conversionSrc.getCurrentTable()).thenReturn(internalTbl);
122124

123-
when(internalTbl.getName()).thenReturn(TableFormat.HUDI);
125+
when(internalTbl.getTableFormat()).thenReturn(TableFormat.HUDI);
124126
when(internalTbl.getLatestMetdataPath()).thenReturn(HUDI_META_PATH);
125127
when(internalTbl.getReadSchema()).thenReturn(internalSchema);
126128

@@ -146,6 +148,7 @@ void convertToTargetIceberg() {
146148
.sourceFormat(TableFormat.DELTA)
147149
.sourceTableName(SOURCE_NAME)
148150
.sourceTablePath(SOURCE_PATH)
151+
.sourceDataPath(SOURCE_DATA_PATH)
149152
.targetFormats(Collections.singletonList(TableFormat.ICEBERG))
150153
.build();
151154

@@ -157,7 +160,7 @@ void convertToTargetIceberg() {
157160
when(provider.getConversionSourceInstance(any())).thenReturn(conversionSrc);
158161
when(conversionSrc.getCurrentTable()).thenReturn(internalTbl);
159162

160-
when(internalTbl.getName()).thenReturn(TableFormat.ICEBERG);
163+
when(internalTbl.getTableFormat()).thenReturn(TableFormat.ICEBERG);
161164
when(internalTbl.getLatestMetdataPath()).thenReturn(ICEBERG_META_PATH);
162165
when(internalTbl.getReadSchema()).thenReturn(internalSchema);
163166

@@ -185,6 +188,7 @@ void convertToTargetDelta() {
185188
.sourceFormat(TableFormat.ICEBERG)
186189
.sourceTableName(SOURCE_NAME)
187190
.sourceTablePath(SOURCE_PATH)
191+
.sourceDataPath(SOURCE_DATA_PATH)
188192
.targetFormats(Collections.singletonList(TableFormat.DELTA))
189193
.build();
190194

@@ -194,7 +198,7 @@ void convertToTargetDelta() {
194198
when(provider.getConversionSourceInstance(any())).thenReturn(conversionSrc);
195199
when(conversionSrc.getCurrentTable()).thenReturn(internalTbl);
196200

197-
when(internalTbl.getName()).thenReturn(TableFormat.DELTA);
201+
when(internalTbl.getTableFormat()).thenReturn(TableFormat.DELTA);
198202
when(internalTbl.getLatestMetdataPath()).thenReturn(DELTA_META_PATH);
199203
when(internalTbl.getReadSchema()).thenReturn(internalSchema);
200204

0 commit comments

Comments
 (0)