guixiaowen commented on code in PR #1379: URL: https://github.com/apache/auron/pull/1379#discussion_r2389715304
########## spark-extension-shims-spark3/src/test/scala/org/apache/spark/sql/auron/AuronCheckConvertBroadcastExchangeSuite.scala: ########## @@ -0,0 +1,177 @@ +/* + * 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.auron + +import org.apache.spark.sql.{QueryTest, Row, SparkSession} +import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanExec +import org.apache.spark.sql.execution.auron.plan.NativeBroadcastExchangeExec +import org.apache.spark.sql.execution.exchange.BroadcastExchangeExec +import org.apache.spark.sql.test.SharedSparkSession + +class AuronCheckConvertBroadcastExchangeSuite + extends QueryTest + with SharedSparkSession + with AuronSQLTestHelper + with org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper { + + test( + "test bhj broadcastExchange to native where spark.auron.enable.broadcastexchange is true") { + val spark = SparkSession + .builder() + .master("local[2]") + .appName("checkConvertToNativeShuffleManger") + .config("spark.sql.shuffle.partitions", "4") + .config("spark.sql.autoBroadcastJoinThreshold", -1) + .config("spark.sql.extensions", "org.apache.spark.sql.auron.AuronSparkSessionExtension") + .config( + "spark.shuffle.manager", + "org.apache.spark.sql.execution.auron.shuffle.AuronShuffleManager") + .config("spark.memory.offHeap.enabled", "false") + .config("spark.auron.enable", "true") + .getOrCreate() + + spark.sql( + "create table if not exists broad_cast_table1 using parquet PARTITIONED BY (part) as select 1 as c1, 2 as c2, 'test test' as part") + spark.sql( + "create table if not exists broad_cast_table2 using parquet PARTITIONED BY (part) as select 1 as c1, 2 as c2, 'test test' as part") + val executePlan = + spark.sql( + "select /*+ broadcast(a)*/ a.c1, a.c2 from broad_cast_table1 a inner join broad_cast_table2 b on a.c1 = b.c1") + + val plan = executePlan.queryExecution.executedPlan.asInstanceOf[AdaptiveSparkPlanExec] + val broadcastExchangeExec = + plan.executedPlan + .collectFirst { case broadcastExchangeExec: BroadcastExchangeExec => + broadcastExchangeExec + } + + val afterConvertPlan = AuronConverters.convertSparkPlan(broadcastExchangeExec.get) + assert(afterConvertPlan.isInstanceOf[NativeBroadcastExchangeExec]) + checkAnswer(executePlan, Seq(Row(1, 2))) + } + + test( + "test bnlj broadcastExchange to native where spark.auron.enable.broadcastexchange is true") { + val spark = SparkSession + .builder() + .master("local[2]") + .appName("checkConvertToNativeShuffleManger") + .config("spark.sql.shuffle.partitions", "4") + .config("spark.sql.autoBroadcastJoinThreshold", -1) + .config("spark.sql.extensions", "org.apache.spark.sql.auron.AuronSparkSessionExtension") + .config( + "spark.shuffle.manager", + "org.apache.spark.sql.execution.auron.shuffle.AuronShuffleManager") + .config("spark.memory.offHeap.enabled", "false") + .config("spark.auron.enable", "true") + .getOrCreate() + + spark.sql( + "create table if not exists broad_cast_table1 using parquet PARTITIONED BY (part) as select 1 as c1, 2 as c2, 'test test' as part") + spark.sql( + "create table if not exists broad_cast_table2 using parquet PARTITIONED BY (part) as select 1 as c1, 2 as c2, 'test test' as part") Review Comment: > suggestion: should we use temp views here instead? I think it’s safer and faster to build the data in memory and register it as a temp view using createOrReplaceTempView, as temp views are session-scoped. > > ```scala > private def createData()(implicit spark: SparkSession): Unit = { > import spark.implicits._ > Seq((1, 2, "test test")).toDF("c1","c2","part").createOrReplaceTempView("t1") > Seq((1, 2, "test test")).toDF("c1","c2","part").createOrReplaceTempView("t2") > } > ``` @ShreyeshArangath Done -- 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]
