Skip to content

feat(gateway): preserve Spark Connect query types in JSON results - #20761

Open
cshuo wants to merge 1 commit into
apache:masterfrom
cshuo:codex/20606-spark-connect-json
Open

cshuo wants to merge 1 commit into
apache:masterfrom
cshuo:codex/20606-spark-connect-json

Conversation

@cshuo

@cshuo cshuo commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Describe the issue this Pull Request addresses

Closes #20606.

With the Spark Connect backend, query_lakehouse loses information when converting collected rows to JSON. Structs lose their field names, TIMESTAMP and TIMESTAMP_NTZ both appear without a UTC offset, and clients cannot distinguish a decimal value such as "1.10" from a string with the same text.

Summary and Changelog

feat(gateway): preserve Spark Connect query types in JSON results (b16f437d901)

  • Encode Arrow values using the schema returned by the same Spark execution. Include column_types in column order, even for empty results, and apply the existing response byte limit to both rows and type metadata.
  • Return named structs as JSON objects, including inside arrays. When field names repeat, return values in field order so both values survive.
  • Preserve decimal precision and scale with exact strings. Encode TIMESTAMP as ISO-8601 in UTC with +00:00 and TIMESTAMP_NTZ as local date and time without an offset.
  • Encode binary values as base64. Maps with string or integer keys use JSON objects, matching Trino for integer keys. Other map keys use [key, value] pairs so clients can read structured keys.

Impact

The response format changes for Spark Connect clients, including MCP clients. For example, a struct previously returned as ["Beijing", "South Station"] now appears as {"city":"Beijing","station":"South Station"}. Clients that accessed named struct fields by position should use field names.

Risk Level

Medium. Existing clients may depend on positional struct values or the previous timestamp format. All 797 gateway offline tests passed. On Spark Connect 4.1.3, five live tests passed, including checks for timestamps across a daylight-saving transition and distinct BIGINT map keys above JavaScript’s safe integer range. Four tests were skipped because their environment prerequisites were unavailable.

Documentation Update

The gateway README documents column_types, decimal and timestamp encodings, and the JSON differences between Spark Connect and Trino for structs, binary values, and maps.

Contributor's checklist

  • Read through the contributor's guide
  • Enough context is provided in the sections above
  • Adequate tests were added if applicable

@github-actions github-actions Bot added the size:L PR with lines of changes in (300, 1000] label Nov 19, 2026
Encode Arrow values with the Spark execution schema so nested field names, decimal precision and timestamp semantics survive JSON serialization. Include column types in the bounded response and document differences from Trino.
@cshuo
cshuo force-pushed the codex/20606-spark-connect-json branch from b16f437 to 9ca0dff Compare November 19, 2026 12:42
@cshuo
cshuo marked this pull request as ready for review November 19, 2026 12:55
@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.88%. Comparing base (f383424) to head (9ca0dff).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #20761   +/-   ##
=========================================
  Coverage     80.87%   80.88%           
- Complexity    36135    36144    +9     
=========================================
  Files          2590     2590           
  Lines        147760   147760           
  Branches      18256    18256           
=========================================
+ Hits         119500   119511   +11     
+ Misses        19985    19971   -14     
- Partials       8275     8278    +3     
Components Coverage Δ
hudi-common 84.14% <ø> (-0.01%) ⬇️
hudi-client 84.09% <ø> (+0.01%) ⬆️
hudi-flink 86.28% <ø> (ø)
hudi-spark-datasource 74.43% <ø> (ø)
hudi-utilities 79.29% <ø> (+0.03%) ⬆️
hudi-cli 70.92% <ø> (ø)
hudi-hadoop 71.16% <ø> (-0.02%) ⬇️
hudi-sync 77.35% <ø> (+0.06%) ⬆️
hudi-io 81.66% <ø> (+0.09%) ⬆️
hudi-timeline-service 83.41% <ø> (-0.09%) ⬇️
hudi-cloud 81.01% <ø> (ø)
hudi-kafka-connect 57.90% <ø> (ø)
Flag Coverage Δ
common-and-other-modules 44.65% <ø> (+<0.01%) ⬆️
flink-integration-tests 41.44% <ø> (+<0.01%) ⬆️
hadoop-mr-java-client 43.95% <ø> (-0.03%) ⬇️
integration-tests 14.71% <ø> (ø)
spark-client-hadoop-common 37.64% <ø> (ø)
spark-java-tests 51.64% <ø> (+0.01%) ⬆️
spark-scala-tests 54.02% <ø> (+<0.01%) ⬆️
utilities 42.34% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cshuo
cshuo requested a review from nsivabalan November 20, 2026 01:54

This branch has not been deployed

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

Labels

size:L PR with lines of changes in (300, 1000]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Spark Connect] Preserve timestamps, structs and decimals in gateway JSON results

2 participants