Skip to content

sql_database: add mssql-python native Arrow batch extraction backend #4254

Description

@sdebruyn

Problem

The pyarrow backend in sql_database always fetches SQLAlchemy rows and rebuilds Arrow tables via row_tuples_to_arrow(). With mssql-python, this creates an unnecessary conversion chain:

ODBC buffers -> mssql-python Row -> SQLAlchemy Row -> Python tuples -> PyArrow buffers

mssql-python exposes cursor.arrow_reader(batch_size) which yields native RecordBatch objects via the Arrow C Data Interface, bypassing the intermediate layers entirely.

Proposed solution

Register a new mssql_arrow backend that:

  1. Executes the query through SQLAlchemy (compilation, parameters, credentials unchanged)
  2. Accesses the raw DBAPI cursor from the CursorResult
  3. Iterates cursor.arrow_reader(batch_size=chunk_size) for native Arrow batches
  4. Falls back to the standard pyarrow path when arrow_reader is unavailable

An opt-in backend keeps compatibility risk isolated and fits the TableLoader registry from #2736.

Use case

Large SQL Server tables with varbinary(max) columns create substantial memory pressure during extraction. The native path removes the SQLAlchemy/Python tuple layer and one complete Arrow buffer construction.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions