Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/adbc_driver_manager/adbc_driver_manager/_reader.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ class AdbcRecordBatchReader(pyarrow.RecordBatchReader):
def __enter__(self) -> AdbcRecordBatchReader: ...
def __exit__(self, type, value, traceback) -> None: ...
def __iter__(self) -> typing.Iterator[pyarrow.RecordBatch]: ...

class _AdbcErrorHelper:
def check_error(self, exception: Exception) -> None: ...
3 changes: 3 additions & 0 deletions python/adbc_driver_manager/adbc_driver_manager/_reader.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ cdef class _AdbcErrorHelper:
CArrowArrayStream c_stream

def check_error(self, exception):
if self.c_stream.release == NULL:
raise exception

cdef:
CAdbcStatusCode c_status = ADBC_STATUS_OK
const CAdbcError* error = \
Expand Down
16 changes: 16 additions & 0 deletions python/adbc_driver_manager/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,19 @@ def test_reader_methods() -> None:

with _make_reader() as reader:
assert reader.schema == schema


def test_check_error_with_released_stream():
"""check_error must re-raise when c_stream.release is NULL."""
from adbc_driver_manager._reader import _AdbcErrorHelper

# Default-constructed helper has a zeroed c_stream (release == NULL)
helper = _AdbcErrorHelper.__new__(_AdbcErrorHelper)

err = ValueError("upstream error")
with pytest.raises(ValueError, match="upstream error"):
helper.check_error(err)

err = pyarrow.ArrowInvalid("Invalid or unsupported format string: 'd:5,2,32'")
with pytest.raises(pyarrow.ArrowInvalid, match="unsupported format string"):
helper.check_error(err)
Loading