|
| 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 | +} |
0 commit comments