Skip to content

Commit 4ee63ac

Browse files
gaogaotiantianHyukjinKwon
authored andcommitted
[SPARK-55020][PYTHON][FOLLOW-UP] Use iter() to get an iterator from ExecutePlan
### What changes were proposed in this pull request? Get the iterator from `ExecutePlan`, instead of using it as an iterator directly. ### Why are the changes needed? In #54248 we did `gen = self._stub.ExecutePlan(req, metadata=self._builder.metadata())` to replace `for b in self._stub.ExecutePlan(req, metadata=self._builder.metadata())`. This is theoretically inequivalent. We use the iterable to be the iterator. For the actual `ExecutePlan` it works fine because the class can be both an iterator and an iterable. However, we do some mock test in our test suite and we should not have to worry too much about our mock. I fixed the test in the previous PR but I think it's better to stick to the actual semantics for the for loop, which is getting the iterator out of the iterable and do `next` on it. I also reverted the change I made to the mock test. It still works with `iter()`, but I don't want to mislead people to believe that's necessary. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? The changed test passed locally. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #54351 from gaogaotiantian/fix-iter-problem. Authored-by: Tian Gao <gaogaotiantian@hotmail.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
1 parent a5f064f commit 4ee63ac

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

python/pyspark/sql/connect/client/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,11 +1701,13 @@ def handle_response(
17011701
for attempt in self._retrying():
17021702
with attempt:
17031703
with disable_gc():
1704-
gen = self._stub.ExecutePlan(req, metadata=self._builder.metadata())
1704+
it = iter(
1705+
self._stub.ExecutePlan(req, metadata=self._builder.metadata())
1706+
)
17051707
while True:
17061708
try:
17071709
with disable_gc():
1708-
b = next(gen)
1710+
b = next(it)
17091711
yield from handle_response(b)
17101712
except StopIteration:
17111713
break

python/pyspark/sql/tests/connect/client/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def ExecutePlan(self, req: proto.ExecutePlanRequest, metadata):
158158
buf = sink.getvalue()
159159
resp.arrow_batch.data = buf.to_pybytes()
160160
resp.arrow_batch.row_count = 2
161-
return iter([resp])
161+
return [resp]
162162

163163
def Interrupt(self, req: proto.InterruptRequest, metadata):
164164
self.req = req

0 commit comments

Comments
 (0)