Skip to content

Commit aa31ae8

Browse files
authored
Add additional properties when doing conversion for hudi (#714)
* Add additional properties when doing conversion for hudi * fix other issue with hudi partitiong when iceberg is source, and fix UT * spotless apply
1 parent 108ec64 commit aa31ae8

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.xtable.service;
2020

2121
import static org.apache.xtable.conversion.ConversionUtils.convertToSourceTable;
22+
import static org.apache.xtable.hudi.HudiSourceConfig.PARTITION_FIELD_SPEC_CONFIG;
2223
import static org.apache.xtable.model.storage.TableFormat.DELTA;
2324
import static org.apache.xtable.model.storage.TableFormat.HUDI;
2425
import static org.apache.xtable.model.storage.TableFormat.ICEBERG;
@@ -27,6 +28,7 @@
2728
import java.util.HashMap;
2829
import java.util.List;
2930
import java.util.Map;
31+
import java.util.Properties;
3032

3133
import lombok.extern.log4j.Log4j2;
3234

@@ -186,20 +188,34 @@ public ConversionService(
186188
* @return a ConvertTableResponse containing details of the converted target tables
187189
*/
188190
public ConvertTableResponse convertTable(ConvertTableRequest convertTableRequest) {
191+
192+
Properties sourceProperties = new Properties();
193+
if (convertTableRequest.getConfigurations() != null) {
194+
String partitionSpec =
195+
convertTableRequest.getConfigurations().getOrDefault("partition-spec", null);
196+
if (partitionSpec != null) {
197+
sourceProperties.put(PARTITION_FIELD_SPEC_CONFIG, partitionSpec);
198+
}
199+
}
200+
189201
SourceTable sourceTable =
190202
SourceTable.builder()
191203
.name(convertTableRequest.getSourceTableName())
192204
.basePath(convertTableRequest.getSourceTablePath())
205+
.dataPath(convertTableRequest.getSourceDataPath())
193206
.formatName(convertTableRequest.getSourceFormat())
207+
.additionalProperties(sourceProperties)
194208
.build();
195209

196210
List<TargetTable> targetTables = new ArrayList<>();
197211
for (String targetFormat : convertTableRequest.getTargetFormats()) {
198212
TargetTable targetTable =
199213
TargetTable.builder()
200214
.name(convertTableRequest.getSourceTableName())
201-
.basePath(convertTableRequest.getSourceTablePath())
215+
// set the metadata path to the data path as the default (required by Hudi)
216+
.basePath(convertTableRequest.getSourceDataPath())
202217
.formatName(targetFormat)
218+
.additionalProperties(sourceProperties)
203219
.build();
204220
targetTables.add(targetTable);
205221
}
@@ -220,7 +236,7 @@ public ConvertTableResponse convertTable(ConvertTableRequest convertTableRequest
220236
String schemaString = extractSchemaString(targetTable, internalTable);
221237
convertedTables.add(
222238
ConvertedTable.builder()
223-
.targetFormat(internalTable.getName())
239+
.targetFormat(internalTable.getTableFormat())
224240
.targetSchema(schemaString)
225241
.targetMetadataPath(internalTable.getLatestMetdataPath())
226242
.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)