rahil-c commented on code in PR #704:
URL: https://github.com/apache/incubator-xtable/pull/704#discussion_r2081180846


##########
xtable-service/src/main/java/org/apache/xtable/service/spark/SparkHolder.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.service.spark;
+
+import static 
org.apache.xtable.service.ConversionServiceConfig.HADOOP_DEFAULTS_XML;
+
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import org.apache.spark.SparkConf;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.serializer.KryoSerializer;
+import org.apache.spark.sql.SparkSession;
+
+import org.apache.xtable.service.ConversionServiceConfig;
+
+import io.quarkus.runtime.ShutdownEvent;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.event.Observes;
+import jakarta.inject.Inject;
+
+@ApplicationScoped
+public class SparkHolder {
+
+  private volatile SparkSession spark;
+  private volatile JavaSparkContext jsc;
+
+  @Inject private ConversionServiceConfig conversionServiceConfig;
+
+  public SparkSession spark() {
+    if (spark == null) {
+      synchronized (this) {
+        if (spark == null) {
+          spark =
+              SparkSession.builder()
+                  .config(getSparkConf())
+                  .appName("xtable-conversion-service")
+                  .getOrCreate();
+          jsc = JavaSparkContext.fromSparkContext(spark.sparkContext());
+
+          // Load user-provided Hadoop XML file if available, otherwise load 
the default
+          try (InputStream configStream =
+              
!conversionServiceConfig.getHadoopConfigPath().equals(HADOOP_DEFAULTS_XML)
+                  ? 
Files.newInputStream(Paths.get(conversionServiceConfig.getHadoopConfigPath()))
+                  : 
SparkHolder.class.getClassLoader().getResourceAsStream(HADOOP_DEFAULTS_XML)) {
+            if (configStream != null) {
+              
spark.sparkContext().hadoopConfiguration().addResource(configStream);
+            } else {
+              throw new RuntimeException("Failed to load Hadoop configuration 
file");
+            }
+          } catch (Exception e) {
+            throw new RuntimeException("Error loading Hadoop configuration 
file", e);
+          }
+        }
+      }
+    }
+    return spark;
+  }
+
+  public JavaSparkContext jsc() {

Review Comment:
   Remove sparkHolder and spark bootstrap



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