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
5 changes: 5 additions & 0 deletions src_cpp/include/pyarrow/pyarrow_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ struct PyArrowTableScanSharedState final : public function::TableFuncSharedState
: TableFuncSharedState{numRows}, chunks{std::move(chunks)}, currentChunk{0} {}

ArrowArrayWrapper* getNextChunk();

// TableFunctionCall::copy() (used by the physical-plan cache on prepared
// statement re-execution) shares the same sharedState instance, so the
// chunk cursor must be rewound here or a re-executed scan yields 0 rows.
void resetState() override { currentChunk = 0; }
};

struct PyArrowTableScanFunctionData final : public function::TableFuncBindData {
Expand Down
12 changes: 12 additions & 0 deletions test/test_scan_pandas_pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ def test_pyarrow_primitive(conn_db_empty: ConnDB) -> None:
pyarrow_test_helper(establish_connection, sf, thread)


def test_pyarrow_scan_repeated_execution(conn_db_in_mem: ConnDB) -> None:
# Regression test: re-executing the same (implicitly cached) prepared
# statement that scans a python object returned 0 rows on the second run.
# The cached physical plan shares the scan's shared state, whose chunk
# cursor was never rewound between executions.
conn, _ = conn_db_in_mem
df = pd.DataFrame({"a": pd.Series([1, 2, 3, None], dtype="int32[pyarrow]")})
for _ in range(3):
result = conn.execute("LOAD FROM df RETURN count(*)")
assert result.get_next()[0] == 4


def test_pyarrow_time(conn_db_readonly: ConnDB) -> None:
conn, _ = conn_db_readonly
col1 = pa.array([1000123, 2000123, 3000123], type=pa.duration("s"))
Expand Down
Loading