Skip to content

Extract shared boilerplate from sync cursors into WithFetch mixin #669

@laughingman7743

Description

@laughingman7743

Problem

The five sync cursor implementations (Cursor, PandasCursor, ArrowCursor, PolarsCursor, S3FSCursor) duplicate ~350 lines of identical boilerplate code:

Duplicated code Lines (×5 cursors)
Properties: result_set, query_id, rownumber, rowcount ~125
Fetch methods: fetchone, fetchmany, fetchall ~75
Lifecycle: close(), cancel(), executemany() ~60
execute() shared control flow ~100

This is the sync equivalent of the deduplication done for async cursors in #668 (WithAsyncFetch mixin).

Proposed solution

Create a WithFetch mixin in pyathena/common.py (mirroring WithAsyncFetch in pyathena/aio/common.py) that provides:

  • Properties: arraysize (getter/setter), result_set (getter/setter), query_id (getter/setter), rownumber, rowcount
  • Lifecycle: close(), executemany(), cancel()
  • Default fetch: fetchone(), fetchmany(), fetchall() — delegates to self.result_set.fetch*()

Each specialized cursor would then only need to implement __init__, get_default_converter(), execute(), and format-specific methods (e.g., as_pandas(), as_arrow()).

Files involved

File Change
pyathena/common.py Add WithFetch(BaseCursor, CursorIterator, WithResultSet)
pyathena/cursor.py Extend WithFetch, remove boilerplate
pyathena/pandas/cursor.py Extend WithFetch, remove boilerplate
pyathena/arrow/cursor.py Extend WithFetch, remove boilerplate
pyathena/polars/cursor.py Extend WithFetch, remove boilerplate
pyathena/s3fs/cursor.py Extend WithFetch, remove boilerplate

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions