Skip to content

FEAT: Add native JSON columns to synchronous TVPs - #929

Draft
Jahnvi Thakkar (jahnvi480) wants to merge 2 commits into
mainfrom
jahnvi/json-api-coverage-study
Draft

Jahnvi Thakkar (jahnvi480) wants to merge 2 commits into
mainfrom
jahnvi/json-api-coverage-study

Conversation

@jahnvi480

Copy link
Copy Markdown
Contributor

Work Item / Issue Reference

N/A; related GitHub issue below.

GitHub Issue: #261


Summary

Add native JSON columns to the existing synchronous TableValuedParameter API.

  • Declare columns with SQL_JSON and pass Json snapshots or None. JSON size/scale must be omitted or zero; bare dict/list/str cells are rejected.
  • Bind native SQL_SS_JSON / SQL_C_WCHAR child columns. Unwrap Json text only in the copied binding row, without parsing, reserializing or mutating caller rows.
  • Preserve lazy generators, large Unicode cell streaming, SQL NULLs, multiple TVPs/scalars, execution-scoped JSON output and statement recovery. Unsupported providers retain ODBC diagnostics; there is no text fallback or retry.
  • Add contract, live streaming/results/recovery, shipped-driver rejection and consumer typing coverage; document usage and provider requirements. Async, Rust, bulk/Arrow and callproc TVP support are unchanged.

Validation:

  • Windows x64, Python 3.13.17: build.bat x64 from mssql_python\pybind — passed.
  • Linux x64, Python 3.13.15/GCC 12.2: fresh Release CMake build with two build workers — passed.
  • On each OS, python -m pytest tests/test_028_table_valued_parameters.py tests/test_json.py tests/test_042_execute_param_rebind.py -q --no-cov with the qualified preview and MSSQL_TEST_NATIVE_JSON=1 — 342 passed, 9 expected shipped/legacy skips, 1 stress deselection.
  • Same test selection on Windows with the shipped provider and without the preview flag — 140 passed, 211 expected preview-only skips, 1 stress deselection. Native JSON TVP rejection preserves HY004 and leaves the source unconsumed; cursor reuse succeeds.
  • python -m pytest tests/test_typing.py -m typing -q --no-cov — 9 passed.
  • python -m pre_commit run black-check --all-files --hook-stage pre-push — passed.
  • git diff --check — passed.

Provider/server qualification:

  • Reused native-JSON preview ODBC 18.7.1.1, feature/JsonFeature@ee87e0c6b, build 194329; SQL Server 2025 17.0.5005.3.
  • Windows DLL SHA256: e373fd476d97d4870c1adbac65d0590dd5d7624ddef43c0b7ae5d4711654f635.
  • Linux library SHA256: 85a667eb8e237015d0de2691055ea4c0b0c9235262f68a27f8b7f501f20fe1d0.
  • Actual binary bytes were checked: package metadata still reports 18.6.2.2. Linux used an isolated runtime alias to the verified preview library.
  • Disposable localhost-only SQL containers and the Linux client were removed; absence verified. No preview binaries, credentials, environment changes or test harnesses are included in this PR.
  • These are targeted source-build results, not release enablement or all-platform qualification. macOS, ARM64 and the full repository suite were not run. The shipped provider does not yet support native JSON TVP binding.
