|
54 | 54 | import pyarrow as pa |
55 | 55 |
|
56 | 56 | from datafusion._internal import expr as expr_internal |
| 57 | + from datafusion.record_batch import RecordBatch |
57 | 58 |
|
58 | 59 | from enum import Enum |
59 | 60 |
|
@@ -1121,22 +1122,16 @@ def __arrow_c_stream__(self, requested_schema: object | None = None) -> object: |
1121 | 1122 | # preserving the original partition order. |
1122 | 1123 | return self.df.__arrow_c_stream__(requested_schema) |
1123 | 1124 |
|
1124 | | - def __iter__(self) -> Iterator[pa.RecordBatch]: |
1125 | | - """Yield record batches from the DataFrame without materializing results. |
| 1125 | + def __iter__(self) -> Iterator[RecordBatch]: |
| 1126 | + """Yield DataFusion record batches without materializing results. |
1126 | 1127 |
|
1127 | | - This implementation streams record batches via the Arrow C Stream |
1128 | | - interface, allowing callers such as :func:`pyarrow.Table.from_batches` to |
1129 | | - consume results lazily. The DataFrame is executed using DataFusion's |
1130 | | - partitioned streaming APIs so ``collect`` is never invoked and batch |
1131 | | - order across partitions is preserved. |
| 1128 | + Batches are produced lazily using DataFusion's partitioned streaming |
| 1129 | + APIs so ``collect`` is never invoked. Each returned batch exposes the |
| 1130 | + Arrow C data interface and can be consumed by downstream libraries that |
| 1131 | + support ``__arrow_c_array__``. |
1132 | 1132 | """ |
1133 | | - from contextlib import closing |
1134 | | - |
1135 | | - import pyarrow as pa |
1136 | | - |
1137 | | - reader = pa.RecordBatchReader._import_from_c_capsule(self.__arrow_c_stream__()) |
1138 | | - with closing(reader): |
1139 | | - yield from reader |
| 1133 | + for stream in self.execute_stream_partitioned(): |
| 1134 | + yield from stream |
1140 | 1135 |
|
1141 | 1136 | def transform(self, func: Callable[..., DataFrame], *args: Any) -> DataFrame: |
1142 | 1137 | """Apply a function to the current DataFrame which returns another DataFrame. |
|
0 commit comments