Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-33912][SQL] Refactor DependencyUtils ivy property parameter #30928

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ private[spark] class SparkSubmit extends Logging {
// Resolve maven dependencies if there are any and add classpath to jars. Add them to py-files
// too for packages that include Python code
val resolvedMavenCoordinates = DependencyUtils.resolveMavenDependencies(
packagesTransitive = true, args.packagesExclusions, args.packages,
args.repositories, args.ivyRepoPath, args.ivySettingsPath)
packagesTransitive = true, Option(args.packagesExclusions), Option(args.packages),
Option(args.repositories), Option(args.ivyRepoPath), args.ivySettingsPath)

if (resolvedMavenCoordinates.nonEmpty) {
// In K8s client mode, when in the driver, add resolved jars early as we might need
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object DriverWrapper extends Logging {

val resolvedMavenCoordinates = DependencyUtils.resolveMavenDependencies(true,
ivyProperties.packagesExclusions, ivyProperties.packages, ivyProperties.repositories,
ivyProperties.ivyRepoPath, Option(ivyProperties.ivySettingsPath))
ivyProperties.ivyRepoPath, ivyProperties.ivySettingsPath)
val jars = {
val jarsProp = sys.props.get(config.JARS.key).orNull
if (resolvedMavenCoordinates.nonEmpty) {
Expand Down
40 changes: 20 additions & 20 deletions core/src/main/scala/org/apache/spark/util/DependencyUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import org.apache.spark.deploy.SparkSubmitUtils
import org.apache.spark.internal.Logging

case class IvyProperties(
packagesExclusions: String,
packages: String,
repositories: String,
ivyRepoPath: String,
ivySettingsPath: String)
packagesExclusions: Option[String],
packages: Option[String],
repositories: Option[String],
ivyRepoPath: Option[String],
ivySettingsPath: Option[String])

private[spark] object DependencyUtils extends Logging {

Expand All @@ -44,7 +44,7 @@ private[spark] object DependencyUtils extends Logging {
"spark.jars.repositories",
"spark.jars.ivy",
"spark.jars.ivySettings"
).map(sys.props.get(_).orNull)
).map(sys.props.get(_))
IvyProperties(packagesExclusions, packages, repositories, ivyRepoPath, ivySettingsPath)
}

Expand All @@ -69,10 +69,10 @@ private[spark] object DependencyUtils extends Logging {
* Example: Input: excludeorg.mortbay.jetty:jetty,org.eclipse.jetty:jetty-http
* Output: [org.mortbay.jetty:jetty,org.eclipse.jetty:jetty-http]
*/
private def parseQueryParams(uri: URI): (Boolean, String) = {
private def parseQueryParams(uri: URI): (Boolean, Option[String]) = {
val uriQuery = uri.getQuery
if (uriQuery == null) {
(false, "")
(false, None)
} else {
val mapTokens = uriQuery.split("&").map(_.split("="))
if (mapTokens.exists(isInvalidQueryString)) {
Expand Down Expand Up @@ -103,7 +103,7 @@ private[spark] object DependencyUtils extends Logging {
}
excludes
}.mkString(",")
}.getOrElse("")
}

val validParams = Set("transitive", "exclude")
val invalidParams = groupedParams.keys.filterNot(validParams.contains).toSeq
Expand Down Expand Up @@ -150,36 +150,36 @@ private[spark] object DependencyUtils extends Logging {
resolveMavenDependencies(
transitive,
exclusionList,
authority,
Some(authority),
ivyProperties.repositories,
ivyProperties.ivyRepoPath,
Option(ivyProperties.ivySettingsPath)
ivyProperties.ivySettingsPath
)
}

def resolveMavenDependencies(
packagesTransitive: Boolean,
packagesExclusions: String,
packages: String,
repositories: String,
ivyRepoPath: String,
packagesExclusions: Option[String],
packages: Option[String],
repositories: Option[String],
ivyRepoPath: Option[String],
ivySettingsPath: Option[String]): Seq[String] = {
val exclusions: Seq[String] =
if (!StringUtils.isBlank(packagesExclusions)) {
packagesExclusions.split(",")
if (packagesExclusions.nonEmpty) {
packagesExclusions.map(_.split(",")).get
} else {
Nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use idiomatic Option processing, either a match or packagesExclusions.map(_.split(",")).getOrElse(Nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use idiomatic Option processing, either a match or packagesExclusions.map(_.split(",")).getOrElse(Nil)

DOne

// Create the IvySettings, either load from file or build defaults
val ivySettings = ivySettingsPath match {
case Some(path) =>
SparkSubmitUtils.loadIvySettings(path, Option(repositories), Option(ivyRepoPath))
SparkSubmitUtils.loadIvySettings(path, repositories, ivyRepoPath)

case None =>
SparkSubmitUtils.buildIvySettings(Option(repositories), Option(ivyRepoPath))
SparkSubmitUtils.buildIvySettings(repositories, ivyRepoPath)
}

SparkSubmitUtils.resolveMavenCoordinates(packages, ivySettings,
SparkSubmitUtils.resolveMavenCoordinates(packages.get, ivySettings,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be packages.orNull ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be packages.orNull ?

Yea

transitive = packagesTransitive, exclusions = exclusions)
}

Expand Down