jzhuge commented on code in PR #59743:
URL: https://github.com/apache/spark/pull/59743#discussion_r4582533443
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/StaticSQLConf.scala:
##########
@@ -163,7 +163,10 @@ object StaticSQLConf {
.booleanConf
.createWithDefault(false)
+ private[spark] val DEFAULT_EXTENSIONS_LIST =
"spark.sql.extensions.defaultList"
Review Comment:
Registered as a static conf, as you suggested. One deviation: I did not use
`.withPrepended(...)` on `spark.sql.extensions`, because that would make
`spark.conf.get("spark.sql.extensions")` return the combined list, which
contradicts the note you asked for in the sibling thread. Instead
`applyExtensions` reads both entries and builds the effective list, so
registration still gives the static guard, the generated docs row and the
version, while `SET` keeps showing the raw user value.
##########
sql/core/src/test/scala/org/apache/spark/sql/SparkSessionExtensionSuite.scala:
##########
@@ -513,6 +514,52 @@ 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(DEFAULT_EXTENSIONS_LIST, 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(DEFAULT_EXTENSIONS_LIST, 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: keep an extension listed by both the operator and the
user") {
+ // Applied twice, matching the existing contract for duplicated user
extensions.
Review Comment:
Your last-win recommendation is what landed: every occurrence of a shared
class is dropped from the default list, so it runs only at its user-list
positions, with one warning per duplicated class. Repeats inside a single list
are unchanged. The description no longer claims parity with `spark.plugins`,
and the new key documents the overlap case.
##########
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:
Kept `private[spark]` on purpose: `object StaticSQLConf` is public, so a
plain `val` widens this entry to anyone importing the object. I do see the
consistency argument, and I can switch it to `val` to match the neighbouring
entries if you prefer.
##########
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:
Took the assertion point: it now checks for `appears in
spark.sql.extensions.` instead of `contains(SPARK_SESSION_EXTENSIONS.key)`. I
left the message wording unchanged in this revision, since the clauses read
correctly and the assertion matches the current text, so I have not resolved
this one.
##########
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:
Agreed the gap is real: nothing currently pins repeats inside the default
list, so a `.distinct` on the applied list would still pass every test. I have
left those cases out to keep this diff narrow this close to merge rather than
implying the behaviour is covered, and flagged them as a follow-up. Not
resolving, so it stays visible.
--
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]