Support explicit Json snapshots and NULLs in native JSON TVP columns, preserving lazy streaming and provider diagnostics.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 09:15
@github-actions github-actions Bot added the pr-size: medium Moderate update size label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 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.335 ms 10.589 ms -0.1% no signal
SELECT queries 1.369 ms 1.304 ms -5.8% no signal
Row insertion 31.748 ms 31.554 ms -0.5% no signal
Executemany inserts 165.549 ms 156.954 ms -5.2% no signal
Fetch-all queries 122.674 ms 120.733 ms -0.5% no signal
Row-by-row fetching 6.073 ms 6.277 ms +2.0% no signal
Batched row fetching 118.845 ms 119.884 ms +0.4% no signal
Transaction commit and rollback 108.016 ms 107.539 ms -0.4% no signal
Arrow row fetching 99.407 ms 101.138 ms +2.6% no signal
100,000-row insertion 362.277 ms 363.412 ms +1.3% no signal
Row fetching in batches of 100 128.405 ms 125.196 ms -1.7% no signal
Row fetching in batches of 10,000 135.690 ms 127.563 ms -5.9% no signal
Repeated positional queries 33.760 ms 33.648 ms -1.4% no signal
Repeated named-parameter queries 33.728 ms 33.434 ms -1.0% no signal
Legacy 100,000-row insertion 275.766 ms 273.472 ms -1.0% no signal
Insertion with explicit input sizes 526.301 ms 540.327 ms +3.0% no signal
Joined aggregation queries 182.241 ms 180.588 ms -0.3% no signal
Large joined-result fetching 193.521 ms 194.127 ms +1.0% no signal
1.2-million-row fetching 3606.594 ms 3584.107 ms -0.4% no signal
Common table expression queries 5.706 ms 5.409 ms -4.0% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.343 ms 1.340 ms +5.8% no signal
10,000 scalar values / fetchval() (debug disabled) 20.396 ms 19.431 ms -1.7% no signal
10,000 output-converted rows / fetchall() 19.622 ms 19.791 ms +1.6% no signal
10,000 output-converted rows / fetchmany(1000) 24.552 ms 23.585 ms -2.5% no signal
10,000 INT/NVARCHAR rows / fetchmany(1) 28.311 ms 27.996 ms -1.5% no signal
5,000 x 8 VARCHAR(8000) / ASCII to UTF-16 45.920 ms 45.021 ms -5.2% no signal
5,000 x 8 VARCHAR(8000) / CP1252 to UTF-16 58.464 ms 57.525 ms -2.0% no signal
5,000 x 8 VARCHAR(8000) / UTF-8 to UTF-16 (astral) 112.594 ms 113.185 ms -0.6% no signal
5,000 x 8 NVARCHAR(4000) / UTF-16 (astral) 99.096 ms 96.391 ms -4.9% no signal
5,000 x 8 VARCHAR(8000) / short ASCII 10.490 ms 10.168 ms -3.1% no signal
200 x 8 VARCHAR(8000) / full-width ASCII 44.535 ms 44.471 ms +0.9% no signal
5,000 x 8 VARCHAR(8000) / short CP1252 13.349 ms 12.663 ms -4.9% no signal
200 x 8 VARCHAR(8000) / full-width CP1252 43.841 ms 43.795 ms -0.7% no signal
5,000 x 8 VARCHAR(8000) / short UTF-8 (astral) 16.628 ms 15.785 ms -4.7% no signal
200 x 8 VARCHAR(8000) / full-width UTF-8 (astral) 47.912 ms 47.658 ms -0.5% no signal
5,000 x 8 NVARCHAR(4000) / short UTF-16 (astral) 14.300 ms 14.143 ms -1.8% no signal
200 x 8 NVARCHAR(4000) / full-width UTF-16 (astral) 63.718 ms 63.665 ms +3.2% no signal
200,000 x 8 VARCHAR(32) / fetchall control 550.532 ms 522.070 ms -4.3% no signal
200,000 x 8 INT / fetchall control 288.943 ms 275.644 ms -7.0% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 30.808 ms 31.345 ms +0.6% no signal

Unix / SQL Server 2025

Database task Before After Paired change Result
Connection opening 81.285 ms 81.561 ms +0.2% no signal
SELECT queries 1.437 ms 1.277 ms -8.9% no signal
Row insertion 31.545 ms 31.455 ms -1.2% no signal
Executemany inserts 153.123 ms 153.451 ms +0.2% no signal
Fetch-all queries 123.126 ms 124.006 ms +0.3% no signal
Row-by-row fetching 6.127 ms 6.151 ms -0.1% no signal
Batched row fetching 120.123 ms 119.414 ms -0.9% no signal
Transaction commit and rollback 108.442 ms 107.441 ms -0.8% no signal
Arrow row fetching 99.028 ms 102.445 ms +1.6% no signal
100,000-row insertion 357.590 ms 355.332 ms -0.2% no signal
Row fetching in batches of 100 126.106 ms 128.213 ms +1.7% no signal
Row fetching in batches of 10,000 124.714 ms 124.285 ms -1.1% no signal
Repeated positional queries 32.914 ms 33.110 ms +0.3% no signal
Repeated named-parameter queries 33.350 ms 33.732 ms +0.6% no signal
Legacy 100,000-row insertion 290.862 ms 281.896 ms -1.8% no signal
Insertion with explicit input sizes 527.533 ms 545.627 ms -0.1% no signal
Joined aggregation queries 166.569 ms 165.749 ms +0.2% no signal
Large joined-result fetching 198.047 ms 186.221 ms -1.2% no signal
1.2-million-row fetching 3615.757 ms 3649.365 ms +1.0% no signal
Common table expression queries 5.419 ms 5.372 ms -2.6% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.346 ms 1.671 ms +24.4% no signal
10,000 scalar values / fetchval() (debug disabled) 19.732 ms 19.754 ms -0.5% no signal
10,000 output-converted rows / fetchall() 19.453 ms 20.345 ms +5.2% no signal
10,000 output-converted rows / fetchmany(1000) 24.140 ms 23.400 ms +0.8% no signal
10,000 INT/NVARCHAR rows / fetchmany(1) 28.165 ms 27.934 ms -0.1% no signal
5,000 x 8 VARCHAR(8000) / ASCII to UTF-16 46.851 ms 49.811 ms +6.6% no signal
5,000 x 8 VARCHAR(8000) / CP1252 to UTF-16 75.127 ms 60.957 ms +3.1% no signal
5,000 x 8 VARCHAR(8000) / UTF-8 to UTF-16 (astral) 121.784 ms 119.432 ms -2.5% no signal
5,000 x 8 NVARCHAR(4000) / UTF-16 (astral) 117.936 ms 121.792 ms +3.2% no signal
5,000 x 8 VARCHAR(8000) / short ASCII 10.109 ms 10.008 ms -0.5% no signal
200 x 8 VARCHAR(8000) / full-width ASCII 50.493 ms 50.290 ms +3.6% no signal
5,000 x 8 VARCHAR(8000) / short CP1252 13.011 ms 12.581 ms -2.7% no signal
200 x 8 VARCHAR(8000) / full-width CP1252 49.696 ms 49.994 ms +0.6% no signal
5,000 x 8 VARCHAR(8000) / short UTF-8 (astral) 16.319 ms 15.728 ms -3.6% no signal
200 x 8 VARCHAR(8000) / full-width UTF-8 (astral) 52.241 ms 52.272 ms -0.0% no signal
5,000 x 8 NVARCHAR(4000) / short UTF-16 (astral) 14.658 ms 14.006 ms -4.7% no signal
200 x 8 NVARCHAR(4000) / full-width UTF-16 (astral) 74.381 ms 76.325 ms +3.1% no signal
200,000 x 8 VARCHAR(32) / fetchall control 516.802 ms 533.992 ms +2.6% no signal
200,000 x 8 INT / fetchall control 283.800 ms 275.409 ms -0.5% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 31.180 ms 30.914 ms -1.2% no signal
Build and measurement details

ADO build 196299

PR head: 1e2aaf74dce49a758c086fa18bdb10f1086e38d3
Base: 3a2f221153fa16ad128a0d5dfda7a12de64aff68
Measured merge: 15ba8429932b0f77e2cd1ba9358cd647c3ea020c

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

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

The native JSON TVP path requires maintainer confirmation because its reported binding and recovery results cannot be independently validated without the unbundled preview ODBC provider and a live SQL Server.

No open issues 🎉

What changed in this PR

Adds native JSON columns to the existing synchronous TableValuedParameter API, using explicit Json snapshots and native ODBC binding without a text fallback. Successful execution requires a JSON-TVP-capable provider; the bundled released provider is not yet supported.

Changes:

  • Accepts SQL_JSON columns with Json or None cells and validates size/scale restrictions.
  • Unwraps JSON snapshots in copied binding rows and preserves unsupported-provider diagnostics.
  • Adds contract, streaming, recovery, result-handling, and typing coverage, plus usage documentation.
File Description
tests/​test_typing.py Adds consumer typing coverage for JSON TVP cells.
tests/​test_028_table_valued_parameters.py Tests JSON contracts, streaming, results, recovery, and unsupported-provider rejection.
README.md Documents JSON TVP usage, restrictions, and provider requirements.
mssql_python/​table_valued_parameter.py Accepts JSON columns and validates their metadata and cell types.
mssql_python/​pybind/​tvp.hpp Unwraps JSON snapshots for binding and handles JSON-specific binding errors.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 2, 2026 01:29

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 JSON TVP depends on an unshipped preview ODBC provider that could not be independently runtime-validated, with macOS and ARM64 qualification unverified, requiring human provider/protocol review.

No open issues 🎉

Review effort: Balanced

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

📊 Code Coverage Report

🔥 Diff Coverage

80%


🎯 Overall Coverage

87%


📈 Total Lines Covered: 15169 out of 17392
📁 Project: mssql-python


Diff Coverage

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

  • mssql_python/pybind/tvp.hpp (71.4%): Missing lines 64-65
  • mssql_python/table_valued_parameter.py (100%)

Summary

  • Total: 10 lines
  • Missing: 2 lines
  • Coverage: 80%

mssql_python/pybind/tvp.hpp

Lines 60-69

  60                 row[i] = row[i].attr("bytes_le");
  61             }
  62             if (declared.paramSQLType == SQL_SS_JSON) {
  63                 // Unwrap only the copied binding row, never the caller's snapshot.
! 64                 row[i] = row[i].attr("_text");
! 65             }
  66             // ApplyInputSizeOverride preserves decimal coefficients (no float or
  67             // decimal-context arithmetic) and fractional time via isoformat.
  68             ParamInfo converted;
  69             ApplyInputSizeOverride(row.ptr(), sizes[i].ptr(), i, converted, "utf-8");


📋 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: 75.4%
mssql_python._native_fetch.py: 80.1%
mssql_python.pybind.row_mapping_cache.hpp: 81.5%
mssql_python.pybind.connection.connection_pool.cpp: 82.5%
mssql_python.pybind.ddbc_bindings.cpp: 83.9%
mssql_python.pybind.connection.connection.cpp: 84.9%
mssql_python.logging.py: 86.8%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: medium Moderate update size

2 participants