sarutak commented on code in PR #59743:
URL: https://github.com/apache/spark/pull/59743#discussion_r4566832899
##########
sql/core/src/main/scala/org/apache/spark/sql/classic/SparkSession.scala:
##########
@@ -1267,8 +1267,23 @@ object SparkSession extends SparkSessionCompanion with
Logging {
private def applyExtensions(
sparkContext: SparkContext,
extensions: SparkSessionExtensions): SparkSessionExtensions = {
- val extensionConfClassNames =
sparkContext.conf.get(StaticSQLConf.SPARK_SESSION_EXTENSIONS)
- .getOrElse(Seq.empty)
+ val extensionConfClassNames = {
+ val defaultKey = StaticSQLConf.SPARK_SESSION_EXTENSIONS_DEFAULT_LIST.key
+ val userKey = StaticSQLConf.SPARK_SESSION_EXTENSIONS.key
+ val defaultClassNames =
+
sparkContext.conf.get(StaticSQLConf.SPARK_SESSION_EXTENSIONS_DEFAULT_LIST)
+ .getOrElse(Seq.empty)
+ val userClassNames =
sparkContext.conf.get(StaticSQLConf.SPARK_SESSION_EXTENSIONS)
+ .getOrElse(Seq.empty)
+ // Last-win: drop operator defaults also listed by the user, then apply
defaults first.
+ defaultClassNames.distinct.filter(userClassNames.contains(_)).foreach {
className =>
+ logWarning(log"Extension ${MDC(CLASS_NAME, className)} is listed in
both " +
+ log"${MDC(CONFIG, defaultKey)} and ${MDC(CONFIG2, userKey)};
dropping every " +
+ log"occurrence of it from ${MDC(CONFIG, defaultKey)}; it is applied
where it " +
+ log"appears in ${MDC(CONFIG2, userKey)}.")
Review Comment:
nit (optional): the message joins three clauses with two semicolons. Maybe
something like "Extension X is listed in both A and B. Dropping every
occurrence of it from A; it is applied where it appears in B." The test checks
only that the message contains the default-list key and "it is applied where it
appears", so it would still pass. (Its
`m.contains(SPARK_SESSION_EXTENSIONS.key)` adds nothing, since
`spark.sql.extensions` is a prefix of `spark.sql.extensions.defaultList`;
checking e.g. `s"appears in ${SPARK_SESSION_EXTENSIONS.key}."` would pin the
second key.)
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/StaticSQLConf.scala:
##########
@@ -163,14 +163,32 @@ object StaticSQLConf {
.booleanConf
.createWithDefault(false)
+ private[spark] val SPARK_SESSION_EXTENSIONS_DEFAULT_LIST =
Review Comment:
nit: the other entries in `StaticSQLConf`, including
`SPARK_SESSION_EXTENSIONS` right below, are plain `val`s. Could this be `val
SPARK_SESSION_EXTENSIONS_DEFAULT_LIST =` for consistency?
##########
sql/core/src/test/scala/org/apache/spark/sql/SparkSessionExtensionSuite.scala:
##########
@@ -513,6 +514,78 @@ class SparkSessionExtensionSuite extends PlanTest with
AdaptiveSparkPlanHelper {
}
}
+ test("SPARK-60483: use the operator default list ahead of user extensions") {
+ val session = SparkSession.builder()
+ .master("local[1]")
+ .config(SPARK_SESSION_EXTENSIONS_DEFAULT_LIST.key,
classOf[MyExtensions].getCanonicalName)
+ .config(SPARK_SESSION_EXTENSIONS.key,
classOf[MyExtensions2].getCanonicalName)
+ .getOrCreate()
+ try {
+ val orderedRules = Seq(MyRule(session), MyRule2(session))
+ val orderedCheckRules = Seq(MyCheckRule(session), MyCheckRule2(session))
+
assert(session.sessionState.analyzer.extendedResolutionRules.containsSlice(orderedRules))
+
assert(session.sessionState.analyzer.extendedCheckRules.containsSlice(orderedCheckRules))
+ assert(session.sessionState.planner.strategies.containsSlice(
+ Seq(MySparkStrategy(session), MySparkStrategy2(session))))
+ } finally {
+ stop(session)
+ }
+ }
+
+ test("SPARK-60483: use the operator default list when user extensions are
unset") {
+ val session = SparkSession.builder()
+ .master("local[1]")
+ .config(SPARK_SESSION_EXTENSIONS_DEFAULT_LIST.key,
classOf[MyExtensions].getCanonicalName)
+ .getOrCreate()
+ try {
+
assert(session.sessionState.analyzer.extendedResolutionRules.contains(MyRule(session)))
+
assert(session.sessionState.planner.strategies.contains(MySparkStrategy(session)))
+ } finally {
+ stop(session)
+ }
+ }
+
+ test("SPARK-60483: an extension listed by both the operator and the user is
applied once") {
+ // De-duplicated across the two lists (last-win); repeats within a single
list stay allowed.
+ val session = SparkSession.builder()
+ .master("local[1]")
+ .config(SPARK_SESSION_EXTENSIONS_DEFAULT_LIST.key,
classOf[MyExtensions].getCanonicalName)
+ .config(SPARK_SESSION_EXTENSIONS.key,
classOf[MyExtensions].getCanonicalName)
+ .getOrCreate()
+ try {
+ assert(session.sessionState.analyzer.extendedResolutionRules.count(_ ===
MyRule(session)) ===
+ 1)
+ } finally {
+ stop(session)
+ }
+ }
+
+ test("SPARK-60483: a shared extension is applied last-win with user-list
repeats kept") {
+ // The shared extension must run only at its user-list positions; plain
concatenation,
+ // first-win, and whole-list distinct all give a different rule order here.
+ val appender = new LogAppender("SPARK-60483 dedup warning")
+ withLogAppender(appender) {
+ val session = SparkSession.builder()
+ .master("local[1]")
+ .config(SPARK_SESSION_EXTENSIONS_DEFAULT_LIST.key,
classOf[MyExtensions].getCanonicalName)
Review Comment:
nit: every test in this suite that sets the default list gives it a single
entry, so a few behaviors of the default list are not pinned. For example,
`defaultClassNames.distinct.filterNot(...)` or
`defaultClassNames.diff(userClassNames)` instead of
`defaultClassNames.filterNot(...)`, or dropping `.distinct` from the warning
loop, would still pass all tests. Could you add cases like these?
- default `MyExtensions,MyExtensions` with user `MyExtensions2`: `MyRule` is
applied twice (repeats within the default list stay).
- default `MyExtensions,MyExtensions` with user `MyExtensions`: `MyRule` is
applied once, and exactly one matching warning is logged (count the messages;
`exists` would not catch a warning per occurrence).
If you add them, please also list them under "How was this patch tested?".
##########
sql/core/src/test/scala/org/apache/spark/sql/SparkSessionExtensionSuite.scala:
##########
@@ -513,6 +514,78 @@ class SparkSessionExtensionSuite extends PlanTest with
AdaptiveSparkPlanHelper {
}
}
+ test("SPARK-60483: use the operator default list ahead of user extensions") {
+ val session = SparkSession.builder()
+ .master("local[1]")
+ .config(SPARK_SESSION_EXTENSIONS_DEFAULT_LIST.key,
classOf[MyExtensions].getCanonicalName)
+ .config(SPARK_SESSION_EXTENSIONS.key,
classOf[MyExtensions2].getCanonicalName)
+ .getOrCreate()
+ try {
+ val orderedRules = Seq(MyRule(session), MyRule2(session))
+ val orderedCheckRules = Seq(MyCheckRule(session), MyCheckRule2(session))
+
assert(session.sessionState.analyzer.extendedResolutionRules.containsSlice(orderedRules))
+
assert(session.sessionState.analyzer.extendedCheckRules.containsSlice(orderedCheckRules))
+ assert(session.sessionState.planner.strategies.containsSlice(
+ Seq(MySparkStrategy(session), MySparkStrategy2(session))))
+ } finally {
+ stop(session)
+ }
+ }
+
+ test("SPARK-60483: use the operator default list when user extensions are
unset") {
+ val session = SparkSession.builder()
+ .master("local[1]")
+ .config(SPARK_SESSION_EXTENSIONS_DEFAULT_LIST.key,
classOf[MyExtensions].getCanonicalName)
+ .getOrCreate()
+ try {
+
assert(session.sessionState.analyzer.extendedResolutionRules.contains(MyRule(session)))
+
assert(session.sessionState.planner.strategies.contains(MySparkStrategy(session)))
+ } finally {
+ stop(session)
+ }
+ }
+
+ test("SPARK-60483: an extension listed by both the operator and the user is
applied once") {
+ // De-duplicated across the two lists (last-win); repeats within a single
list stay allowed.
Review Comment:
nit: with default `MyExtensions` and user `MyExtensions`, this test passes
under first-win as well, and it has no repeats, so the comment claims more than
the test checks. Maybe:
```scala
// De-duplicated across the two lists; the next test pins which position
is kept
// and that repeats in spark.sql.extensions stay.
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]