You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FEAT: Add native FLOAT32 and FLOAT16 vector support - #902
Introduce immutable Vector(values, base_type="float32" | "float16"), with .base_type, .dimensions, and normal sequence operations including list(v).
Normalize elements to float32 at construction. Reject non-numeric elements, NaN/infinity, float32 overflow, and conservatively out-of-range FLOAT16 inputs before native binding. Explicitly hinted numeric lists receive the same validation during binding.
Support native scalar and batch binding, typed/all-NULL arrays, explicitly hinted lists, parameter styles, streamed companion text, row fetch APIs, metadata, output converters, transactions, and cursor reuse.
Implement buffered callproc() (1-3 part names, optionally bracket-quoted) with OutputParameter(sql_type, size, scale) / InputOutputParameter(vector) wrappers, multiple results and repeated NULL inputs. Output parameters take the setinputsizes() triple; only SQL_SS_VECTOR is supported today and other types raise NotSupportedError.
Preserve existing unhinted-list and default connection behavior. Pass through VectorTypeSupport=off/v1/v2; both vector base types use float32 application buffers, while ODBC owns FLOAT16 conversion and native serialization.
Preserve the latest parameter-binding reuse and native-fetch behavior. Buffered procedure rows stay on the Python fetch path.
Add documentation, native type declarations, public consumer typing checks, and unit/live SQL coverage. Gate integration tests using server type metadata and the qualified provider, without suppressing connection/query errors on supported configurations.
API example: native reads and writes
connection_string is supplied externally. This FLOAT16 example requires ODBC 18.7.1.1+ and server support; FLOAT32 uses base_type="float32" and a matching SQL column.
The same values work with executemany() and procedure parameter wrappers, e.g. OutputParameter(SQL_SS_VECTOR, 3, 1). Vector bulk copy and Arrow are covered by the follow-up PRs, not this PR.
Validation
Validated on Windows x64 / Python 3.13 with a rebuilt native extension and an isolated source-built Microsoft ODBC 18.7.1.1 provider:
Coverage
Result
Vector unit tests, including numeric boundaries and CI capability gates
Existing Azure input-size, prepared-statement reuse and native-fetch regressions
16 passed
Existing executemany/setinputsizes/decimal/time cursor tests (local SQL Server 2022)
162 passed, 3 pre-existing skips
Strict source/stub typing and consumer API tests
6 passed
Native Release build, full repository-pinned Black check, and whitespace checks passed.
Reran all three vector modes through the final server metadata gate successfully.
Provisioned and tested through Azure CLI, then deleted the isolated SQL server/databases and temporary credentials. Existing resources were untouched.
This is targeted Windows/Azure validation, not a claim that the full suite or cross-platform/provider matrix has completed.
Scope and follow-up
Vector bulk copy and Arrow vector support are intentionally deferred to the next PR. Existing unsupported boundaries raise explicit errors.
New async vector integration and alternate Rust ODBC provider qualification are not included.
Table-valued parameters are intentionally not part of this PR; vector TVP columns will build on the shared TableValuedParameter definition from FEAT: Add table-valued parameter support #789.
Procedure output parameters currently support SQL_SS_VECTOR only; procedure result sets are buffered in memory so output values are final when callproc() returns.
FLOAT32 requires Microsoft ODBC 18.6.1.1+; FLOAT16/v2 requires 18.7.1.1+ and server support. This PR does not replace bundled binaries.
Use server type metadata and the qualified provider to skip unsupported CI legs without hiding connection failures. Cover both gate outcomes and cleanup.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Unix / SQL Server 2022: Python 3.12.3, x86_64, SQL 16.0.4325.4; 5 paired comparisons and 1 warmup.
Unix / SQL Server 2025: Python 3.12.3, x86_64, SQL 17.0.5065.9; 5 paired comparisons and 1 warmup.
A consistent change requires more than 20% median paired movement, at least 1 ms between the median runtimes, and at least 80% of pairs exceeding the relative threshold in the same direction. A slowdown without enough pair agreement is reported as inconsistent.
The displayed change is the median of paired before-and-after ratios. It is not recalculated from the two displayed median runtimes.
Both revisions use profiling-enabled builds on the same agent and database, with alternating order and discarded warmups. Results are diagnostic and do not represent production-wheel latency.
Raw samples and logs are attached to the ADO run as profiler-* artifacts.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A failing callproc() can leave stale cache state, causing subsequent execution of the previous SQL to skip preparation even though the handle is prepared for the procedure.
Adds opt-in FLOAT32/FLOAT16 vector support to the synchronous Python API and native ODBC bindings, extending parameter binding, row fetching, and stored-procedure support.
Changes:
Introduces immutable Vector values with numeric validation, explicit list hints, and connection-level vector negotiation.
Adds scalar and batch binding, typed table-valued parameters, and buffered callproc() with vector output wrappers.
Adds documentation, type declarations, and unit/live SQL coverage. Vector bulk copy, Arrow fetches, and async integration remain out of scope.
File
Description
tests/test_typing.py
Checks public vector API call shapes.
tests/test_025_vector.py
Adds vector unit contracts and live SQL coverage.
tests/test_004_cursor.py
Replaces the unsupported-callproc test with name validation.
README.md
Documents vector APIs, requirements, limitations, and testing.
mssql_python/vector.py
Defines validated vectors and procedure output wrappers.
mssql_python/table_parameter.py
Defines explicit table schemas and row snapshots.
mssql_python/pybind/vector_support.hpp
Implements native vector buffers and conversion.
mssql_python/pybind/py_type_cache.hpp
Caches vector and table-parameter classes.
mssql_python/pybind/param_detect.hpp
Detects vector/table parameters and applies vector hints.
mssql_python/pybind/ddbc_bindings.h
Adds vector and table-parameter ODBC constants.
mssql_python/pybind/ddbc_bindings.cpp
Implements binding, vector fetching, and buffered procedure execution.
mssql_python/mssql_python.pyi
Exposes new public types and the vector constant.
mssql_python/ddbc_bindings.py
Adds typing imports for native vector helpers.
mssql_python/cursor.py
Integrates vector batches, buffered procedures, and unsupported-operation guards.
mssql_python/constants.py
Registers vector types and the negotiation keyword.
mssql_python/connection_string_parser.py
Validates and normalizes VectorTypeSupport.
mssql_python/_native_fetch.py
Keeps buffered procedure results on Python fetch paths.
mssql_python/_ddbc_types.pyi
Declares native vector helpers and procedure results.
mssql_python/__init__.py
Exports the new public API.
CHANGELOG.md
Records vector support and its current limitations.
2840ifsql_type==ddbc_sql_const.SQL_SS_VECTOR.value:
2841frommssql_python.vectorimport_check_shape28422843ifdecimal_digitsnotin (0, 1):
! 2844raiseValueError("Vector subtype must be 0 (FLOAT32) or 1 (FLOAT16)")
2845_check_shape(column_size, "float16"ifdecimal_digitselse"float32")
2846paraminfo.columnSize=ddbc_bindings._vector_buffer_size(column_size)
2847paraminfo.isDAE=is_dae
Lines 4685-4693
4685ifnotisinstance(procname, str) ornotprocnameor"\0"inprocname:
4686raiseValueError("procname must be a non-empty procedure name")
4687name=_quote_procedure_name(procname)
4688ifisinstance(parameters, (str, bytes, bytearray)):
! 4689raiseTypeError("parameters must be a sequence of parameter values")
4690values=list(parameters) ifparametersisnotNoneelse []
4691query="{CALL "+name+"("+",".join("?"for_invalues) +")}"4692self._soft_reset_cursor()
4693self.messages= []
Invalidate prepared-query caches before calling procedures and reject overwritten non-vector INPUT_OUTPUT values before native binding. Add unit and Azure regressions and remove a stale TODO.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pushed review fixes in 9c515b5 and re-reviewed the updated feature diff.
Fixed the valid prepared-statement cache finding: both caches are invalidated before DDBCCallProc, including failure paths. Added the exact execute -> failing callproc -> execute regression, plus live missing-procedure and execution-error cases for all three vector configurations.
Re-review also found that overwriting InputOutputParameter.value with a non-vector could reach ODBC without validation. Native code now rejects it before preparation/binding; added 15 live cases covering invalid values and subsequent cursor reuse.
Removed the carried-over TODO comment. Replied inline to all seven localhost warnings with the parser/mock evidence; those are test-only false positives, so the fixtures were not changed.
Validation passed:
Release native build.
114 vector unit tests and 6 strict source/stub/API typing tests.
All 188 Azure vector E2E cases, zero skipped: v1/FLOAT32, v2/FLOAT32 and v2/FLOAT16 using isolated ODBC 18.7.1.1.
16 existing live input-size, prepared-statement and native-fetch regressions.
Pinned full-directory Black check, commit/push hooks and whitespace checks.
Both regressions were observed failing before their respective fixes. Temporary Azure servers were deleted and deletion was verified.
The previous ADO validation failures are separate setup blockers, not failing vector assertions:
Nine jobs fail while installing mssql-python-rs==0.5.0.dev20261117: the public nightly feed reports either no matching distribution or HTTP 403 (anonymous identity lacks Reader permission). The same 403 occurs on main in build 192647.
macOS x86_64 SQL2025 fails before tests because the SQL Server container exits with "Failed to load LSA: 0xc0000001", including its retry.
The Debian result-copy failures are secondary to the dependency installation failure.
I have not changed runtime pins, disabled jobs or weakened validation to hide these failures. The feed's intended public access/authentication and the macOS SQL container/runner need to be restored by their owners before the standard matrix can go green.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
An empty buffered procedure result consumed by fetchall() leaves rowcount at -1 instead of 0; exhaustion handling needs correction and a regression test.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Empty buffered fetchall leaves rowcount at -1
mssql_python/cursor.py:3299
For an empty buffered procedure result set, fetchall() calls fetchmany(0), which returns before updating rowcount. This leaves rowcount at -1 after the result is consumed, unlike fetchone() and fetchmany(), which set it to 0. Request at least one row to process exhaustion, and add an empty buffered-result regression.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
An empty buffered procedure result leaves rowcount at -1 after fetchall() instead of finalizing it to 0, requiring a fetch-path fix and regression coverage.
Bind TVP TIME columns as text so fractional seconds survive, size numeric/time text buffers separately from SQL precision, normalize non-Decimal DECIMAL/NUMERIC TVP cells like executemany(), and finalize rowcount when fetchall() exhausts an empty buffered procedure result. Add unit and live regressions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Native ABI, TVP handling, and buffer cleanup across new ODBC paths need human review because reported validation is Windows-only and this environment cannot perform cross-platform or live SQL/fault-injection checks.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Platform-sensitive native ABI and buffer-ownership changes need cross-platform runtime and failure-path validation beyond the reported Windows x64 checks, which could not be independently verified.
The reason will be displayed to describe this comment to others. Learn more.
vector reads and writes work end to end for float32, including batches and procedure outputs. two things need to change before merge: the table-valued parameter API here collides with the one already in review, and batch inserts got slower for users who never touch vectors. requesting changes.
Drop the PR-local TableValuedParameter and TVP binder so the shared TVP definition (#789) is the single public API; vector TVP columns will build on it. Restore main's array-binding buffer ownership.
OutputParameter now takes the setinputsizes (sql_type, size, scale) triple; only SQL_SS_VECTOR is supported and other types raise NotSupportedError. InputOutputParameter infers its type from the initial Vector.
Avoid per-cell ABC isinstance scans in executemany() and bulkcopy() by gating on exact Vector type. Build fetched and output vectors through a cached trusted constructor instead of revalidating driver-produced values. Add a bulk fast path for list/tuple float inputs with identical values and errors. Accept bracket-quoted callproc name parts and reject malformed brackets.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Complete dropping the PR-local TVP API in favor of the shared definition (#789); nothing imports this module any more.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The table-valued parameter class lacks a public export and execution/binding integration, leaving the advertised support unimplemented and inconsistent with the README’s deferred scope.
FLOAT16 is preview-only on SQL Server 2025 (PREVIEW_FEATURES) and GA on Azure SQL DB, MI and Fabric. The driver never converts between vector base types; SQL Server converts native FLOAT32/FLOAT16 parameters to the column type, matching Microsoft.Data.SqlClient. Add a live test pinning conversion, rounding and the out-of-range error.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pick up the reviewed #902 changes (TVP removal, OutputParameter triple, trusted vector construction, exact Vector type checks, SQL Server 2025 FLOAT16 preview docs).
Align vector bulk copy and Arrow docs/tests with Microsoft.Data.SqlClient: the client never converts between base types; columns are declared with their source base type (JSON text for FLOAT16 columns as text) and SQL Server converts them. Replace base-type mismatch rejection tests with live conversion, rounding, out-of-range and mixed-column tests.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because buffered callproc() results can leave skip() and scroll() out of sync with subsequent fetches and row-position counters.
No open issues 🎉
Review effort: Balanced
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
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
Add opt-in synchronous native FLOAT32/FLOAT16 vector support.
Vector(values, base_type="float32" | "float16"), with.base_type,.dimensions, and normal sequence operations includinglist(v).callproc()(1-3 part names, optionally bracket-quoted) withOutputParameter(sql_type, size, scale)/InputOutputParameter(vector)wrappers, multiple results and repeated NULL inputs. Output parameters take thesetinputsizes()triple; onlySQL_SS_VECTORis supported today and other types raiseNotSupportedError.VectorTypeSupport=off/v1/v2; both vector base types use float32 application buffers, while ODBC owns FLOAT16 conversion and native serialization.API example: native reads and writes
connection_stringis supplied externally. This FLOAT16 example requires ODBC 18.7.1.1+ and server support; FLOAT32 usesbase_type="float32"and a matching SQL column.The same values work with
executemany()and procedure parameter wrappers, e.g.OutputParameter(SQL_SS_VECTOR, 3, 1). Vector bulk copy and Arrow are covered by the follow-up PRs, not this PR.Validation
Validated on Windows x64 / Python 3.13 with a rebuilt native extension and an isolated source-built Microsoft ODBC 18.7.1.1 provider:
Scope and follow-up
TableValuedParameterdefinition from FEAT: Add table-valued parameter support #789.SQL_SS_VECTORonly; procedure result sets are buffered in memory so output values are final whencallproc()returns.