Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ private[spark] object PythonUtils extends Logging {
val PY4J_ZIP_NAME = "py4j-0.10.9.7-src.zip"

/** Get the PYTHONPATH for PySpark, either from SPARK_HOME, if it is set, or from our JAR */
def sparkPythonPath: String = {
def sparkPythonPaths: Seq[String] = {
val pythonPath = new ArrayBuffer[String]
for (sparkHome <- sys.env.get("SPARK_HOME")) {
pythonPath += Seq(sparkHome, "python", "lib", "pyspark.zip").mkString(File.separator)
pythonPath +=
Seq(sparkHome, "python", "lib", PY4J_ZIP_NAME).mkString(File.separator)
}
pythonPath ++= SparkContext.jarOfObject(this)
pythonPath.mkString(File.pathSeparator)
pythonPath.toSeq
}

def sparkPythonPath: String = sparkPythonPaths.mkString(File.pathSeparator)

/** Merge PYTHONPATHS with the appropriate separator. Ignores blank strings. */
def mergePythonPaths(paths: String*): String = {
paths.filter(_ != "").mkString(File.pathSeparator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package org.apache.spark.sql.execution.datasources
import java.io.File
import java.util.Locale
import java.util.concurrent.ConcurrentHashMap
import java.util.regex.Pattern

import scala.jdk.CollectionConverters._

Expand Down Expand Up @@ -91,8 +90,7 @@ object DataSourceManager extends Logging {
private lazy val shouldLoadPythonDataSources: Boolean = {
Utils.checkCommandAvailable(PythonUtils.defaultPythonExec) &&
// Make sure PySpark zipped files also exist.
PythonUtils.sparkPythonPath
.split(Pattern.quote(File.separator)).forall(new File(_).exists())
PythonUtils.sparkPythonPaths.forall(new File(_).exists())
}

private def initialDataSourceBuilders: Map[String, UserDefinedPythonDataSource] = {
Expand Down