anishshri-db commented on code in PR #47641:
URL: https://github.com/apache/spark/pull/47641#discussion_r1714235275


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/TransformWithStateExec.scala:
##########
@@ -250,9 +287,31 @@ case class TransformWithStateExec(
       new ExpiredTimerInfoImpl(isValid = true, Some(expiryTimestampMs))).map { 
obj =>
       getOutputRow(obj)
     }
-    processorHandle.deleteTimer(expiryTimestampMs)
     ImplicitGroupingKeyTracker.removeImplicitKey()
-    mappedIterator
+
+    // See the comment in handleInputRows for an explanation of this wrapper.
+    new Iterator[InternalRow] {
+      var hasStarted = false
+
+      override def hasNext: Boolean = {
+        if (!hasStarted) {
+          hasStarted = true
+          ImplicitGroupingKeyTracker.setImplicitKey(keyObj)
+        }
+
+        val hasNext = mappedIterator.hasNext
+        if (!hasNext) {
+          processorHandle.deleteTimer(expiryTimestampMs)
+          ImplicitGroupingKeyTracker.removeImplicitKey()
+        }
+        hasNext
+      }
+
+      override def next(): InternalRow = {
+        assert(hasStarted, "next called before hasNext")

Review Comment:
   same 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