[Phase 2] Enable MSSQL JSON data type - type mapping & error codes (engine) - #3691
Merged
Conversation
souvikghosh04
force-pushed
the
Usr/sogh/mssql-json-phase2
branch
from
July 1, 2026 13:54
4edabac to
6bed2da
Compare
…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
force-pushed
the
Usr/sogh/mssql-json-phase2
branch
from
July 1, 2026 14:07
6bed2da to
9e5a38d
Compare
souvikghosh04
marked this pull request as ready for review
July 2, 2026 09:43
souvikghosh04
requested review from
Alekhya-Polavarapu,
Aniruddh25,
JerryNixon,
RubenCerna2079,
aaronburtle,
anushakolan,
rusamant,
sourabh1007,
stuartpa and
vadeveka
as code owners
July 2, 2026 09:43
Contributor
There was a problem hiding this comment.
Pull request overview
Adds SQL Server 2025 JSON column support by treating JSON exactly like a string in DAB’s type system, and improves error handling so SQL JSON validation failures map to a client error instead of a generic server error.
Changes:
- Map
SqlDbType.Json(and the"json"type literal) to CLRstringso existing string read/write/filter/sort paths apply. - Map SQL Server JSON validation error codes (13608–13614) to HTTP 400 (Bad Request) in the MSSQL exception parser.
- Add/extend tests validating the new type mapping and HTTP status mapping.
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 |
|---|---|
| src/Core/Services/TypeHelper.cs | Adds SqlDbType.Json -> string mapping so JSON behaves like a string in CLR/type resolution. |
| src/Core/Models/SqlTypeConstants.cs | Marks "json" as a supported SQL type literal for metadata/type-resolution test coverage. |
| src/Core/Resolvers/MsSqlDbExceptionParser.cs | Adds JSON validation error codes to the “bad request” classification. |
| src/Service.Tests/OpenApiDocumentor/CLRtoJsonValueTypeUnitTests.cs | Adds a targeted test asserting "json" resolves to string and maps to JsonDataType.String. |
| src/Service.Tests/UnitTests/DbExceptionParserUnitTests.cs | Adds a data-driven test asserting JSON validation errors map to HTTP 400. |
RubenCerna2079
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me, but the tests will need to be changed as the pipeline should be able to support the JSON data type with this PR. #3697
RubenCerna2079
approved these changes
Jul 9, 2026
RubenCerna2079
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Just address the comments made by copilot.
anushakolan
approved these changes
Jul 14, 2026
souvikghosh04
enabled auto-merge (squash)
July 14, 2026 12:13
souvikghosh04
added a commit
that referenced
this pull request
Jul 28, 2026
## What this PR does Adds the database test fixture and REST integration tests for SQL Server 2025 `JSON` columns. It builds on Phase 2 (which taught the engine to treat `JSON` as a normal `string`) and proves the behavior end-to-end through the REST API. This follows the exact pattern of the recently merged **vector data type** feature (#3677), and is unblocked by CI now running SQL Server 2025 (#3697). ## What's included - **Test table** — a `profiles` table with an `id` and a `metadata json` column, plus 5 seed rows covering a simple object, an array, a deeply nested object, unicode + emoji, and `NULL`. - **Entity** — a `Profile` entity (REST + GraphQL enabled) in the MsSql test config and config generator. - **REST tests** — `MsSqlRestJsonTypesTests`: read (list, by id, null, array, nested, unicode), insert, update (PUT/PATCH), clear-to-null, and delete. Because DAB treats `JSON` as a string, the tests parse `metadata` and compare it **semantically**, so they're robust to any whitespace / key-order normalization the engine applies. ## No gating needed Unlike the earlier plan, the table is created **unconditionally** (no server-version guard) — CI runs SQL Server 2025 and the schema already uses the 2025-only `vector` type the same way. ## Delivery plan | Phase | What | Status | |------|------|--------| | 1 | .NET 10 + SqlClient 6.x (prerequisite) | ✅ Merged (#3697/#3656) | | 2 | JSON type + error mapping (engine) | ✅ Merged (#3691) | | **3** | **Test fixture + REST CRUD tests (this PR)** | 🚧 In review | | 3b | GraphQL / OpenAPI / MCP schema-discovery tests | Next | | 4 | Error/filter edge cases + regression | After | ## Notes - Requires SQL Server 2025 / Azure SQL (native `json` type). - No changes to PostgreSQL, MySQL, DwSql, or CosmosDB. - Related issue: #2768. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jul 28, 2026
souvikghosh04
added a commit
that referenced
this pull request
Jul 30, 2026
…QL tests (#3738) ## Why Part of MSSQL native `JSON` support (#2768). Started as Phase 3b **schema-discovery tests**, but review (thanks @aaronburtle) surfaced a real product inconsistency that this PR now also fixes. **The problem:** #2768 requires a `JSON` column to be treated as a normal `string` for **input and output**. But the MSSQL read path (`FOR JSON PATH`) was *inlining* a native `json` column as a nested JSON **object**. Consequences: - REST returned `"metadata": {"role":"admin"}` (object) instead of `"metadata": "{\"role\":\"admin\"}"` (string). - A GraphQL read of the `String`-typed field threw a `GraphQLMapping` error — the `String` leaf resolver calls `JsonElement.GetString()`, which fails on an object. So schema introspection could pass while `profile_by_pk(id:1){ metadata }` failed at runtime. - OpenAPI/GraphQL advertised `string`, contradicting the object runtime — generated clients would mis-model the field. ## What **Engine fix** (`MsSqlQueryBuilder`): the read path now casts a native `json` column (`SqlDbType.Json`) to `NVARCHAR(MAX)` in `WrappedColumns`, so `FOR JSON PATH` emits it as an escaped JSON **string** rather than inlining it as an object. This is the single choke point for REST **and** GraphQL reads. Regular `nvarchar` columns are untouched. Mutations already return `json` as a string via the tabular `OUTPUT` clause, so no change was needed there. **Tests:** | Layer | Test | Asserts | |------|------|---------| | OpenAPI | `JsonTypeSchemaTests` | `metadata` is `type: string` with no `format` in the **response** and both **request-body** schemas (`Profile_NoAutoPK` for POST, `Profile_NoPK` for PUT/PATCH) | | GraphQL introspection | `MsSqlGraphQLJsonSchemaTests` | `Profile.metadata` is the built-in `String` scalar (no custom JSON scalar) | | GraphQL read (new) | `MsSqlGraphQLJsonSchemaTests` | `profile_by_pk(id:1){ metadata }` returns the payload as a JSON **string** — guards against introspection passing while a real read throws | | REST | `MsSqlRestJsonTypesTests` (updated) | flipped back to the string contract: `metadata` is returned as a JSON **string** (`ParseMetadata`/`GetJsonTypeList` assert `JsonValueKind.String`) | > Note: DAB's OpenAPI documentor does not emit `Nullable` on the property schema for **any** column type, so the schema tests assert `type: string` + no `format` (not nullability). ## Intentionally omitted - **MCP `describe_entities` (T010)**: it projects only the config field `name`/`description`, not DB column data types, so there is no JSON-specific behavior to assert. ## Notes - **This PR now includes a product (engine) change**, not tests only. - Requires SQL Server 2025 / Azure SQL (native `json`); CI already runs SQL 2025. - Cannot be run locally (no SQL 2025 here) — relying on CI. ## Delivery plan | Phase | What | Status | |-------|------|--------| | 1 | .NET 10 + SqlClient 6.x | ✅ Merged (#3697/#3656) | | 2 | JSON type + error mapping (engine) | ✅ Merged (#3691) | | 3 | Test fixture + REST CRUD tests | ✅ Merged (#3720) | | **3b** | **json-as-string read fix + OpenAPI/GraphQL discovery & read tests (this PR)** | 🚧 | | 4 | Error/filter edge cases + regression + polish | Next |
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.
What this PR does
Adds support for the SQL Server 2025
JSONcolumn type by treating it exactly like a normal text (string) column. Reading, writing, filtering, and sorting all reuse the paths DAB already has for strings — no new type, no special handling.The change
Two small edits to the engine:
JSONcolumn is astring.Both are covered by new unit tests.
This PR is intentionally scoped to just the engine change. The database test table and end-to-end (REST/GraphQL) tests are not included here because they need a real SQL Server 2025 database — and our CI currently runs on LocalDB, which doesn't understand the
JSONtype yet. Those tests come in the next phase.Delivery plan
Notes
JSONdata type for MSSQL #2768.