You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "alekjarmov (via GitHub)" <gi...@apache.org> on 2026/10/15 09:50:25 UTC
[PR] [SQL] Map SQL Server native JSON JDBC type to StringType [spark]
alekjarmov opened a new pull request, #59503:
URL: https://github.com/apache/spark/pull/59503
### What changes were proposed in this pull request?
Map SQL Server's native JSON JDBC type (`microsoft.sql.Types.JSON`, vendor type code `-159`) to Spark `StringType` in `MsSqlServerDialect`.
SQL Server native `json` values are exposed to JDBC applications as text. Depending on the Microsoft JDBC driver, a native `json` column may be reported either through the standard NVARCHAR / string-compatible path or as this vendor-specific type. Spark's generic JDBC mapping does not know `-159`, so schema inference fails with `UNRECOGNIZED_SQL_TYPE`. This change recognizes `-159` in the SQL Server dialect and maps it to `StringType`.
This does not parse JSON or introduce a Spark JSON data type. The payload remains a string, matching the driver's `getString` behavior.
### Why are the changes needed?
Native `json` columns should have the same logical Spark type with both older and newer SQL Server JDBC drivers. Without this mapping, schema inference fails for `-159`, and affected tables can be unreadable (in some catalog paths they appear to have no columns). A common workaround is to expose the column through a view that casts it to `NVARCHAR(MAX)`, which restores standard string metadata. Handling `-159` in the dialect keeps the string representation without that workaround.
### Does this PR introduce _any_ user-facing change?
Yes. SQL Server native `json` columns whose JDBC metadata reports type `-159` are inferred as `StringType` instead of failing with `UNRECOGNIZED_SQL_TYPE`. Columns already reported as NVARCHAR continue to map as they do today.
### How was this patch tested?
Added a `JDBCSuite` unit test that maps `-159` / `"json"` to `StringType` and checks that `java.sql.Types.OTHER` with type name `"json"` is left unmapped.
Local `sbt` could not be run in this environment because the sbt 1.13.0 launcher could not be downloaded.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor Grok 4.6
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-60258][SQL] Map SQL Server native JSON JDBC type to StringType [spark]
Posted by "alekjarmov (via GitHub)" <gi...@apache.org>.
alekjarmov commented on code in PR #59503:
URL: https://github.com/apache/spark/pull/59503#discussion_r4285702821
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MsSqlServerDialect.scala:
##########
@@ -166,6 +166,7 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
case java.sql.Types.REAL if !SQLConf.get.legacyMsSqlServerNumericMappingEnabled =>
Some(FloatType)
case GEOMETRY | GEOGRAPHY => Some(BinaryType)
+ case JSON => Some(StringType)
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-60258][SQL] Map SQL Server native JSON JDBC type to StringType [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #59503:
URL: https://github.com/apache/spark/pull/59503#discussion_r4284910039
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MsSqlServerDialect.scala:
##########
@@ -166,6 +166,7 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
case java.sql.Types.REAL if !SQLConf.get.legacyMsSqlServerNumericMappingEnabled =>
Some(FloatType)
case GEOMETRY | GEOGRAPHY => Some(BinaryType)
+ case JSON => Some(StringType)
Review Comment:
**Nit (P3):** Could you add a `json` -> `StringType` row to the "Mapping Spark SQL Data Types from Microsoft SQL Server" table in `docs/sql-data-sources-jdbc.md`? Every other special case in this `getCatalystType` (datetimeoffset, tinyint/smallint, real, geography/geometry) has a row there. Without one, json would be the only special-cased SQL Server read mapping with no doc row, and the docs would not tell users that native json columns are now readable or that they come back as unparsed strings. It's a single row, which could go right after `geometry`.
**Verification:**
- **Inspection:** The Microsoft SQL Server to Spark SQL read-mapping table contains exactly one json entry mapped to StringType, and its row structure (three cells per row) matches the neighboring rows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-60258][SQL] Map SQL Server native JSON JDBC type to StringType [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #59503: [SPARK-60258][SQL] Map SQL Server native JSON JDBC type to StringType
URL: https://github.com/apache/spark/pull/59503
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-60258][SQL] Map SQL Server native JSON JDBC type to StringType [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #59503:
URL: https://github.com/apache/spark/pull/59503#issuecomment-6227770696
**Merge Summary:**
- merged into master https://github.com/apache/spark/commit/6941ceef6e6b151a8e6e44576648605eef5a215b
- merged into branch-4.x https://github.com/apache/spark/commit/d7d280b24bdb9b67ea3408c5e206ac9fa576932d
*Posted by `merge_spark_pr.py`*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org