arrow: ArrowResult helpers and coerce_arrow_table/coerce_arrow_batches fail on non-'table' return_format payloads
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
Start with sqlspec/utils/arrow_helpers.py, especially coerce_arrow_table() and coerce_arrow_batches(), then inspect ArrowResult._as_table() in sqlspec/core/result/_base.py. Reproduce with a RecordBatch, a list of batches, and a RecordBatchReader; check existing Arrow helper tests for coverage. Done when all documented return formats coerce correctly, including empty batches, and repeated result property access works after reader materialization.
Written by the indexing model from the issue text.
Description
Summary
ArrowResult helper methods and coerce_arrow_table / coerce_arrow_batches fail when select_to_arrow() returns any return_format other than "table" ("batch", "batches", or "reader").
Details
-
ArrowResult._as_table()rejects"batch","batches", and"reader"payloads (sqlspec/core/result/_base.py:1385-1389):ArrowResult.get_data()(sqlspec/core/result/_base.py:1149-1163) andarrow_table_to_return_format()(sqlspec/utils/arrow_helpers.py:812-838) document all four return shapes:pyarrow.Table,pyarrow.RecordBatch,list[pyarrow.RecordBatch], andpyarrow.RecordBatchReader.- However,
ArrowResult._as_table()delegates directly toensure_arrow_table(self.data)(sqlspec/utils/arrow_helpers.py:776-784), which raisesTypeErrorfor anything other thanpyarrow.Table. - Calling
len(res),iter(res),res.column_names,res.num_rows,res.num_columns,res.to_dict(),res.to_pandas(), orres.to_polars()raisesTypeError: Expected an Arrow Table, but got RecordBatch / list / RecordBatchReader.
-
coerce_arrow_table()andcoerce_arrow_batches()fail onlist[pyarrow.RecordBatch]andArrowResult(data=list[pyarrow.RecordBatch])(sqlspec/utils/arrow_helpers.py:694-753):- Passing a
list[pa.RecordBatch](the exact payload returned byselect_to_arrow(..., return_format="batches")) falls through toif isinstance(source, Iterable): return pa.Table.from_pylist(list(source))(arrow_helpers.py:716-719), raisingAttributeError: 'pyarrow.lib.RecordBatch' object has no attribute 'keys'. - Passing
ArrowResult(data=[batch])tocoerce_arrow_table()raisesTypeError: ArrowResult did not return a pyarrow.Table instance(arrow_helpers.py:698-704), and passing it tocoerce_arrow_batches()raises the sameAttributeError.
- Passing a
Reproduction (sqlspec==0.74.2)
import pyarrow as pa
from sqlspec.core import SQL, create_arrow_result
from sqlspec.utils.arrow_helpers import coerce_arrow_batches, coerce_arrow_table
batch = pa.record_batch({"amount": [1.0, 2.0]})
for payload in (
batch,
[batch],
pa.RecordBatchReader.from_batches(batch.schema, [batch]),
):
res = create_arrow_result(SQL("SELECT 1"), payload)
len(res) # TypeError: Expected an Arrow Table, but got RecordBatch / list / RecordBatchReader
coerce_arrow_table([batch])
# AttributeError: 'pyarrow.lib.RecordBatch' object has no attribute 'keys'
coerce_arrow_table(create_arrow_result(SQL("SELECT 1"), [batch]))
# TypeError: ArrowResult did not return a pyarrow.Table instance
coerce_arrow_batches(create_arrow_result(SQL("SELECT 1"), [batch]))
# AttributeError: 'pyarrow.lib.RecordBatch' object has no attribute 'keys'
Expected Behavior
coerce_arrow_table()andcoerce_arrow_batches()should recognize sequences/iterables ofpyarrow.RecordBatch(converting viapa.Table.from_batches(...)or yielding batches directly, handling empty lists cleanly).ArrowResult._as_table()should coercepyarrow.RecordBatch,list[pyarrow.RecordBatch], andpyarrow.RecordBatchReaderpayloads (caching the materialized table when consuming a reader/iterator so repeated property access works consistently across all documentedArrowReturnFormatmodes).
- Dominant language
- Python
- Stars
- 110
- Forks
- 11
- Avg merge
- 19h 9m
- Merged PRs (30d)
- 37
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from litestar-org/sqlspec
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
litestar-org/sqlspec#946 ·
Maintainers usually reply within 1 day
-
builder: order_by("col", "asc") silently treats the direction as a columnPossibly taken @cofin claimed this 1 day ago. Openenhancement
litestar-org/sqlspec#944 · 1 assignee ·
Maintainers usually reply within 1 day
-
builder: explain why boolean projections are rejected in sql.select() string columnsPossibly taken @cofin claimed this 1 day ago. Openenhancement
litestar-org/sqlspec#943 · 1 assignee ·
Maintainers usually reply within 1 day
-
feat(litestar): support Litestar v3 compatibility and DI changesPossibly taken @cofin claimed this 14 days ago. Openenhancement
litestar-org/sqlspec#926 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
litestar-org/sqlspec#509 ·
Maintainers usually reply within 1 day
All issues in litestar-org/sqlspec
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
nael5x/creative-ai#130 ·
-
Make the "%" unit spacing the same in the web and in A10Possibly taken @kragent66-glitch claimed this today. Openbug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
maiychrus25/OpenTea-DX-OS#226 · 1 comment ·
-
ci severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
TMHSDigital/Spackle#205 ·
Maintainers usually reply within 1 day
-
pkg:lgm type:chore upstream-gaussx
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
jejjohnson/pyrox#610 ·
Maintainers usually reply within 1 day