Skip to content

FEAT: Add native FLOAT32 and FLOAT16 vector support - #902

Merged
gargsaumya merged 27 commits into
mainfrom
saumya/vector-support
Nov 24, 2026
Merged

gargsaumya merged 27 commits into
mainfrom
saumya/vector-support

Conversation

@gargsaumya

@gargsaumya gargsaumya commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Work Item / Issue Reference

AB#50380


Summary

Add opt-in synchronous native FLOAT32/FLOAT16 vector support.

  • 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.

from mssql_python import Vector, connect

with connect(connection_string, VectorTypeSupport="v2") as connection:
    with connection.cursor() as cursor:
        cursor.execute("CREATE TABLE #VectorData (value VECTOR(3, FLOAT16) NULL)")
        v = Vector([1.0, 2.0, 3.0], base_type="float16")
        cursor.execute("INSERT INTO #VectorData VALUES (?)", v)
        cursor.execute("SELECT value FROM #VectorData")
        result = cursor.fetchone()[0]  # Vector; SQL NULL returns None
        values = list(result)

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 144 passed
Azure SQL vector E2E: v1/FLOAT32, v2/FLOAT32, v2/FLOAT16 194 passed, zero skipped
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.
gargsaumya and others added 2 commits November 17, 2026 11:01
Add immutable base_type-aware vectors, hinted list binding, TVPs and buffered procedure outputs. Include numeric validation, documentation and unit/live SQL coverage. Vector bulk copy and Arrow remain explicit follow-up work.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 05:43
@github-actions github-actions Bot added the pr-size: large Substantial code update label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

PR Performance Report

✅ No regression detected

No consistent slowdowns detected across all 2 environments.

0 IMPROVEMENTS 0 SLOWDOWNS 2/2 ENVIRONMENTS

Coverage: 2 of 2 environments completed. Advisory result; does not block merging.

Performance diagnostics

Phase times are inclusive diagnostics and must not be added together. They identify where measured time changed, not why it changed.

No affected phases or call-count changes were recorded.

All database tasks and timings

Unix / SQL Server 2022

Database task Before After Paired change Result
Connection opening 10.024 ms 10.006 ms +0.2% no signal
SELECT queries 0.979 ms 0.982 ms +2.4% no signal
Row insertion 30.904 ms 30.601 ms -0.8% no signal
Executemany inserts 157.330 ms 154.835 ms -0.9% no signal
Fetch-all queries 119.309 ms 119.086 ms -0.3% no signal
Row-by-row fetching 4.973 ms 5.012 ms +1.1% no signal
Batched row fetching 118.315 ms 116.622 ms -0.6% no signal
Transaction commit and rollback 105.065 ms 106.483 ms +1.8% no signal
Arrow row fetching 89.036 ms 89.670 ms +0.4% no signal
100,000-row insertion 354.501 ms 369.926 ms +1.7% no signal
Row fetching in batches of 100 121.100 ms 125.689 ms +3.9% no signal
Row fetching in batches of 10,000 122.673 ms 135.715 ms +3.9% no signal
Repeated positional queries 32.917 ms 32.098 ms -3.2% no signal
Repeated named-parameter queries 32.670 ms 32.697 ms +0.1% no signal
Legacy 100,000-row insertion 281.411 ms 271.389 ms +2.4% no signal
Insertion with explicit input sizes 403.983 ms 422.703 ms +3.9% no signal
Joined aggregation queries 183.088 ms 181.647 ms -0.4% no signal
Large joined-result fetching 193.181 ms 188.768 ms -3.7% no signal
1.2-million-row fetching 3455.547 ms 3463.280 ms -0.1% no signal
Common table expression queries 5.397 ms 5.335 ms -2.0% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.161 ms 1.679 ms +36.0% no signal
10,000 scalar values / fetchval() (debug disabled) 16.758 ms 16.842 ms +0.7% no signal
10,000 output-converted rows / fetchall() 19.336 ms 19.555 ms +0.3% no signal
10,000 output-converted rows / fetchmany(1000) 23.945 ms 28.762 ms +6.5% no signal
10,000 INT/NVARCHAR rows / fetchmany(1) 24.650 ms 25.007 ms +2.9% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 30.756 ms 31.370 ms +0.3% no signal

Unix / SQL Server 2025

