Skip to content

fix: Serialize MAP columns as {key: value} in REST JSON (#89)#91

Merged
jrosskopf merged 1 commit into
mainfrom
fix/gh-89-map-serialization
Jun 26, 2026
Merged

fix: Serialize MAP columns as {key: value} in REST JSON (#89)#91
jrosskopf merged 1 commit into
mainfrom
fix/gh-89-map-serialization

Conversation

@jrosskopf

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #90. After v26.06.25 shipped the LIST/STRUCT/ARRAY/UNION fix, the reporter found that a native MAP column still serializes incorrectly (null / wrong type) — e.g. map_from_entries(...)"reasons": null.

A DuckDB MAP is physically LIST(STRUCT(key, value)), but it was aliased onto the struct serializer, so it never round-tripped.

Fix

  • convertVectorMapToJson — slice the row's duckdb_list_entry, read key/value from the list child's struct, and emit a JSON object {key: value} matching DuckDB's own to_json. Empty map → {}, NULL map → null.
  • vectorEntryToMapKey — raw string for VARCHAR keys (escape-safe), JSON rendering for scalar keys (e.g. 10"10").
  • Fixed a pre-existing logical-type leak in convertVectorDecimalToJson (now reachable via decimal map keys), surfaced by codex review.

Test plan

  • New MAP regression tests: string keys, integer keys, empty map ({}), NULL map (null).
  • Full C++ unit suite: 643/643 passing.
  • Reviewed with codex (decimal leak fixed; composite-key edge case documented as a known limitation).

Relates to #89

Follow-up to the LIST/STRUCT/ARRAY/UNION fix. MAP columns were aliased
onto the struct serializer, but a DuckDB MAP is physically
LIST(STRUCT(key, value)), so they did not round-trip (serialized to
null / wrong type) — reported on #89 after v26.06.25.

- Add convertVectorMapToJson: slice the row's duckdb_list_entry, read
  key/value from the list child struct, emit {key: value} matching
  DuckDB's to_json. Empty map -> {}, NULL map -> null.
- Add vectorEntryToMapKey: raw string for VARCHAR keys (escape-safe),
  JSON rendering for scalar keys (e.g. 10 -> "10").
- Fix a pre-existing logical-type leak in convertVectorDecimalToJson
  (now reachable via decimal map keys).
- Add MAP regression tests: string keys, integer keys, empty, and NULL.

Found via user follow-up + codex review.
@jrosskopf jrosskopf merged commit ac97de0 into main Jun 26, 2026
21 checks passed
@jrosskopf jrosskopf deleted the fix/gh-89-map-serialization branch June 26, 2026 21:10
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