Skip to content

Commit a8d9531

Browse files
HeartSaVioRsrowen
authored andcommitted
[SPARK-27205][CORE] Remove complicated logic for just leaving warning log when main class is scala.App
## What changes were proposed in this pull request? [SPARK-26977](https://issues.apache.org/jira/browse/SPARK-26977) introduced very strange bug which spark-shell is no longer able to load classes which are provided via `--packages`. TBH I don't know about the details why it is broken, but looks like initializing `object class` brings the weirdness (maybe due to static initialization done twice?). This patch removes the logic to leave warning log when main class is scala.App, to not deal with such complexity for just leaving warning message. ## How was this patch tested? Manual test: suppose we run spark-shell with `--packages` option like below: ``` ./bin/spark-shell --verbose --master "local[*]" --packages org.apache.spark:spark-sql-kafka-0-10_2.11:2.4.0 ``` Before this patch, importing class in transitive dependency fails: ``` Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). Spark context Web UI available at http://localhost:4040 Spark context available as 'sc' (master = local[*], app id = local-1553005771597). Spark session available as 'spark'. Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 3.0.0-SNAPSHOT /_/ Using Scala version 2.12.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_191) Type in expressions to have them evaluated. Type :help for more information. scala> import org.apache.kafka <console>:23: error: object kafka is not a member of package org.apache import org.apache.kafka ``` After this patch, importing class in transitive dependency succeeds: ``` Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). Spark context Web UI available at http://localhost:4040 Spark context available as 'sc' (master = local[*], app id = local-1553004095542). Spark session available as 'spark'. Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 3.0.0-SNAPSHOT /_/ Using Scala version 2.12.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_191) Type in expressions to have them evaluated. Type :help for more information. scala> import org.apache.kafka import org.apache.kafka ``` Closes apache#24147 from HeartSaVioR/SPARK-27205. Authored-by: Jungtaek Lim (HeartSaVioR) <[email protected]> Signed-off-by: Sean Owen <[email protected]>
1 parent 46f9f44 commit a8d9531

File tree

1 file changed

+0
-12
lines changed

1 file changed

+0
-12
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -826,18 +826,6 @@ private[spark] class SparkSubmit extends Logging {
826826
val app: SparkApplication = if (classOf[SparkApplication].isAssignableFrom(mainClass)) {
827827
mainClass.getConstructor().newInstance().asInstanceOf[SparkApplication]
828828
} else {
829-
// Scala object subclassing scala.App has its whole class body executed in the
830-
// main method it inherits. Fields of the object will not have been initialized
831-
// before the main method has been executed, which will cause problems like SPARK-4170
832-
// Note two Java classes are generated, the childMainClass and childMainClass$.
833-
// Users will pass in childMainClass which will delegate all invocations to childMainClass$
834-
// but it's childMainClass$ that subclasses scala.App and we should check for.
835-
Try {
836-
if (classOf[scala.App].isAssignableFrom(Utils.classForName(s"$childMainClass$$"))) {
837-
logWarning("Subclasses of scala.App may not work correctly. " +
838-
"Use a main() method instead.")
839-
}
840-
}
841829
new JavaMainApplication(mainClass)
842830
}
843831

0 commit comments

Comments
 (0)