Skip to content

Commit cc59929

Browse files
committed
Backported SPARK-2678 fix
1 parent b180467 commit cc59929

2 files changed

Lines changed: 25 additions & 26 deletions

File tree

core/src/main/scala/org/apache/spark/deploy/SparkSubmitArguments.scala

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ private[spark] class SparkSubmitArguments(args: Seq[String]) {
202202

203203
/** Fill in values by parsing user options. */
204204
private def parseOpts(opts: Seq[String]): Unit = {
205-
// Delineates parsing of Spark options from parsing of user options.
206-
var inSparkOpts = true
205+
val EQ_SEPARATED_OPT = """(--[^=]+)=(.+)""".r
206+
207207
parse(opts)
208208

209209
def parse(opts: Seq[String]): Unit = opts match {
@@ -297,33 +297,20 @@ private[spark] class SparkSubmitArguments(args: Seq[String]) {
297297
verbose = true
298298
parse(tail)
299299

300+
case EQ_SEPARATED_OPT(opt, value) :: tail =>
301+
parse(opt :: value :: tail)
302+
303+
case value :: tail if value.startsWith("-") =>
304+
SparkSubmit.printErrorAndExit(s"Unrecognized option '$value'.")
305+
300306
case value :: tail =>
301-
if (inSparkOpts) {
302-
value match {
303-
// convert --foo=bar to --foo bar
304-
case v if v.startsWith("--") && v.contains("=") && v.split("=").size == 2 =>
305-
val parts = v.split("=")
306-
parse(Seq(parts(0), parts(1)) ++ tail)
307-
case v if v.startsWith("-") =>
308-
val errMessage = s"Unrecognized option '$value'."
309-
SparkSubmit.printErrorAndExit(errMessage)
310-
case v =>
311-
primaryResource =
312-
if (!SparkSubmit.isShell(v)) {
313-
Utils.resolveURI(v).toString
314-
} else {
315-
v
316-
}
317-
inSparkOpts = false
318-
isPython = SparkSubmit.isPython(v)
319-
parse(tail)
320-
}
307+
primaryResource = if (!SparkSubmit.isShell(value)) {
308+
Utils.resolveURI(value).toString
321309
} else {
322-
if (!value.isEmpty) {
323-
childArgs += value
324-
}
325-
parse(tail)
310+
value
326311
}
312+
isPython = SparkSubmit.isPython(value)
313+
childArgs ++= tail
327314

328315
case Nil =>
329316
}

core/src/test/scala/org/apache/spark/deploy/SparkSubmitSuite.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ class SparkSubmitSuite extends FunSuite with ShouldMatchers {
106106
appArgs.childArgs should be (Seq("some", "--weird", "args"))
107107
}
108108

109+
test("handles arguments to user program with name collision") {
110+
val clArgs = Seq(
111+
"--name", "myApp",
112+
"--class", "Foo",
113+
"userjar.jar",
114+
"--master", "local",
115+
"some",
116+
"--weird", "args")
117+
val appArgs = new SparkSubmitArguments(clArgs)
118+
appArgs.childArgs should be (Seq("--master", "local", "some", "--weird", "args"))
119+
}
120+
109121
test("handles YARN cluster mode") {
110122
val clArgs = Seq(
111123
"--deploy-mode", "cluster",

0 commit comments

Comments
 (0)