Skip to content

[Phase 2] Enable MSSQL JSON data type - type mapping & error codes (engine)#3691

Draft
souvikghosh04 wants to merge 1 commit into
mainfrom
Usr/sogh/mssql-json-phase2
Draft

[Phase 2] Enable MSSQL JSON data type - type mapping & error codes (engine)#3691
souvikghosh04 wants to merge 1 commit into
mainfrom
Usr/sogh/mssql-json-phase2

Conversation

@souvikghosh04

@souvikghosh04 souvikghosh04 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Phase 2 — MSSQL JSON engine enablement

Part of the phased delivery for MSSQL JSON data type support (issue #2768).

Phase Scope Status
Phase 1 .NET 10 + Microsoft.Data.SqlClient 6.x upgrade (#3656) ✅ Merged
Phase 2 JSON engine enablement (this PR) 🚧 Draft
Phase 3 DB fixture + CRUD integration tests (REST / GraphQL / MCP) Pending
Phase 4 Error handling, filter/orderby pass-through, edge cases & regression Pending

What this delivers

Treats a SQL Server 2025+ JSON column exactly like a string column (per the 2026-06-09 design). This PR is the engine-only change, validated entirely by unit tests (no database dependency).

Production change (2 lines):

  • TypeHelper._sqlDbTypeToType[SqlDbType.Json] = typeof(string) — JSON columns flow through every existing string read/write path. (T004)
  • MsSqlDbExceptionParser.BadRequestExceptionCodes += 13608–13614 — SQL Server JSON-validation errors surface as HTTP 400 instead of 500. (T006)

Supporting changes:

  • SqlTypeConstants: register json as a supported SqlDbType literal. (T004)
  • Unit tests: jsonstring type mapping, and JSON error codes → 400. (T005 / T007)

The 13608–13614 error-code range is the starting set; it is pruned to the numbers SQL Server actually raises in Phase 4 (via the malformed-write / rejected-filter integration tests).

Why the DB fixture is NOT in this PR

The profiles test table (T002) and the Profile config entity (T003) are deferred to Phase 3. The native json column type requires SQL Server 2025+ / Azure SQL, and the CI test job initializes DatabaseSchema-MsSql.sql against LocalDB (SQL 2022 max), which does not know the json type — CREATE TABLE profiles (metadata json ...) fails schema init for the entire MsSql suite. Since no Phase 2 test consumes that table, the fixture ships with the Phase 3 integration tests behind server-version gating (see T031). This keeps Phase 2 green on the existing CI engine.

Requirements covered

FR-004, FR-007, FR-014 (schema-surface FR-001 is exercised by the Phase 3 integration tests).

Non-goals / out of scope

  • No changes to PostgreSQL, MySQL, DwSql, or CosmosDB (FR-012).
  • No new GraphQL scalar, no OData operator allow-list, no MCP annotation (superseded 2026-06-09).
  • DB fixture + integration tests (REST/GraphQL/MCP) land in Phase 3; error/filter/edge coverage in Phase 4.

Testing

  • dotnet build src/Service.Tests/Azure.DataApiBuilder.Service.Tests.csproj — succeeds, 0 warnings.
  • New unit tests pass: JsonSqlDbTypeResolvesToString, TestJsonValidationErrorsMapToBadRequest (8 cases).
  • No database-backed tests in this PR; full TestCategory=MsSql integration run arrives with Phase 3 (requires SQL Server 2025+).

Draft rationale

Opened as draft — the feature is not functionally verifiable end-to-end until the Phase 3 integration tests run against a SQL Server 2025+ environment, and the error-code list is finalized in Phase 4.

@souvikghosh04 souvikghosh04 force-pushed the Usr/sogh/mssql-json-phase2 branch from 4edabac to 6bed2da Compare July 1, 2026 13:54
…s (Phase 2)

Treat SQL Server 2025+ JSON columns exactly like string columns (2026-06-09 design, issue #2768). Engine-only change validated by unit tests.

- TypeHelper._sqlDbTypeToType[SqlDbType.Json] = typeof(string) (T004)

- SqlTypeConstants: register json as supported literal (T004)

- MsSqlDbExceptionParser BadRequestExceptionCodes += 13608-13614 so SQL JSON errors map to HTTP 400 (T006)

- unit tests for json type mapping and 400 error mapping (T005/T007)

The profiles DB fixture (T002) and Profile config entity (T003) are DEFERRED to Phase 3: the native json type requires SQL Server 2025+/Azure SQL and cannot be created on the LocalDB engine used by CI. They ship with the Phase 3 integration tests behind server-version gating.

No changes to PostgreSQL/MySQL/DwSql/CosmosDB (FR-012).
@souvikghosh04 souvikghosh04 force-pushed the Usr/sogh/mssql-json-phase2 branch from 6bed2da to 9e5a38d Compare July 1, 2026 14:07
@souvikghosh04 souvikghosh04 changed the title [Phase 2] Enable MSSQL JSON data type - type mapping, error codes & fixtures [Phase 2] Enable MSSQL JSON data type - type mapping & error codes (engine) Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant