dongjoon-hyun commented on code in PR #43955:
URL: https://github.com/apache/spark/pull/43955#discussion_r1401744439


##########
connector/connect/common/src/main/scala/org/apache/spark/sql/connect/client/ExecutePlanResponseReattachableIterator.scala:
##########
@@ -101,7 +101,20 @@ class ExecutePlanResponseReattachableIterator(
   // throw error on first iter.hasNext() or iter.next()
   // Visible for testing.
   private[connect] var iter: 
Option[java.util.Iterator[proto.ExecutePlanResponse]] =
-    Some(rawBlockingStub.executePlan(initialRequest))
+    Some(makeLazyIter(rawBlockingStub.executePlan(initialRequest)))
+
+  // Creates a request that contains the query and returns a stream of 
`ExecutePlanResponse`.
+  // After upgrading gRPC from 1.56.0 to 1.59.3, it makes the first request 
when
+  // the stream is created, but here the code here assumes that no request is 
made before
+  // that, see also SPARK-46042
+  private def makeLazyIter(f: => java.util.Iterator[proto.ExecutePlanResponse])
+      : java.util.Iterator[proto.ExecutePlanResponse] = {
+    new java.util.Iterator[proto.ExecutePlanResponse] {
+      private lazy val internalIter = f
+      override def hasNext: Boolean = internalIter.hasNext
+      override def next(): proto.ExecutePlanResponse = internalIter.next
+    }
+  }

Review Comment:
   Wow, thank you for the quick fix!



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