Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.spark.sql

import java.util.concurrent.atomic.AtomicBoolean

import org.apache.hadoop.hive.conf.HiveConf.ConfVars
import org.apache.spark.SparkConf
import org.apache.spark.sql.classic.SparkSession
Expand Down Expand Up @@ -100,13 +102,17 @@ trait KyuubiSparkSQLExtensionTest extends QueryTest
withListener(sql(sqlString))(callback)
}

def withListener(df: => DataFrame)(callback: DataWritingCommand => Unit): Unit = {
def withListener(df: => DataFrame, mustBeCalled: Boolean = true)(
callback: DataWritingCommand => Unit): Unit = {
val called = new AtomicBoolean(false)
val listener = new QueryExecutionListener {
override def onFailure(f: String, qe: QueryExecution, e: Exception): Unit = {}

override def onSuccess(funcName: String, qe: QueryExecution, duration: Long): Unit = {
qe.executedPlan match {
case write: DataWritingCommandExec => callback(write.cmd)
collect(qe.executedPlan) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataWritingCommandExec is wrapped by AdaptiveSparkPlanExec, so we should use AdaptiveSparkPlanHelper#collect

case write: DataWritingCommandExec =>
called.set(true)
callback(write.cmd)
case _ =>
}
}
Expand All @@ -115,6 +121,7 @@ trait KyuubiSparkSQLExtensionTest extends QueryTest
try {
df.collect()
sparkContext.listenerBus.waitUntilEmpty()
assert(!mustBeCalled || called.get(), "callback function should be executed.")
} finally {
spark.listenerManager.unregister(listener)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class RebalanceBeforeWritingSuite extends KyuubiSparkSQLExtensionTest {

test("check rebalance does not exists") {
def check(df: DataFrame): Unit = {
withListener(df) { write =>
withListener(df, false) { write =>
assert(write.collect {
case r: RebalancePartitions => r
}.isEmpty)
Expand Down
Loading