This is an automated email from the ASF dual-hosted git repository.

vinishjail97 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-xtable.git


The following commit(s) were added to refs/heads/main by this push:
     new 4ed068f6 [927] Support VALUE partitions in the Parquet source (#985)
4ed068f6 is described below

commit 4ed068f6bb5f4c872a28044d9e2db62d9c803ddc
Author: Vinish Reddy <[email protected]>
AuthorDate: Sat Dec 5 04:11:36 2026 +0530

    [927] Support VALUE partitions in the Parquet source (#985)
    
    The Parquet source parsed every partition field as a date, so a VALUE
    (identity) spec such as `region:VALUE` failed with an NPE. Identity fields
    are now read from their Hive style directory, unescaped, and typed by the
    source column (DATE directories become days since epoch, matching other
    sources). A time transform without a path format now fails fast with an
    example of the expected form.
    
    RunSync forwarded the partition spec only under the Hudi key, so it never
    reached a Parquet source; it now uses the Parquet key for PARQUET, as the
    spark-runtime does since #931.
---
 .../hudi/PathBasedPartitionValuesExtractor.java    |   2 +-
 .../parquet/ParquetPartitionSpecExtractor.java     |   6 +-
 .../parquet/ParquetPartitionValueExtractor.java    |  53 +++++++-
 .../apache/xtable/parquet/ParquetSourceConfig.java |   6 +
 .../xtable/parquet/ITParquetConversionSource.java  | 103 ++++++++++++++-
 .../TestParquetPartitionValueExtractor.java        | 146 +++++++++++++++++++++
 .../java/org/apache/xtable/utilities/RunSync.java  |  22 +++-
 .../org/apache/xtable/utilities/TestRunSync.java   |  18 +++
 8 files changed, 344 insertions(+), 12 deletions(-)

diff --git 
a/xtable-core/src/main/java/org/apache/xtable/hudi/PathBasedPartitionValuesExtractor.java
 
b/xtable-core/src/main/java/org/apache/xtable/hudi/PathBasedPartitionValuesExtractor.java
index c5ca0bdc..75c18983 100644
--- 
a/xtable-core/src/main/java/org/apache/xtable/hudi/PathBasedPartitionValuesExtractor.java
+++ 
b/xtable-core/src/main/java/org/apache/xtable/hudi/PathBasedPartitionValuesExtractor.java
@@ -41,7 +41,7 @@ import org.apache.xtable.model.stat.Range;
 /** Extracts Partition Values for Hudi/Parquet from Partition Path. */
 @AllArgsConstructor
 public class PathBasedPartitionValuesExtractor {
-  private static final String HIVE_DEFAULT_PARTITION = 
"__HIVE_DEFAULT_PARTITION__";
+  protected static final String HIVE_DEFAULT_PARTITION = 
"__HIVE_DEFAULT_PARTITION__";
   @NonNull protected final Map<String, String> pathToPartitionFieldFormat;
 
   public List<PartitionValue> extractPartitionValues(
diff --git 
a/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetPartitionSpecExtractor.java
 
b/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetPartitionSpecExtractor.java
index ddbdccba..9a1824a9 100644
--- 
a/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetPartitionSpecExtractor.java
+++ 
b/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetPartitionSpecExtractor.java
@@ -20,6 +20,7 @@ package org.apache.xtable.parquet;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -58,7 +59,10 @@ public class ParquetPartitionSpecExtractor implements 
PathBasedPartitionSpecExtr
       partitionFields.add(
           InternalPartitionField.builder()
               .sourceField(sourceField)
-              
.partitionFieldNames(getListPartitionNamesFromFormatInput(fieldSpec.getFormat()))
+              .partitionFieldNames(
+                  fieldSpec.getFormat() == null
+                      ? Collections.emptyList()
+                      : 
getListPartitionNamesFromFormatInput(fieldSpec.getFormat()))
               .transformType(fieldSpec.getTransformType())
               .build());
     }
diff --git 
a/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetPartitionValueExtractor.java
 
b/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetPartitionValueExtractor.java
index 19c2f705..977430bf 100644
--- 
a/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetPartitionValueExtractor.java
+++ 
b/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetPartitionValueExtractor.java
@@ -20,6 +20,7 @@ package org.apache.xtable.parquet;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -28,9 +29,13 @@ import java.util.TimeZone;
 
 import lombok.NonNull;
 
+import org.apache.hudi.common.util.PartitionPathEncodeUtils;
+
 import org.apache.xtable.exception.PartitionValuesExtractorException;
 import org.apache.xtable.hudi.PathBasedPartitionValuesExtractor;
 import org.apache.xtable.model.schema.InternalPartitionField;
+import org.apache.xtable.model.schema.InternalType;
+import org.apache.xtable.model.schema.PartitionTransformType;
 import org.apache.xtable.model.stat.PartitionValue;
 import org.apache.xtable.model.stat.Range;
 
@@ -52,14 +57,24 @@ public class ParquetPartitionValueExtractor extends 
PathBasedPartitionValuesExtr
   public List<PartitionValue> extractPartitionValues(
       List<InternalPartitionField> partitionColumns, String partitionPath) {
     String currentDateValue = "";
-    List<String> parsedDateValues = new ArrayList<>();
     if (partitionColumns.size() == 0) {
       return Collections.emptyList();
     }
-    int totalNumberOfPartitions = 
partitionColumns.get(0).getPartitionFieldNames().size();
-    List<PartitionValue> result = new ArrayList<>(totalNumberOfPartitions);
+    List<PartitionValue> result = new ArrayList<>(partitionColumns.size());
     String remainingPartitionPath = partitionPath;
     for (InternalPartitionField partitionField : partitionColumns) {
+      if (partitionField.getTransformType() == PartitionTransformType.VALUE) {
+        PartialResult valueAndRemainingPath =
+            parseIdentityValue(partitionField, remainingPartitionPath);
+        result.add(
+            PartitionValue.builder()
+                .partitionField(partitionField)
+                .range(Range.scalar(valueAndRemainingPath.getValue()))
+                .build());
+        remainingPartitionPath = valueAndRemainingPath.getRemainingPath();
+        continue;
+      }
+      List<String> parsedDateValues = new ArrayList<>();
       int index = 0;
       for (String partitionFieldName : 
partitionField.getPartitionFieldNames()) {
         if (remainingPartitionPath.startsWith(partitionFieldName + "=")) {
@@ -93,6 +108,38 @@ public class ParquetPartitionValueExtractor extends 
PathBasedPartitionValuesExtr
     return result;
   }
 
+  /**
+   * Parses one Hive style directory, e.g. {@code region=us-west}, as the 
value of an identity
+   * partition. Directory names are unescaped the way Hive and Spark escape 
them.
+   */
+  private PartialResult parseIdentityValue(InternalPartitionField field, 
String remainingPath) {
+    String fieldName = field.getSourceField().getPath();
+    if (remainingPath.startsWith(fieldName + "=")) {
+      remainingPath = remainingPath.substring(fieldName.length() + 1);
+    }
+    int slashIndex = remainingPath.indexOf('/');
+    String rawValue = slashIndex == -1 ? remainingPath : 
remainingPath.substring(0, slashIndex);
+    String unparsedPath = slashIndex == -1 ? "" : 
remainingPath.substring(slashIndex + 1);
+    if (rawValue.equals(HIVE_DEFAULT_PARTITION)) {
+      return new PartialResult(null, unparsedPath);
+    }
+    String value = PartitionPathEncodeUtils.unescapePathName(rawValue);
+    InternalType dataType = field.getSourceField().getSchema().getDataType();
+    try {
+      if (dataType == InternalType.DATE) {
+        // Hive style paths hold dates as yyyy-MM-dd; the internal value is 
days since epoch.
+        return new PartialResult((int) LocalDate.parse(value).toEpochDay(), 
unparsedPath);
+      }
+      return new PartialResult(parseValue(value, dataType, false).getValue(), 
unparsedPath);
+    } catch (RuntimeException e) {
+      throw new PartitionValuesExtractorException(
+          String.format(
+              "Unable to parse partition value '%s' for field %s of type %s",
+              value, fieldName, dataType),
+          e);
+    }
+  }
+
   protected String parsePartitionDateValue(
       InternalPartitionField field, String remainingPath, int index) {
     return parseDateValue(
diff --git 
a/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetSourceConfig.java 
b/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetSourceConfig.java
index c1ab594c..b6830ec4 100644
--- 
a/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetSourceConfig.java
+++ 
b/xtable-core/src/main/java/org/apache/xtable/parquet/ParquetSourceConfig.java
@@ -68,6 +68,12 @@ public class ParquetSourceConfig {
       PartitionTransformType type =
           PartitionTransformType.valueOf(parts[1].toUpperCase(Locale.ROOT));
       String format = parts.length == 3 ? parts[2] : null;
+      if (type.isTimeBased() && format == null) {
+        throw new IllegalArgumentException(
+            String.format(
+                "Partition field %s with transform %s needs a path format, 
e.g. %s:%s:%s=yyyy-MM-dd",
+                path, type, path, type, path));
+      }
 
       partitionFields.add(new PartitionFieldSpec(path, type, format));
     }
diff --git 
a/xtable-core/src/test/java/org/apache/xtable/parquet/ITParquetConversionSource.java
 
b/xtable-core/src/test/java/org/apache/xtable/parquet/ITParquetConversionSource.java
index 66773f2a..af771cbc 100644
--- 
a/xtable-core/src/test/java/org/apache/xtable/parquet/ITParquetConversionSource.java
+++ 
b/xtable-core/src/test/java/org/apache/xtable/parquet/ITParquetConversionSource.java
@@ -349,7 +349,8 @@ public class ITParquetConversionSource {
         targetFormats,
         Collections.emptyMap(),
         null,
-        isPartitioned);
+        isPartitioned,
+        schema);
   }
 
   private void checkDatasetEquivalence(
@@ -359,7 +360,8 @@ public class ITParquetConversionSource {
       List<String> targetFormats,
       Map<String, Map<String, String>> targetOptions,
       Integer expectedCount,
-      boolean isPartitioned) {
+      boolean isPartitioned,
+      StructType schema) {
     Dataset<Row> sourceRows =
         sparkSession
             .read()
@@ -436,6 +438,103 @@ public class ITParquetConversionSource {
     }
   }
 
+  @Test
+  void testSyncWithValuePartitions() {
+    String tableName = getTableName();
+    StructType valueSchema =
+        DataTypes.createStructType(
+            new StructField[] {
+              DataTypes.createStructField("id", DataTypes.IntegerType, false),
+              DataTypes.createStructField("region", DataTypes.StringType, 
false),
+              DataTypes.createStructField("order_date", DataTypes.DateType, 
false)
+            });
+    Path dataPath = tempDir.resolve("value_partitioned_data");
+    // Partition columns stay in the files, as when a Hive-style layout is 
written without Spark's
+    // partitionBy.
+    writeHiveStyle(
+        Arrays.asList(
+            RowFactory.create(1, "us-west", 
java.sql.Date.valueOf("2026-08-01")),
+            RowFactory.create(2, "us-west", 
java.sql.Date.valueOf("2026-08-02")),
+            RowFactory.create(3, "us-east", 
java.sql.Date.valueOf("2026-08-01"))),
+        valueSchema,
+        dataPath);
+    List<String> targetFormats = Arrays.asList(ICEBERG, DELTA, HUDI);
+
+    try (GenericTable table =
+        GenericTable.getInstance(tableName, dataPath, sparkSession, jsc, 
PARQUET, true)) {
+      syncValuePartitioned(tableName, table, valueSchema, targetFormats, 
SyncMode.FULL);
+      writeHiveStyle(
+          Collections.singletonList(
+              RowFactory.create(4, "eu-central", 
java.sql.Date.valueOf("2026-08-03"))),
+          valueSchema,
+          dataPath);
+      syncValuePartitioned(tableName, table, valueSchema, targetFormats, 
SyncMode.INCREMENTAL);
+
+      assertEquals(
+          "[identity(region), identity(order_date)]",
+          new org.apache.iceberg.hadoop.HadoopTables(jsc.hadoopConfiguration())
+              .load(table.getDataPath()).spec().fields().stream()
+                  .map(field -> field.transform() + "(" + field.name() + ")")
+                  .collect(Collectors.toList())
+                  .toString());
+      Row deltaDetail =
+          sparkSession
+              .sql(String.format("DESCRIBE DETAIL delta.`%s`", 
table.getDataPath()))
+              .first();
+      // The Delta target does not keep the partition column order, so compare 
as sets.
+      assertEquals(
+          new HashSet<>(Arrays.asList("region", "order_date")),
+          new 
HashSet<>(deltaDetail.getList(deltaDetail.fieldIndex("partitionColumns"))));
+    }
+  }
+
+  private void syncValuePartitioned(
+      String tableName,
+      GenericTable table,
+      StructType valueSchema,
+      List<String> targetFormats,
+      SyncMode syncMode) {
+    ConversionConfig conversionConfig =
+        getTableSyncConfig(
+            PARQUET,
+            syncMode,
+            tableName,
+            table,
+            targetFormats,
+            "region:VALUE,order_date:VALUE",
+            null);
+    new ConversionController(jsc.hadoopConfiguration())
+        .sync(conversionConfig, getConversionSourceProvider(PARQUET));
+    checkDatasetEquivalence(
+        PARQUET,
+        table,
+        Collections.emptyMap(),
+        targetFormats,
+        Collections.emptyMap(),
+        null,
+        true,
+        valueSchema);
+  }
+
+  private void writeHiveStyle(List<Row> rows, StructType valueSchema, Path 
dataPath) {
+    Dataset<Row> df = sparkSession.createDataFrame(rows, valueSchema);
+    for (Row partition : df.select("region", 
"order_date").distinct().collectAsList()) {
+      df.filter(
+              functions
+                  .col("region")
+                  .equalTo(partition.get(0))
+                  .and(functions.col("order_date").equalTo(partition.get(1))))
+          .coalesce(1)
+          .write()
+          .mode(SaveMode.Append)
+          .parquet(
+              dataPath
+                  .resolve("region=" + partition.get(0))
+                  .resolve("order_date=" + partition.get(1))
+                  .toString());
+    }
+  }
+
   @Test
   void testIncrementalSyncWithMultiplePartitions() throws IOException {
 
diff --git 
a/xtable-core/src/test/java/org/apache/xtable/parquet/TestParquetPartitionValueExtractor.java
 
b/xtable-core/src/test/java/org/apache/xtable/parquet/TestParquetPartitionValueExtractor.java
new file mode 100644
index 00000000..670071f2
--- /dev/null
+++ 
b/xtable-core/src/test/java/org/apache/xtable/parquet/TestParquetPartitionValueExtractor.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+package org.apache.xtable.parquet;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.time.Instant;
+import java.time.LocalDate;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.xtable.exception.PartitionValuesExtractorException;
+import org.apache.xtable.hudi.PathBasedPartitionSpecExtractor;
+import org.apache.xtable.model.schema.InternalField;
+import org.apache.xtable.model.schema.InternalPartitionField;
+import org.apache.xtable.model.schema.InternalSchema;
+import org.apache.xtable.model.schema.InternalType;
+import org.apache.xtable.model.schema.PartitionTransformType;
+import org.apache.xtable.model.stat.PartitionValue;
+
+public class TestParquetPartitionValueExtractor {
+
+  private static final InternalSchema SCHEMA =
+      InternalSchema.builder()
+          .name("record")
+          .dataType(InternalType.RECORD)
+          .fields(
+              Arrays.asList(
+                  field("region", InternalType.STRING),
+                  field("bucket", InternalType.INT),
+                  field("order_date", InternalType.DATE),
+                  field("ts", InternalType.TIMESTAMP)))
+          .build();
+
+  @Test
+  void testStringValuePartition() {
+    List<PartitionValue> values = extract("region:VALUE", "region=us-west");
+    assertEquals(
+        PartitionTransformType.VALUE, 
values.get(0).getPartitionField().getTransformType());
+    assertEquals("us-west", values.get(0).getRange().getMaxValue());
+  }
+
+  @Test
+  void testDateValuePartitionIsDaysSinceEpoch() {
+    List<PartitionValue> values = extract("order_date:VALUE", 
"order_date=2026-08-01");
+    assertEquals((int) LocalDate.parse("2026-08-01").toEpochDay(), 
scalars(values).get(0));
+  }
+
+  @Test
+  void testMultipleValuePartitions() {
+    List<PartitionValue> values = extract("region:VALUE,bucket:VALUE", 
"region=us-west/bucket=7");
+    assertEquals(Arrays.asList("us-west", 7), scalars(values));
+  }
+
+  @Test
+  void testValuePartitionIsUnescaped() {
+    List<PartitionValue> values = extract("region:VALUE", "region=a%3Ab%2Fc");
+    assertEquals("a:b/c", scalars(values).get(0));
+  }
+
+  @Test
+  void testHiveDefaultPartitionIsNull() {
+    List<PartitionValue> values =
+        extract("region:VALUE,bucket:VALUE", 
"region=__HIVE_DEFAULT_PARTITION__/bucket=7");
+    assertNull(scalars(values).get(0));
+    assertEquals(7, scalars(values).get(1));
+  }
+
+  @Test
+  void testValueAndTimePartitions() {
+    List<PartitionValue> values =
+        extract("region:VALUE,ts:DAY:ts=yyyy-MM-dd", 
"region=us-west/ts=2026-08-01");
+    assertEquals(
+        Arrays.asList("us-west", 
Instant.parse("2026-08-01T00:00:00Z").toEpochMilli()),
+        scalars(values));
+  }
+
+  @Test
+  void testTimePartitionAcrossDirectories() {
+    List<PartitionValue> values = extract("ts:MONTH:year=yyyy/month=MM", 
"year=2026/month=08");
+    assertEquals(Instant.parse("2026-08-01T00:00:00Z").toEpochMilli(), 
scalars(values).get(0));
+  }
+
+  @Test
+  void testUnparsableValueNamesTheField() {
+    PartitionValuesExtractorException e =
+        assertThrows(
+            PartitionValuesExtractorException.class, () -> 
extract("bucket:VALUE", "bucket=seven"));
+    assertTrue(e.getMessage().contains("bucket"), e.getMessage());
+  }
+
+  @Test
+  void testTimeTransformWithoutFormatIsRejected() {
+    IllegalArgumentException e =
+        assertThrows(IllegalArgumentException.class, () -> config("ts:DAY"));
+    assertTrue(e.getMessage().contains("ts:DAY:ts=yyyy-MM-dd"), 
e.getMessage());
+  }
+
+  private static List<PartitionValue> extract(String partitionSpec, String 
partitionPath) {
+    PathBasedPartitionSpecExtractor specExtractor =
+        config(partitionSpec).loadSourcePartitionSpecExtractor();
+    List<InternalPartitionField> partitionFields = specExtractor.spec(SCHEMA);
+    return new 
ParquetPartitionValueExtractor(specExtractor.getPathToPartitionFieldFormat())
+        .extractPartitionValues(partitionFields, partitionPath);
+  }
+
+  private static ParquetSourceConfig config(String partitionSpec) {
+    Properties properties = new Properties();
+    properties.put(ParquetSourceConfig.PARTITION_FIELD_SPEC_CONFIG, 
partitionSpec);
+    return ParquetSourceConfig.fromProperties(properties);
+  }
+
+  private static List<Object> scalars(List<PartitionValue> values) {
+    return values.stream().map(v -> 
v.getRange().getMaxValue()).collect(Collectors.toList());
+  }
+
+  private static InternalField field(String name, InternalType type) {
+    return InternalField.builder()
+        .name(name)
+        
.schema(InternalSchema.builder().name(type.name()).dataType(type).build())
+        .build();
+  }
+}
diff --git 
a/xtable-utilities/src/main/java/org/apache/xtable/utilities/RunSync.java 
b/xtable-utilities/src/main/java/org/apache/xtable/utilities/RunSync.java
index 5560fad2..2adfa559 100644
--- a/xtable-utilities/src/main/java/org/apache/xtable/utilities/RunSync.java
+++ b/xtable-utilities/src/main/java/org/apache/xtable/utilities/RunSync.java
@@ -63,6 +63,7 @@ import org.apache.xtable.hudi.HudiSourceConfig;
 import org.apache.xtable.iceberg.IcebergCatalogConfig;
 import org.apache.xtable.model.storage.TableFormat;
 import org.apache.xtable.model.sync.SyncMode;
+import org.apache.xtable.parquet.ParquetSourceConfig;
 import org.apache.xtable.reflection.ReflectionUtils;
 
 /**
@@ -178,6 +179,20 @@ public class RunSync {
     return targetProperties;
   }
 
+  /** Puts the partition spec under the config key that the given source 
format reads. */
+  @VisibleForTesting
+  static Properties sourceProperties(String sourceFormat, String 
partitionSpec) {
+    Properties sourceProperties = new Properties();
+    if (partitionSpec != null) {
+      String key =
+          TableFormat.PARQUET.equals(sourceFormat)
+              ? ParquetSourceConfig.PARTITION_FIELD_SPEC_CONFIG
+              : HudiSourceConfig.PARTITION_FIELD_SPEC_CONFIG;
+      sourceProperties.put(key, partitionSpec);
+    }
+    return sourceProperties;
+  }
+
   static void syncTableMetdata(
       DatasetConfig datasetConfig,
       List<String> tableFormatList,
@@ -190,11 +205,8 @@ public class RunSync {
           "Running sync for basePath {} for following table formats {}",
           table.getTableBasePath(),
           tableFormatList);
-      Properties sourceProperties = new Properties();
-      if (table.getPartitionSpec() != null) {
-        sourceProperties.put(
-            HudiSourceConfig.PARTITION_FIELD_SPEC_CONFIG, 
table.getPartitionSpec());
-      }
+      Properties sourceProperties =
+          sourceProperties(datasetConfig.getSourceFormat(), 
table.getPartitionSpec());
 
       SourceTable sourceTable =
           sourceTableBuilder(table, catalogConfig, datasetConfig, 
sourceProperties);
diff --git 
a/xtable-utilities/src/test/java/org/apache/xtable/utilities/TestRunSync.java 
b/xtable-utilities/src/test/java/org/apache/xtable/utilities/TestRunSync.java
index 2933f76f..81a9f151 100644
--- 
a/xtable-utilities/src/test/java/org/apache/xtable/utilities/TestRunSync.java
+++ 
b/xtable-utilities/src/test/java/org/apache/xtable/utilities/TestRunSync.java
@@ -22,6 +22,7 @@ import static 
org.apache.xtable.model.storage.TableFormat.DELTA;
 import static org.apache.xtable.model.storage.TableFormat.HUDI;
 import static org.apache.xtable.model.storage.TableFormat.ICEBERG;
 import static org.apache.xtable.model.storage.TableFormat.PAIMON;
+import static org.apache.xtable.model.storage.TableFormat.PARQUET;
 
 import java.io.IOException;
 import java.net.URL;
@@ -40,6 +41,8 @@ import org.junit.jupiter.api.io.TempDir;
 
 import org.apache.xtable.conversion.CatalogConfig;
 import org.apache.xtable.conversion.TargetTable;
+import org.apache.xtable.hudi.HudiSourceConfig;
+import org.apache.xtable.parquet.ParquetSourceConfig;
 import org.apache.xtable.utilities.RunSync.DatasetConfig;
 import org.apache.xtable.utilities.RunSync.TableFormatConverters;
 import 
org.apache.xtable.utilities.RunSync.TableFormatConverters.ConversionConfig;
@@ -217,4 +220,19 @@ class TestRunSync {
     Assertions.assertEquals("value1", 
catalogConfig.getCatalogOptions().get("option1"));
     Assertions.assertEquals("value2", 
catalogConfig.getCatalogOptions().get("option2"));
   }
+
+  @Test
+  public void testPartitionSpecUsesSourceFormatKey() {
+    Properties parquet = RunSync.sourceProperties(PARQUET, "region:VALUE");
+    Assertions.assertEquals(
+        "region:VALUE", 
parquet.getProperty(ParquetSourceConfig.PARTITION_FIELD_SPEC_CONFIG));
+    
Assertions.assertNull(parquet.getProperty(HudiSourceConfig.PARTITION_FIELD_SPEC_CONFIG));
+
+    Properties hudi = RunSync.sourceProperties(HUDI, "region:VALUE");
+    Assertions.assertEquals(
+        "region:VALUE", 
hudi.getProperty(HudiSourceConfig.PARTITION_FIELD_SPEC_CONFIG));
+    
Assertions.assertNull(hudi.getProperty(ParquetSourceConfig.PARTITION_FIELD_SPEC_CONFIG));
+
+    Assertions.assertTrue(RunSync.sourceProperties(PARQUET, null).isEmpty());
+  }
 }

Reply via email to