Preserve null-valued keys in map literals (#2391)#2412
Open
crprashant wants to merge 1 commit intoapache:masterfrom
Open
Preserve null-valued keys in map literals (#2391)#2412crprashant wants to merge 1 commit intoapache:masterfrom
crprashant wants to merge 1 commit intoapache:masterfrom
Conversation
Map literals such as RETURN {a: null} previously dropped keys whose
values were null, producing {} instead of {"a": null}. This
diverged from the openCypher / Neo4j semantics where map literals
preserve every key the user wrote, including those bound to null.
Root cause: cypher_map.keep_null defaulted to false (zero-initialised),
so the grammar-produced node fed agtype_build_map_nonull, which strips
null entries. Call sites that legitimately need strip-null semantics
(CREATE node/edge property maps and SET = assignments) already set
keep_null=false explicitly, and the MATCH pattern path sets it to true
explicitly. Flipping the grammar default to true therefore only affects
the cases that were buggy (bare map expressions and nested map values),
and leaves CREATE/SET behaviour unchanged.
Two preexisting tests encoded the old buggy output and are updated:
expr.out (bare RETURN maps now keep the null value) and agtype.out
(a nested map inside an orderability test no longer drops its null
entry, shifting one row in the ORDER BY result). Dedicated regression
coverage for apache#2391 is added to regress/sql/expr.sql.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Author
|
Hi @jrgemignani , @MuhammadTahaNaveed could you pls review this.. |
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.
Summary
Fixes #2391.
Map literals such as
RETURN {a: null}previously dropped keys whose values were null, producing{}instead of{"a": null}. This diverged from the openCypher / Neo4j semantics where map literals preserve every key the user wrote, including those bound to null.Root cause
cypher_map.keep_nulldefaulted tofalse(zero-initialised), so the grammar-produced node fedagtype_build_map_nonull, which strips null entries. Call sites that legitimately need strip-null semantics (CREATE node/edge property maps and SET=assignments) already setkeep_null = falseexplicitly, and the MATCH pattern path sets it totrueexplicitly. Flipping the grammar default totruetherefore only affects the cases that were buggy (bare map expressions and nested map values), and leaves CREATE / SET behaviour unchanged.Changes
src/backend/parser/cypher_gram.y— themap:rule now setsn->keep_null = truewith an explanatory comment.regress/sql/expr.sql— dedicated regression coverage for Map literals may drop keys whose values arenull. #2391 (single-key null, multiple nulls,keys(),coalesce, nested map values, mixed null / non-null, empty map, CREATE control, MATCH verify).regress/expected/expr.out— two preexisting tests that encoded the old buggy output now show the preserved"z": null; plus expected output for the new Map literals may drop keys whose values arenull. #2391 block.regress/expected/agtype.out— nested{bool: true, i: null}inside an orderability test no longer drops its null entry, shifting one row in theORDER BYresult.Behaviour before / after
CREATE and SET
=still strip null-valued keys (unchanged), matching openCypher semantics for property writes.Test results
make installcheckagainst PostgreSQL 18: 32 / 33 pass. The only failure isage_upgrade, which is a preexisting failure unrelated to this change.