vinishjail97 commented on code in PR #964:
URL: https://github.com/apache/incubator-xtable/pull/964#discussion_r4251848295


##########
xtable-spark-runtime/src/main/java/org/apache/xtable/spark/XTableSyncService.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.spark;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+import lombok.extern.log4j.Log4j2;
+
+import org.apache.hadoop.conf.Configuration;
+
+import org.apache.xtable.conversion.ConversionConfig;
+import org.apache.xtable.conversion.ConversionController;
+import org.apache.xtable.conversion.ConversionSourceProvider;
+import org.apache.xtable.conversion.SourceTable;
+import org.apache.xtable.conversion.TargetTable;
+import org.apache.xtable.delta.DeltaConversionSourceProvider;
+import org.apache.xtable.delta.DeltaConversionTargetConfig;
+import org.apache.xtable.hudi.HudiConversionSourceProvider;
+import org.apache.xtable.hudi.HudiSourceConfig;
+import org.apache.xtable.iceberg.IcebergConversionSourceProvider;
+import org.apache.xtable.kernel.DeltaKernelConversionSourceProvider;
+import org.apache.xtable.model.storage.TableFormat;
+import org.apache.xtable.model.sync.SyncMode;
+import org.apache.xtable.model.sync.SyncResult;
+import org.apache.xtable.paimon.PaimonConversionSourceProvider;
+import org.apache.xtable.parquet.ParquetConversionSourceProvider;
+
+/**
+ * Runs an incremental {@link ConversionController#sync} for a {@link 
TableSyncSpec}. The sync falls
+ * back to a full snapshot when an incremental sync is not safe, so it is safe 
to call after every
+ * write.
+ */
+@Log4j2
+public class XTableSyncService {
+
+  /** Runs a single sync for the given spec, returning the per-format results. 
*/
+  public Map<String, SyncResult> sync(TableSyncSpec spec, Configuration 
hadoopConf) {
+    Properties sourceProperties = new Properties();
+    if (spec.getPartitionSpec() != null && !spec.getPartitionSpec().isEmpty()) 
{
+      sourceProperties.put(HudiSourceConfig.PARTITION_FIELD_SPEC_CONFIG, 
spec.getPartitionSpec());
+    }
+    // Targets write their metadata next to the data files, e.g. 
<basePath>/data for Iceberg.
+    String dataPath =
+        spec.getDataPath() != null && !spec.getDataPath().isEmpty()
+            ? spec.getDataPath()
+            : spec.getBasePath();
+    SourceTable sourceTable =
+        SourceTable.builder()
+            .name(spec.getKey())
+            .basePath(spec.getBasePath())
+            .dataPath(dataPath)
+            .namespace(spec.getNamespace())
+            .formatName(spec.getSourceFormat())
+            .additionalProperties(sourceProperties)
+            .build();
+
+    // Read by ConversionTargetFactory to pick the Delta Kernel target.
+    List<TargetTable> targetTables =
+        spec.getTargets().stream()
+            .map(
+                targetFormat -> {
+                  Properties targetProperties = new Properties();
+                  if (spec.isUseDeltaKernel()) {
+                    targetProperties.setProperty(
+                        DeltaConversionTargetConfig.USE_KERNEL, 
Boolean.TRUE.toString());
+                  }
+                  return TargetTable.builder()
+                      .name(spec.getKey())
+                      .basePath(dataPath)

Review Comment:
   Updated in f7fb5d70: Iceberg and Delta targets now go to the base path. Hudi 
stays on the data path, since it derives partitions relative to its base path 
and an Iceberg `data/` directory would otherwise show up in the partition 
values (`data/level=ERROR`); the bundle IT now also covers Iceberg to Delta.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to