HyukjinKwon commented on code in PR #39976:
URL: https://github.com/apache/spark/pull/39976#discussion_r1103909947


##########
sql/core/src/test/scala/org/apache/spark/sql/util/DataFrameCallbackSuite.scala:
##########
@@ -96,6 +96,34 @@ class DataFrameCallbackSuite extends QueryTest
     spark.listenerManager.unregister(listener)
   }
 
+  test("execute callback functions when a DataSet trigger foreach action 
finished") {
+    val metrics = ArrayBuffer.empty[(String, QueryExecution, Long)]
+    val listener = new QueryExecutionListener {
+      // Only test successful case here, so no need to implement `onFailure`
+      override def onFailure(funcName: String, qe: QueryExecution, exception: 
Exception): Unit = {}
+
+      override def onSuccess(funcName: String, qe: QueryExecution, duration: 
Long): Unit = {
+        metrics += ((funcName, qe, duration))
+      }
+    }
+    spark.listenerManager.register(listener)
+
+    def f(): Unit = {}
+
+    val df = Seq(1).toDF("i")
+
+    df.foreach(r => f)
+    df.reduce((x, y) => x)
+
+    sparkContext.listenerBus.waitUntilEmpty()
+    assert(metrics.length == 2)
+
+    assert(metrics(0)._1 == "foreach")
+    assert(metrics(1)._1 == "reduce")
+
+    spark.listenerManager.unregister(listener)

Review Comment:
   I know other tests don't. but let's at least do it here.



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