Database task Before After Paired change Result
Connection opening 82.812 ms 82.100 ms -0.6% no signal
SELECT queries 1.076 ms 1.112 ms -2.1% no signal
Row insertion 31.113 ms 31.353 ms -0.8% no signal
Executemany inserts 161.659 ms 160.850 ms -0.5% no signal
Fetch-all queries 126.187 ms 128.242 ms -0.7% no signal
Row-by-row fetching 5.050 ms 5.033 ms -0.3% no signal
Batched row fetching 130.622 ms 121.054 ms -7.3% no signal
Transaction commit and rollback 115.262 ms 108.433 ms -4.4% no signal
Arrow row fetching 95.413 ms 97.187 ms -0.8% no signal
100,000-row insertion 378.055 ms 364.821 ms +0.9% no signal
Row fetching in batches of 100 125.424 ms 126.632 ms +1.2% no signal
Row fetching in batches of 10,000 146.370 ms 151.332 ms -0.8% no signal
Repeated positional queries 32.743 ms 32.415 ms -1.5% no signal
Repeated named-parameter queries 32.880 ms 32.786 ms +1.4% no signal
Legacy 100,000-row insertion 296.573 ms 284.655 ms -3.9% no signal
Insertion with explicit input sizes 419.200 ms 439.619 ms +4.7% no signal
Joined aggregation queries 167.507 ms 167.052 ms +1.0% no signal
Large joined-result fetching 202.789 ms 205.079 ms +1.1% no signal
1.2-million-row fetching 3745.756 ms 3671.829 ms -2.2% no signal
Common table expression queries 5.626 ms 5.334 ms -3.8% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.499 ms 2.002 ms +1.5% no signal
10,000 scalar values / fetchval() (debug disabled) 16.866 ms 17.212 ms +2.1% no signal
10,000 output-converted rows / fetchall() 19.992 ms 20.096 ms -0.5% no signal
10,000 output-converted rows / fetchmany(1000) 25.295 ms 25.851 ms +2.2% no signal
10,000 INT/NVARCHAR rows / fetchmany(1) 24.839 ms 24.784 ms +0.7% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 32.476 ms 32.556 ms +2.7% no signal
Build and measurement details

ADO build 194697

PR head: bda79e1504160f23c1e0a11b819a0324fd56564b
Base: 389a318a306dbf880d503037ed8bb2d32a2bd8c3
Measured merge: 92392575b795c6ac6d83f3fee3fac8a15e3e4b47

  • 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.

Comment thread tests/test_025_vector.py Dismissed
Comment thread tests/test_025_vector.py Dismissed
Comment thread tests/test_025_vector.py Dismissed
Comment thread tests/test_025_vector.py Dismissed
Comment thread tests/test_025_vector.py Dismissed
Comment thread tests/test_025_vector.py Dismissed
Comment thread tests/test_025_vector.py Dismissed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
What changed in this PR

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.

Review effort: Balanced

Comment thread mssql_python/cursor.py Resolved
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

📊 Code Coverage Report

🔥 Diff Coverage

91%


🎯 Overall Coverage

85%


📈 Total Lines Covered: 12647 out of 14743
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

  • mssql_python/init.py (100%)
  • mssql_python/_native_fetch.py (100%)
  • mssql_python/connection_string_parser.py (100%)
  • mssql_python/constants.py (100%)
  • mssql_python/cursor.py (98.8%): Missing lines 2897,4799
  • mssql_python/pybind/ddbc_bindings.cpp (86.2%): Missing lines 496-497,566-570,574-575,578,2566-2569,2580,2595-2597,3846-3848,6930-6932,6940-6941
  • mssql_python/pybind/ddbc_bindings.h (100%)
  • mssql_python/pybind/param_detect.hpp (89.7%): Missing lines 265-266,274
  • mssql_python/pybind/py_type_cache.hpp (100%)
  • mssql_python/pybind/vector_support.hpp (59.5%): Missing lines 29,31,52,56,65-73,76-79
  • mssql_python/vector.py (100%)

Summary

  • Total: 565 lines
  • Missing: 48 lines
  • Coverage: 91%

mssql_python/cursor.py

Lines 2893-2901

  2893                     if sql_type == ddbc_sql_const.SQL_SS_VECTOR.value:
  2894                         from mssql_python.vector import _check_shape
  2895 
  2896                         if decimal_digits not in (0, 1):
