Skip to content

Commit 2872874

Browse files
committed
fix
1 parent 56341c9 commit 2872874

2 files changed

Lines changed: 101 additions & 2 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.gluten.execution
18+
19+
import org.apache.gluten.config.GlutenConfig
20+
21+
import org.apache.spark.sql.Row
22+
import org.apache.spark.sql.execution.ColumnarShuffleExchangeExec
23+
import org.apache.spark.sql.execution.adaptive.{ColumnarAQEShuffleReadExec, ShuffleQueryStageExec}
24+
import org.apache.spark.sql.internal.SQLConf
25+
26+
class StageExecutionModeSuite extends VeloxWholeStageTransformerSuite {
27+
override protected val resourcePath: String = "/tpch-data-parquet"
28+
override protected val fileFormat: String = "parquet"
29+
30+
import testImplicits._
31+
32+
test("CPU shuffle mapper and GPU shuffle reader with AQE") {
33+
withSQLConf(
34+
SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
35+
SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
36+
GlutenConfig.COLUMNAR_CUDF_ENABLED.key -> "true",
37+
"spark.sql.shuffle.partitions" -> "2"
38+
) {
39+
40+
withTempView("cpu_scan_left", "cpu_scan_right") {
41+
Seq((1, "left-1"), (2, "left-2"), (3, "left-3"))
42+
.toDF("id", "left_value")
43+
.createOrReplaceTempView("cpu_scan_left")
44+
45+
Seq((1, "right-1"), (2, "right-2"), (4, "right-4"))
46+
.toDF("id", "right_value")
47+
.createOrReplaceTempView("cpu_scan_right")
48+
49+
val df = sql(
50+
"""
51+
|SELECT l.id, l.left_value, r.right_value
52+
|FROM cpu_scan_left l
53+
|JOIN cpu_scan_right r
54+
| ON l.id = r.id
55+
|""".stripMargin)
56+
57+
checkAnswer(
58+
df,
59+
Seq(
60+
Row(1, "left-1", "right-1"),
61+
Row(2, "left-2", "right-2")))
62+
63+
val plan = getExecutedPlan(df)
64+
65+
val shuffleReaders = plan.collect {
66+
case reader: ColumnarAQEShuffleReadExec => reader
67+
}
68+
69+
assert(shuffleReaders.nonEmpty)
70+
71+
shuffleReaders.foreach {
72+
reader =>
73+
assert(
74+
reader.executionMode == MockGPUStageMode,
75+
s"Expected GPU AQE shuffle reader, but got ${reader.executionMode}")
76+
}
77+
78+
val shuffleStages = plan.collect {
79+
case stage: ShuffleQueryStageExec => stage
80+
}
81+
82+
val exchanges = shuffleStages.flatMap {
83+
_.plan.collect {
84+
case exchange: ColumnarShuffleExchangeExec => exchange
85+
}
86+
}
87+
88+
assert(exchanges.nonEmpty)
89+
90+
exchanges.foreach {
91+
exchange =>
92+
assert(
93+
exchange.mapperStageMode.contains(CPUStageMode),
94+
s"Expected CPU mapper stage, but got ${exchange.mapperStageMode}")
95+
}
96+
}
97+
}
98+
}
99+
}

gluten-substrait/src/main/scala/org/apache/spark/sql/execution/GlutenImplicits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ import org.apache.gluten.execution.{GlutenPlan, WholeStageTransformer}
2121
import org.apache.gluten.extension.columnar.FallbackTags
2222
import org.apache.gluten.sql.shims.SparkShimLoader
2323
import org.apache.gluten.utils.PlanUtil
24-
2524
import org.apache.spark.sql.{Column, Dataset, SparkSession}
2625
import org.apache.spark.sql.catalyst.plans.QueryPlan
2726
import org.apache.spark.sql.catalyst.plans.logical.{CommandResult, LogicalPlan}
2827
import org.apache.spark.sql.catalyst.util.StringUtils.PlanStringConcat
2928
import org.apache.spark.sql.classic.ClassicConversions._
3029
import org.apache.spark.sql.execution.ColumnarWriteFilesExec.NoopLeaf
31-
import org.apache.spark.sql.execution.adaptive.{AdaptiveSparkPlanExec, AQEShuffleReadExec, QueryStageExec}
30+
import org.apache.spark.sql.execution.adaptive.{AQEShuffleReadExec, AdaptiveSparkPlanExec, ColumnarAQEShuffleReadExec, QueryStageExec}
3231
import org.apache.spark.sql.execution.columnar.InMemoryTableScanExec
3332
import org.apache.spark.sql.execution.command.{DataWritingCommandExec, ExecutedCommandExec}
3433
import org.apache.spark.sql.execution.datasources.WriteFilesExec
@@ -163,6 +162,7 @@ object GlutenImplicits {
163162
}
164163
collect(i.relation.cachedPlan)
165164
case _: AQEShuffleReadExec => // Ignore
165+
case _: ColumnarAQEShuffleReadExec => // Ignore
166166
case p: SparkPlan =>
167167
GlutenExplainUtils.handleVanillaSparkPlan(p, fallbackNodeToReason)
168168
p.innerChildren.foreach(collect)

0 commit comments

Comments
 (0)