jzhuge commented on code in PR #59743:
URL: https://github.com/apache/spark/pull/59743#discussion_r4593525664


##########
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:
   Correction to my comment above: a `.distinct` on the applied list does not 
survive the current tests. `SPARK-60483: a shared extension is applied last-win 
with user-list repeats kept` asserts the exact three-rule order `MyRule, 
MyRule2, MyRule`, which `.distinct` cuts to `MyRule, MyRule2`, and the existing 
`allow an extension to be duplicated` test fails as well on its count of 2. The 
mutations that do survive every current test are the ones you listed: 
`defaultClassNames.distinct.filterNot(userClassNames.contains(_))`, 
`defaultClassNames.diff(userClassNames)`, and dropping `.distinct` from the 
warning loop.
   
   As you suggested, I am keeping this diff narrow rather than implying the 
behaviour is covered. The follow-up will carry your two cases as written: 
default `MyExtensions,MyExtensions` with user `MyExtensions2` (the repeat 
stays), and default `MyExtensions,MyExtensions` with user `MyExtensions` 
(applied once, and exactly one matching warning, counted rather than `exists`). 
It will also assert that no matching warning is logged when the two lists are 
disjoint, so warning once per default entry cannot pass; that 
`spark.conf.getOption("spark.sql.extensions")` is empty when only the default 
list is set and returns the raw user value when `spark.sql.extensions` is set, 
with `SET spark.sql.extensions` showing `<undefined>` before and the raw value 
after; and that a runtime `SET` on `spark.sql.extensions.defaultList` fails 
with `CANNOT_MODIFY_STATIC_CONFIG`, which pins the `buildStaticConf` 
registration.
   



-- 
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]

Reply via email to