weiting-chen commented on code in PR #13581:
URL: https://github.com/apache/gluten/pull/13581#discussion_r4641401549


##########
gluten-ut/spark43/src/test/scala/org/apache/spark/sql/execution/GlutenPushDownLocalSortSuite.scala:
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.execution
+
+import org.apache.gluten.execution.SortExecTransformer
+
+import org.apache.spark.sql.{DataFrame, GlutenSQLTestsTrait}
+import org.apache.spark.sql.internal.SQLConf
+
+class GlutenPushDownLocalSortSuite extends PushDownLocalSortSuite with 
GlutenSQLTestsTrait {
+
+  // Gluten offloads local sorts to SortExecTransformer, so count both sort 
operators.
+  private def checkNumSorts(df: DataFrame, count: Int): Unit = {
+    df.collect()
+    val sorts = collectWithSubqueries(df.queryExecution.executedPlan) {

Review Comment:
   **Add a native-sort discriminator alongside the mixed count**
   
   **Problem:** A correct all-vanilla `SortExec` plan can satisfy both expected 
counts and answer comparisons here. The mixed count meaningfully tests Spark's 
pushdown, but does not establish that the rewritten Gluten fixture exercises 
native sorting. This is a nonblocking oracle limitation, not evidence that the 
current run fell back.
   
   **Evidence:**
   ```scala
   val sorts = collectWithSubqueries(df.queryExecution.executedPlan) {
     case s: SortExec => s
     case s: SortExecTransformer => s
   }
   assert(sorts.length == count, df.queryExecution.executedPlan)
   ```
   
   **Suggested Fix:** Retain the mixed counts, and for a positive fixture 
confirmed to support native sort add a separate native sentinel after the 
action:
   ```scala
   assert(sorts.exists(_.isInstanceOf[SortExecTransformer]), 
df.queryExecution.executedPlan)
   ```
   A negative control with `spark.gluten.sql.columnar.sort=false` should no 
longer pass that native-path assertion; keep intentionally supported fallback 
cases separate.
   
   _AI-generated review comment._
   
   <!-- pr-review-fingerprint: 
prf-v1:50a746acab5e65633bb929db7c9d8d0e80352348932f63b355ece405267c0c5b -->



##########
gluten-ut/spark43/src/test/scala/org/apache/spark/sql/execution/GlutenWholeStageCodegenSuite.scala:
##########
@@ -0,0 +1,964 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.execution
+
+import org.apache.gluten.config.GlutenConfig
+import org.apache.gluten.execution._
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.{Dataset, GlutenSQLTestsTrait, Row, SaveMode}
+import org.apache.spark.sql.functions._
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types.{DecimalType, IntegerType, StringType, 
StructType}
+
+import java.math.{BigDecimal => JBigDecimal}
+
+import scala.reflect.ClassTag
+
+class GlutenWholeStageCodegenSuite extends WholeStageCodegenSuite with 
GlutenSQLTestsTrait {
+  import testImplicits._
+
+  // Spark's tests inspect WholeStageCodegenExec and row-based operators. 
Gluten replaces them
+  // with WholeStageTransformer and native operator transformers, so the 
excluded parent tests
+  // are repeated below with Gluten-aware plan assertions while preserving 
their result checks.
+  // Disable the forced shuffled hash join rewrite so explicit join hints 
retain their semantics.
+  override def sparkConf: SparkConf = {
+    super.sparkConf
+      .set(GlutenConfig.COLUMNAR_FORCE_SHUFFLED_HASH_JOIN_ENABLED.key, "false")
+  }
+
+  private def assertWholeStageCount[T <: SparkPlan: ClassTag](
+      df: Dataset[_],
+      expectedCount: Int): Unit = {
+    val targetClass = implicitly[ClassTag[T]].runtimeClass
+    val plan = df.queryExecution.executedPlan
+    val stages = plan.collect {

Review Comment:
   **Check both native joins in the fusion cases**
   
   **Problem:** `twoJoinsDF` says both native joins collapse into the same 
stage, but this helper only requires a stage containing at least one target. 
One native join plus a result-correct vanilla join can satisfy `expectedCount = 
1` and the answer assertion. This is a nonblocking oracle gap in the shared 
#13520 suite, not introduced by this PR's incremental re-enablement.
   
   **Evidence:**
   ```scala
   val stages = plan.collect {
     case stage: WholeStageTransformer if 
stage.child.exists(targetClass.isInstance) => stage
   }
   ```
   
   **Investigation Needed:** In the specific two-native-join fusion cases, 
additionally require two target transformer nodes belonging to the same counted 
stage. Stop traversal at input-adapter/stage boundaries so a target in a child 
stage cannot satisfy the assertion. Preserve the current result checks, 
one-join cases and explicit fallback cases.
   
   _AI-generated review comment._
   
   <!-- pr-review-fingerprint: 
prf-v1:e11ac69c0de6fd46fccb5d4c7df853191188b8f107a5d09a46d69d10e04a7e3f -->



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