JingsongLi commented on code in PR #6: URL: https://github.com/apache/paimon-python/pull/6#discussion_r1722604380
########## java_based_implementation/api_impl.py: ########## @@ -110,23 +112,62 @@ def to_j_split(self): class TableRead(table_read.TableRead): - def create_reader(self, split: Split) -> RecordBatchReader: - # TODO - pass + def __init__(self, j_table_read, j_row_type): + self._j_table_read = j_table_read + self._j_bytes_reader = get_gateway().jvm.InvocationUtil.createBytesReader( + j_table_read, j_row_type) + + def create_reader(self, split: Split): + self._j_bytes_reader.setSplit(split.to_j_split()) + return BatchReader(self._j_bytes_reader) + + def close(self): + self._j_bytes_reader.close() + + +class BatchReader(table_read.BatchReader): + + def __init__(self, j_bytes_reader): + self._j_bytes_reader = j_bytes_reader + self._inited = False + self._has_next = True + self._next_arrow_reader() + + def next_batch(self): + if not self._has_next: + return None + + try: + return self._current_arrow_reader.read_next_batch() + except StopIteration: + self._current_arrow_reader.close() + self._next_arrow_reader() + if not self._has_next: + return None + else: + return self._current_arrow_reader.read_next_batch() + + def _next_arrow_reader(self): + byte_array = self._j_bytes_reader.next() + if byte_array is None: + self._has_next = False + else: + self._current_arrow_reader = RecordBatchStreamReader(BufferReader(byte_array)) Review Comment: byte_array must be a single batch, not a batch reader. -- 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]
