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


##########
xtable-spark-runtime/src/main/java/org/apache/xtable/spark/XTableSparkSync.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import lombok.extern.log4j.Log4j2;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.spark.sql.SparkSession;
+
+/**
+ * Standalone {@code spark-submit} entry point that runs a single XTable sync 
using the relocated
+ * {@code xtable-spark-runtime} bundle. It is the RunSync-equivalent for this 
bundle and is
+ * primarily used to validate that the shaded jar is self-contained on a real 
Spark install.
+ *
+ * <pre>
+ * $SPARK_HOME/bin/spark-submit \
+ *   --class org.apache.xtable.spark.XTableSparkSync \
+ *   xtable-spark-runtime_2.12-&lt;ver&gt;.jar \
+ *   --basePath /warehouse/db/orders --sourceFormat HUDI --targets 
ICEBERG,DELTA
+ * </pre>
+ */
+@Log4j2
+public final class XTableSparkSync {
+
+  private XTableSparkSync() {}
+
+  public static void main(String[] args) {
+    Map<String, String> opts = parseArgs(args);
+    String basePath = required(opts, "basePath");
+    String sourceFormat = required(opts, "sourceFormat");
+    String targets = required(opts, "targets");
+    String tableName = opts.getOrDefault("tableName", 
basePathToName(basePath));
+
+    List<String> targetFormats =
+        Arrays.stream(targets.split(","))
+            .map(String::trim)
+            .filter(s -> !s.isEmpty())
+            .map(s -> s.toUpperCase(java.util.Locale.ROOT))
+            .collect(Collectors.toList());
+
+    TableSyncSpec spec =
+        TableSyncSpec.builder()
+            .key(tableName)
+            .basePath(basePath)
+            .dataPath(opts.get("dataPath"))
+            .namespace(opts.containsKey("namespace") ? 
opts.get("namespace").split("\\.") : null)
+            .sourceFormat(sourceFormat.toUpperCase(java.util.Locale.ROOT))
+            .targets(targetFormats)
+            .build();
+
+    SparkSession spark = 
SparkSession.builder().appName("xtable-spark-sync").getOrCreate();
+    try {
+      Configuration hadoopConf = spark.sparkContext().hadoopConfiguration();
+      log.info("Starting standalone XTable sync for {}", spec.getBasePath());
+      new XTableSyncService().sync(spec, hadoopConf);
+      log.info("Completed XTable sync for {}", spec.getBasePath());
+    } finally {
+      spark.stop();
+    }
+  }
+
+  private static Map<String, String> parseArgs(String[] args) {

Review Comment:
   Good call. Switched to Apache Commons CLI (`Options` + `DefaultParser` + 
`HelpFormatter`), mirroring `RunSync`. commons-cli is bundled and relocated 
under `org.apache.xtable.shaded.*`. Done in 96da5d67.



##########
xtable-core/src/main/java/org/apache/xtable/conversion/ConversionTargetFactory.java:
##########
@@ -87,7 +90,19 @@ public ConversionTarget createConversionTargetForName(
         TableFormat.DELTA.equalsIgnoreCase(tableFormatName)
             && 
DeltaConversionTargetConfig.fromProperties(properties).isUseKernel();
     ServiceLoader<ConversionTarget> loader = 
ServiceLoader.load(ConversionTarget.class);
-    for (ConversionTarget target : loader) {
+    Iterator<ConversionTarget> iterator = loader.iterator();
+    while (iterator.hasNext()) {
+      ConversionTarget target;
+      try {
+        target = iterator.next();
+      } catch (ServiceConfigurationError | LinkageError error) {
+        // A registered target whose engine library is not on the classpath 
(e.g. Delta when only
+        // Hudi/Iceberg are provided). Skip it so a subset of engines can 
still be used; a missing
+        // engine for the requested format surfaces below as 
NotSupportedException.
+        log.debug(

Review Comment:
   Changed to `log.warn` with a message pointing the user to provide the 
missing engine, so an absent provided package is visible. Done in 96da5d67.



##########
xtable-core/src/main/java/org/apache/xtable/conversion/ConversionTargetFactory.java:
##########
@@ -96,7 +111,12 @@ && isDeltaKernelTarget(target) == useKernel) {
     throw new NotSupportedException("Target format is not yet supported: " + 
tableFormatName);
   }
 
+  private static final String DELTA_KERNEL_TARGET_CLASS =
+      "org.apache.xtable.kernel.DeltaKernelConversionTarget";
+
+  // Name-based to avoid loading DeltaKernelConversionTarget (and its 
io.delta.kernel dependencies)

Review Comment:
   Removed. Done in 96da5d67.



-- 
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