! 2897                             raise ValueError("Vector subtype must be 0 (FLOAT32) or 1 (FLOAT16)")
  2898                         _check_shape(column_size, "float16" if decimal_digits else "float32")
  2899                         paraminfo.columnSize = ddbc_bindings._vector_buffer_size(column_size)
  2900                     paraminfo.isDAE = is_dae

Lines 4795-4803

  4795             if not isinstance(procname, str) or not procname or "\0" in procname:
  4796                 raise ValueError("procname must be a non-empty procedure name")
  4797             name = _quote_procedure_name(procname)
  4798             if isinstance(parameters, (str, bytes, bytearray)):
! 4799                 raise TypeError("parameters must be a sequence of parameter values")
  4800             values = list(parameters) if parameters is not None else []
  4801             if any(isinstance(value, TableValuedParameter) for value in values):
  4802                 raise NotSupportedError(
  4803                     "callproc() does not support table-valued parameters",

mssql_python/pybind/ddbc_bindings.cpp

Lines 492-501

  492         auto resolved = ResolveNullParamType(handle, hStmt, static_cast<int>(paramIndex));
  493         paramInfo.paramSQLType = resolved.sqlType;
  494         paramInfo.columnSize = resolved.columnSize;
  495         paramInfo.decimalDigits = resolved.decimalDigits;
! 496         if (resolved.sqlType == SQL_SS_VECTOR) {
! 497             if (resolved.columnSize < sizeof(SQL_SS_VECTOR_STRUCT) ||
  498                 (resolved.columnSize - sizeof(SQL_SS_VECTOR_STRUCT)) % sizeof(float) != 0)
  499                 throw py::value_error("ODBC returned invalid vector parameter metadata");
  500             size_t dimensions =
  501                 (resolved.columnSize - sizeof(SQL_SS_VECTOR_STRUCT)) / sizeof(float);

Lines 562-582

  562                                void*& dataPtr, SQLLEN& bufferLength, SQLLEN*& strLenOrIndPtr,
  563                                bool tableCell = false) {
  564         // TODO: Add more data types like money, guid, interval, TVPs etc.
  565         switch (paramInfo.paramCType) {
! 566             case SQL_C_SS_VECTOR: {
! 567                 if (!paramInfo.vectorBinding) {
! 568                     if (param.is_none())
! 569                         throw std::logic_error("Internal error: missing binding for a typed NULL vector parameter");
! 570                     paramInfo.vectorBinding = std::make_shared<VectorBinding>(param);
  571                 }
  572                 auto binding = paramInfo.vectorBinding;
  573                 paramBuffers.push_back(binding);
! 574                 dataPtr = &binding->value;
! 575                 bufferLength = static_cast<SQLLEN>(VectorBufferSize(binding->elements.size()));
  576                 strLenOrIndPtr = &binding->indicator;
  577                 break;
! 578             }
  579             case SQL_C_CHAR: {
  580                 if (!py::isinstance<py::str>(param) && !py::isinstance<py::bytearray>(param) &&
  581                     !py::isinstance<py::bytes>(param)) {
  582                     ThrowStdException(MakeParamMismatchErrorStr(paramInfo.paramCType, paramIndex));

Lines 2562-2573

  2562             SQLLEN bufferLength = 0;
  2563             switch (info.paramCType) {
  2564                 case SQL_C_SS_VECTOR: {
  2565                     size_t dimensions = 0;
! 2566                     int subtype = info.decimalDigits;
! 2567                     for (auto item : columnValues) {
! 2568                         if (!item.is_none()) {
! 2569                             dimensions = item.attr("dimensions").cast<size_t>();
  2570                             subtype = item.attr("base_type").cast<std::string>() == "float16" ? 1 : 0;
  2571                             break;
  2572                         }
  2573                     }

Lines 2576-2584

  2576                             throw std::logic_error("Internal error: missing metadata for an all-NULL vector array");
  2577                         dimensions = (info.columnSize - sizeof(SQL_SS_VECTOR_STRUCT)) / sizeof(float);
  2578                     }
  2579                     ValidateVectorShape(dimensions, subtype);
! 2580                     if (info.columnSize != VectorBufferSize(dimensions) ||
  2581                         info.decimalDigits != subtype)
  2582                         throw py::value_error("Vector array must match its declared dimensions and subtype");
  2583                     auto structs = AllocateParamBufferArray<SQL_SS_VECTOR_STRUCT>(
  2584                         tempBuffers, paramSetSize);

Lines 2591-2601

  2591                             throw py::value_error("Vector array dimensions and subtype must agree");
  2592                         structs[i] = binding->value;
  2593                         strLenOrIndArray[i] = binding->indicator;
  2594                         tempBuffers.push_back(binding);
! 2595                     }
! 2596                     dataPtr = structs;
! 2597                     bufferLength = static_cast<SQLLEN>(VectorBufferSize(dimensions));
  2598                     info.columnSize = static_cast<SQLULEN>(bufferLength);
  2599                     info.decimalDigits = static_cast<SQLSMALLINT>(subtype);
  2600                     break;
  2601                 }

Lines 3842-3852

  3842                     static_cast<SQLLEN>(VectorBufferSize(dimensions)), &binding.indicator);
  3843             }
  3844             CaptureFetchDiagnostics(hStmt, ret, messages);
  3845             if (!SQL_SUCCEEDED(ret)) return ret;
! 3846             row.append(binding.toPython());
! 3847             continue;
! 3848         }
  3849 
  3850         // Preprocess sql_variant: detect underlying type to route to correct conversion logic
  3851         SQLSMALLINT effectiveDataType = dataType;
  3852         if (dataType == SQL_SS_VARIANT) {

Lines 6926-6936

  6926     CheckFetchError(statement, rc);
  6927     {
  6928         py::gil_scoped_release release;
  6929         rc = SQLExecute_ptr(hStmt);
! 6930     }
! 6931     CheckFetchError(statement, rc);
! 6932     CaptureFetchDiagnostics(hStmt, rc, messages);
  6933     py::list results;
  6934     while (rc != SQL_NO_DATA) {
  6935         py::list metadata, rows;
  6936         rc = SQLDescribeCol_wrap(statement, metadata, messages);

Lines 6936-6945

  6936         rc = SQLDescribeCol_wrap(statement, metadata, messages);
  6937         CheckFetchError(statement, rc);
  6938         SQLLEN rowCount = -1;
  6939         rc = SQLRowCount_ptr(hStmt, &rowCount);
! 6940         CheckFetchError(statement, rc);
! 6941         if (!metadata.empty()) {
  6942             rc = FetchAll_wrap(statement, rows, charEncoding, wcharEncoding, charCtype, messages);
  6943             CheckFetchError(statement, rc);
  6944             rowCount = -1;
  6945         }

mssql_python/pybind/param_detect.hpp

Lines 261-270

  261         auto dimensions = static_cast<size_t>(info.columnSize);
  262         py::object vector = py::module_::import("mssql_python.vector")
  263             .attr("_vector_from_hint")(borrow(obj), dimensions, info.decimalDigits);
  264         if (PyList_SetItem(params, index, vector.release().ptr()) != 0) {
! 265             throw py::error_already_set();
! 266         }
  267         obj = PyList_GET_ITEM(params, index);
  268         info.paramCType = SQL_C_SS_VECTOR;
  269         info.vectorBinding = obj == Py_None
  270             ? std::make_shared<VectorBinding>(dimensions, info.decimalDigits)

Lines 270-278

  270             ? std::make_shared<VectorBinding>(dimensions, info.decimalDigits)
  271             : std::make_shared<VectorBinding>(borrow(obj));
  272         if (info.vectorBinding->value.dimension != dimensions ||
  273             info.vectorBinding->value.type != info.decimalDigits)
! 274             throw py::value_error("Vector dimensions and subtype must match setinputsizes");
  275         info.columnSize = VectorBufferSize(dimensions);
  276         info.isDAE = false;
  277         return;
  278     }

mssql_python/pybind/vector_support.hpp

Lines 25-35

  25 }
  26 
  27 inline void ValidateVectorShape(size_t dimensions, int subtype) {
  28     if (subtype != 0 && subtype != 1)
! 29         throw py::value_error("Invalid vector subtype; expected FLOAT32 (0) or FLOAT16 (1)");
  30     if (dimensions == 0 || dimensions > (subtype == 0 ? 1998u : 3996u))
! 31         throw py::value_error("Invalid vector dimensions for the selected subtype");
  32 }
  33 
  34 struct VectorBinding {
  35     std::vector<float> elements;

Lines 48-60

  48         : VectorBinding(source.attr("dimensions").cast<size_t>(),
  49                         source.attr("base_type").cast<std::string>() == "float16" ? 1 : 0) {
  50         auto values = source.attr("values").cast<py::tuple>();
  51         if (values.size() != elements.size())
! 52             throw py::value_error("Vector dimensions do not match its values");
  53         for (size_t i = 0; i < elements.size(); ++i) {
  54             double number = values[i].cast<double>();
  55             if (!std::isfinite(number) || std::abs(number) > std::numeric_limits<float>::max())
! 56                 throw py::value_error("Vector elements must be finite float32 values");
  57             elements[i] = static_cast<float>(number);
  58         }
  59         indicator = static_cast<SQLLEN>(VectorBufferSize(elements.size()));
  60     }

Lines 61-81

  61 
  62     VectorBinding(const VectorBinding&) = delete;
  63     VectorBinding& operator=(const VectorBinding&) = delete;
  64 
! 65     py::object toPython() const {
! 66         if (indicator == SQL_NULL_DATA) return py::none();
! 67         ValidateVectorShape(value.dimension, value.type);
! 68         if (static_cast<size_t>(value.dimension) > elements.size() ||
! 69             indicator != static_cast<SQLLEN>(VectorBufferSize(value.dimension)))
! 70             throw py::value_error("ODBC returned an invalid vector length");
! 71         py::tuple values(value.dimension);
! 72         for (size_t i = 0; i < static_cast<size_t>(value.dimension); ++i)
! 73             values[i] = py::float_(elements[i]);
  74         // The shape check above covers what ODBC can get wrong, and SQL Server cannot
  75         // store non-finite elements, so skip the public constructor's per-element checks.
! 76         PyTypeCache::initialize();
! 77         return py::reinterpret_borrow<py::object>(PyTypeCache::vector_from_trusted)(
! 78             values, value.type == SQL_VECTOR_TYPE_FLOAT16 ? "float16" : "float32");
! 79     }
  80 };


📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.performance_counter.hpp: 0.7%
mssql_python.pybind.logger_bridge.cpp: 57.9%
mssql_python.pybind.vector_support.hpp: 59.5%
mssql_python.pybind.ddbc_bindings.h: 65.1%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python._native_fetch.py: 78.1%
mssql_python.pybind.ddbc_bindings.cpp: 79.5%
mssql_python.__init__.py: 81.4%
mssql_python.pybind.row_mapping_cache.hpp: 81.5%
mssql_python.pybind.connection.connection_pool.cpp: 82.5%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

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>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 08:00
@gargsaumya

Copy link
Copy Markdown
Contributor Author

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.

Evidence: PR build 192677, main build 192647.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Medium severity 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.

1 resolved since last review

Review effort: Balanced

Comment thread mssql_python/pybind/ddbc_bindings.cpp Resolved
Comment thread mssql_python/pybind/ddbc_bindings.cpp Resolved
Comment thread mssql_python/cursor.py Resolved
Copilot AI balanced review requested due to automatic review settings November 18, 2026 05:08
@gargsaumya
gargsaumya enabled auto-merge (squash) November 18, 2026 05:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue

Review effort: Balanced

Comment thread mssql_python/cursor.py Resolved
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>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 07:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 18, 2026 08:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Native ODBC vector ABI, buffer-lifetime, and error-cleanup changes require cross-platform runtime validation beyond the supplied Windows-only evidence.

No open issues 🎉

Review effort: Balanced

Comment thread mssql_python/pybind/param_detect.hpp Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Pointer-bearing ODBC vector bindings and buffered procedure-output lifetimes require cross-platform native runtime validation beyond the reported Windows x64 coverage, which this review environment could not independently perform.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 09:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Pointer-bearing ODBC bindings and buffered procedure cleanup involve native ownership and failure-path lifetimes that require human assessment because cross-platform and provider validation beyond reported Windows checks could not be independently performed.

No open issues 🎉

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 10:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Pointer-bearing vector ABI, array binding, and procedure-output cleanup need cross-platform runtime validation beyond the reported Windows x64 checks, which this environment cannot perform.

No open issues 🎉

Review effort: Balanced

Comment thread mssql_python/pybind/ddbc_bindings.cpp Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 11:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Native vector bindings and buffered procedure/output lifetimes require cross-platform and provider runtime validation beyond the reported Windows x64 coverage, which this read-only environment cannot perform.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 11:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Native vector buffer ABI, parameter lifetimes, and buffered procedure cleanup require maintainer runtime validation across supported platforms and providers beyond the reported Windows-only coverage.

No open issues 🎉

Review effort: Balanced

@gargsaumya
gargsaumya merged commit 599e483 into main Nov 24, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: large Substantial code update

7 participants