FEAT: Support for Apache Arrow in Bulk Copy API - #665
Draft
gargsaumya wants to merge 13 commits into
Draft
Conversation
Adds cursor.bulkcopy_arrow(table_name, source) to bulk-load directly from Apache Arrow data (pyarrow Table/RecordBatch/RecordBatchReader, __arrow_c_stream__/__arrow_c_array__ producers, or an iterable of batches) via the mssql_py_core Rust core, streaming through the Arrow C Data Interface with the GIL released during transfer. bulkcopy() now raises TypeError to steer Arrow inputs here. Auth setup is refactored into a shared _build_pycore_context() helper (preserves SQL, pre-acquired-token, and ServicePrincipal factory paths). Adds tests/test_024_bulkcopy_arrow.py (36 unit tests at 100% coverage of the new code + 16 live round-trip/type-matrix tests) and benchmarks/bench_bulkcopy_arrow.py. Requires mssql-py-core 0.1.5+.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Apache Arrow support to the Bulk Copy API by introducing a dedicated Cursor.bulkcopy_arrow() path and refactoring shared connection/auth context construction so both tuple-based and Arrow-based bulk copy use consistent handling.
Changes:
- Added
Cursor.bulkcopy_arrow(table_name, source)and Arrow-source detection/steering to prevent Arrow inputs from going through tuple bulkcopy. - Refactored bulk-copy connection/auth parsing into
Cursor._build_pycore_context()for reuse across bulk copy entry points. - Added comprehensive tests and a benchmark comparing tuple vs Arrow bulk copy throughput.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_024_bulkcopy_arrow.py | Adds unit + live-DB integration coverage for Arrow bulk copy, auth context building, and Arrow-source detection. |
| mssql_python/mssql_python.pyi | Updates public type stubs to include bulkcopy and new bulkcopy_arrow API. |
| mssql_python/cursor.py | Implements _build_pycore_context, Arrow source detection/steering, and the new bulkcopy_arrow method. |
| CHANGELOG.md | Documents the new Arrow bulk copy feature and related requirements/behavior changes. |
| benchmarks/bench_bulkcopy_arrow.py | Adds a benchmark script comparing tuple-based vs Arrow-based bulk copy performance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gargsaumya
marked this pull request as draft
July 8, 2026 07:47
…sign D13) Remove the keyword-only '*' from Cursor.bulkcopy_arrow (cursor.py + stub) so batch_size/timeout match bulkcopy's signature per the finalized design (D13/section 2). Also set cursor._timeout in the test mock-cursor helper (main's #650 added self._timeout to the shared _build_pycore_context) and add a positional-args regression test.
…al (List[str]) semantics
…w_c_array__); use non-localhost host in unit-test conn strings
…s, memory, MB/s, CSV)
…oney/xml/legacy-datetime/date64/fixed-binary
# Conflicts: # tests/test_019_bulkcopy.py
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 59.9%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 76.3%
mssql_python.__init__.py: 77.3%
mssql_python.row.py: 77.6%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 81.4%
mssql_python.pybind.connection.connection.cpp: 83.7%
mssql_python.connection.py: 84.7%🔗 Quick Links
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work Item / Issue Reference
Summary
This pull request introduces a new high-performance
bulkcopy_arrowmethod to theCursorclass for bulk loading data directly from Apache Arrow sources, along with several related improvements and refactorings. It also updates type stubs and documentation to reflect the new API, and improves bulk copy authentication handling by refactoring shared logic.New feature: Arrow-based bulk copy
Cursor.bulkcopy_arrow(table_name, source)for efficient bulk loading from Arrow sources (e.g.,pyarrow.Table,RecordBatch, objects exposing the Arrow C Data Interface). This avoids unnecessary Python row materialization and is significantly faster for Arrow-native data. [1] [2]bulkcopy()method now raises aTypeErrorif given Arrow-shaped data, steering users to the new method.Codebase refactoring and improvements
_build_pycore_context()helper, used by bothbulkcopyandbulkcopy_arrow. This ensures consistent authentication handling and reduces code duplication. [1] [2]mssql_python.pyi) to include the newbulkcopy_arrowmethod and improved the typing forbulkcopy. [1] [2]Documentation
CHANGELOG.mdto document the new Arrow bulk copy feature and its requirements.Minor improvements
test_bulkcopy_udt_geometry).