arrow: ArrowResult helpers and coerce_arrow_table/coerce_arrow_batches fail on non-'table' return_format payloads

オープン
#945 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python, sql
領域
backend, data

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

bug

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

  1. 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) and arrow_table_to_return_format() (sqlspec/utils/arrow_helpers.py:812-838) document all four return shapes: pyarrow.Table, pyarrow.RecordBatch, list[pyarrow.RecordBatch], and pyarrow.RecordBatchReader.
    • However, ArrowResult._as_table() delegates directly to ensure_arrow_table(self.data) (sqlspec/utils/arrow_helpers.py:776-784), which raises TypeError for anything other than pyarrow.Table.
    • Calling len(res), iter(res), res.column_names, res.num_rows, res.num_columns, res.to_dict(), res.to_pandas(), or res.to_polars() raises TypeError: Expected an Arrow Table, but got RecordBatch / list / RecordBatchReader.
  2. coerce_arrow_table() and coerce_arrow_batches() fail on list[pyarrow.RecordBatch] and ArrowResult(data=list[pyarrow.RecordBatch]) (sqlspec/utils/arrow_helpers.py:694-753):

    • Passing a list[pa.RecordBatch] (the exact payload returned by select_to_arrow(..., return_format="batches")) falls through to if isinstance(source, Iterable): return pa.Table.from_pylist(list(source)) (arrow_helpers.py:716-719), raising AttributeError: 'pyarrow.lib.RecordBatch' object has no attribute 'keys'.
    • Passing ArrowResult(data=[batch]) to coerce_arrow_table() raises TypeError: ArrowResult did not return a pyarrow.Table instance (arrow_helpers.py:698-704), and passing it to coerce_arrow_batches() raises the same AttributeError.

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() and coerce_arrow_batches() should recognize sequences/iterables of pyarrow.RecordBatch (converting via pa.Table.from_batches(...) or yielding batches directly, handling empty lists cleanly).
  • ArrowResult._as_table() should coerce pyarrow.RecordBatch, list[pyarrow.RecordBatch], and pyarrow.RecordBatchReader payloads (caching the materialized table when consuming a reader/iterator so repeated property access works consistently across all documented ArrowReturnFormat modes).
主要言語
Python
スター
110
フォーク
11
平均マージ
19時間 9分
マージ済み PR(30日)
37

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

litestar-org/sqlspec のほかの issue

litestar-org/sqlspec の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。