Skip to content

Commit d34a37a

Browse files
authored
fix(spark-runtime): Support Parquet source partitioning (#927) (#931)
* [Bug] Route partition spec to source-format-specific config key (#927) * fix: add @Builder.Default for initialized fields in conversion sources * fix: apply spotless formatting to XTableSparkSync.java
1 parent 9d9f9b3 commit d34a37a

5 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎xtable-core/src/main/java/org/apache/xtable/delta/DeltaConversionSource.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class DeltaConversionSource implements ConversionSource<Long> {
7373
@Builder.Default
7474
private final DeltaTableExtractor tableExtractor = DeltaTableExtractor.builder().build();
7575

76+
@Builder.Default
7677
private Optional<DeltaIncrementalChangesState> deltaIncrementalChangesState = Optional.empty();
7778

7879
private final SparkSession sparkSession;

‎xtable-core/src/main/java/org/apache/xtable/kernel/DeltaKernelConversionSource.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class DeltaKernelConversionSource implements ConversionSource<Long> {
7474
private final DeltaKernelTableExtractor tableExtractor =
7575
DeltaKernelTableExtractor.builder().build();
7676

77+
@Builder.Default
7778
private Optional<DeltaKernelIncrementalChangesState> deltaKernelIncrementalChangesState =
7879
Optional.empty();
7980

‎xtable-spark-runtime/src/main/java/org/apache/xtable/spark/TableSyncSpec.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public class TableSyncSpec {
4040
/** Optional namespace segments for the table. */
4141
String[] namespace;
4242

43-
/** Optional partition spec for a partitioned Hudi source, e.g. {@code level:VALUE}. */
43+
/**
44+
* Optional source partition spec (e.g. {@code level:VALUE}); applies to partitioned Hudi and
45+
* Parquet sources. Maps to {@code xtable.hudi.source.partition_field_spec_config} for Hudi and
46+
* {@code xtable.parquet.source.partition_field_spec_config} for Parquet.
47+
*/
4448
String partitionSpec;
4549

4650
/** The source table format, e.g. {@code HUDI} (see {@code TableFormat}). */

‎xtable-spark-runtime/src/main/java/org/apache/xtable/spark/XTableSparkSync.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public final class XTableSparkSync {
153153
Option.builder()
154154
.longOpt(PARTITION_SPEC)
155155
.hasArg()
156-
.desc("The Hudi source partition field spec, e.g. level:VALUE")
156+
.desc(
157+
"The source partition field spec, e.g. level:VALUE (Hudi and Parquet sources)")
157158
.build())
158159
.addOption(
159160
Option.builder()

‎xtable-spark-runtime/src/main/java/org/apache/xtable/spark/XTableSyncService.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.xtable.model.sync.SyncResult;
4545
import org.apache.xtable.paimon.PaimonConversionSourceProvider;
4646
import org.apache.xtable.parquet.ParquetConversionSourceProvider;
47+
import org.apache.xtable.parquet.ParquetSourceConfig;
4748

4849
/**
4950
* Runs an incremental {@link ConversionController#sync} for a {@link TableSyncSpec}. The sync falls
@@ -57,7 +58,12 @@ public class XTableSyncService {
5758
public Map<String, SyncResult> sync(TableSyncSpec spec, Configuration hadoopConf) {
5859
Properties sourceProperties = new Properties();
5960
if (spec.getPartitionSpec() != null && !spec.getPartitionSpec().isEmpty()) {
60-
sourceProperties.put(HudiSourceConfig.PARTITION_FIELD_SPEC_CONFIG, spec.getPartitionSpec());
61+
if (TableFormat.PARQUET.equals(spec.getSourceFormat())) {
62+
sourceProperties.put(
63+
ParquetSourceConfig.PARTITION_FIELD_SPEC_CONFIG, spec.getPartitionSpec());
64+
} else {
65+
sourceProperties.put(HudiSourceConfig.PARTITION_FIELD_SPEC_CONFIG, spec.getPartitionSpec());
66+
}
6167
}
6268
String dataPath =
6369
spec.getDataPath() != null && !spec.getDataPath().isEmpty()

0 commit comments

Comments
 (0)