bogao007 commented on code in PR #41752:
URL: https://github.com/apache/spark/pull/41752#discussion_r1260397480


##########
connector/connect/common/src/main/scala/org/apache/spark/sql/connect/common/StreamingListenerPacket.scala:
##########
@@ -0,0 +1,20 @@
+/*
+ * 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.connect.common
+
+case class StreamingListenerPacket(id: String, listener: AnyRef) extends 
Serializable

Review Comment:
   done



##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SessionHolder.scala:
##########
@@ -152,6 +156,26 @@ case class SessionHolder(userId: String, sessionId: 
String, session: SparkSessio
   private[connect] def removeCachedDataFrame(dfId: String): DataFrame = {
     dataFrameCache.remove(dfId)
   }
+
+  /**
+   * Caches given StreamingQueryListener with the ID.
+   */
+  private[connect] def cacheListenerById(id: String, listener: 
StreamingQueryListener): Unit = {
+    if (listenerCache.putIfAbsent(id, listener) != null) {
+      SparkException.internalError(s"A listener is already associated with id 
$id")
+    }
+  }
+
+  /**
+   * Returns [[StreamingQueryListener]] cached for Listener ID `id`. If it is 
not found, throw
+   * [[InvalidPlanInput]].
+   */
+  private[connect] def getListenerOrThrow(id: String): StreamingQueryListener 
= {

Review Comment:
   Added remove() method which would be called in `removeListener()`



##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/streaming/StreamingQuerySuite.scala:
##########
@@ -292,3 +331,31 @@ class TestForeachWriter[T] extends ForeachWriter[T] {
 case class TestClass(value: Int) {
   override def toString: String = value.toString
 }
+
+class EventCollector extends StreamingQueryListener {
+  @volatile var startEvent: QueryStartedEvent = null
+  @volatile var terminationEvent: QueryTerminatedEvent = null
+  @volatile var idleEvent: QueryIdleEvent = null
+
+  private val _progressEvents = new mutable.Queue[StreamingQueryProgress]
+
+  def progressEvents: Seq[StreamingQueryProgress] = 
_progressEvents.synchronized {
+    _progressEvents.clone().toSeq
+  }
+
+  override def onQueryStarted(event: 
StreamingQueryListener.QueryStartedEvent): Unit = {
+    startEvent = event
+  }
+
+  override def onQueryProgress(event: 
StreamingQueryListener.QueryProgressEvent): Unit = {
+    _progressEvents += event.progress

Review Comment:
   Updated the unit test to cover a `spark.write()` case



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