Repository navigation
fix(neo4j): a junction without criteria adds nothing, and an empty block keeps its match in an or - #17011
fix(neo4j): a junction without criteria adds nothing, and an empty block keeps its match in an or#17011borinquenkid wants to merge 6 commits into
Conversation
…ock keeps its match in an or
An empty and { } or or { } left a dangling AND or OR in the Cypher, which Neo4j
rejected. Blank expressions are dropped from a junction. A block without
criteria inside an or no longer becomes an existence branch: it keeps the match,
so it still asks for an associated entity, as on the datastores that join.
Fixes #14635
Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An empty junction inside an association block still changes the match. A negated empty association block now fails to parse.
| return dispatchCriterion(criterion.criteria, scope.forEnd(association)) | ||
| } | ||
| if (scope.builder.inDisjunction) { | ||
| if (scope.builder.inDisjunction && !criterion.criteria.getCriteria().isEmpty()) { |
There was a problem hiding this comment.
Other has no parent. or { parent { and {} }; eq('name', 'Other') } should match nothing, the same as parent {}. It returns Root and Other, because the empty and is treated as a branch. not { parent {} } used to find folders without a parent and now fails to parse. An empty junction adds nothing. A negated empty association still asks for the neighbour.
A junction without criteria produced no Cypher, so the callers dropped it: or {} found no restriction, not { and {} } found every node, and an empty not {} was accepted. Hibernate 5, the reference, treats an empty junction as true: it is neutral in an and, makes the or it stands in true and makes a negation false; an empty not {} is an error. The Cypher builder now answers a junction with no criteria with true and rejects an empty negation. A block without criteria still keeps the match and adds no condition, so it is no branch of the or it stands in.
Adds the shared table CriteriaEmptyJunctionSpec (52 shapes, Hibernate 5's results as the expected values); Neo4j skips a negated association block (it asks whether a neighbour exists) and the two detached inList rows (its inList reads only the listed values and ignores a subquery).
Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
An empty junction is now true wherever it stands in Neo4j, as it is on Hibernate 5, the reference: it adds no restriction beside a property, makes the
The same table file is added by #17010 (8.0.x) and #17009 (7.0.x); the copies differ only in each branch's skip lists, so the merge-up keeps one copy and removes each store's skips as its fix lands. |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An empty junction inside an or keeps its match. A negated empty association still fails to parse, and a negated association that holds an empty junction returns the wrong rows.
| return dispatchCriterion(criterion.criteria, scope.forEnd(association)) | ||
| } | ||
| if (scope.builder.inDisjunction) { | ||
| if (scope.builder.inDisjunction && !criterion.criteria.getCriteria().isEmpty()) { |
There was a problem hiding this comment.
not { parent {} } used to find folders without a parent. It now fails to parse, because the association adds a match and then an empty expression, and the negation wraps that as NOT (). not { child { or {} } } returns the orphan instead of nothing. An empty junction is true. A negated empty association still asks for the neighbour, and the query has to parse.
…ls it, and a negation with nothing to negate is refused
not { parent {} } failed to parse: the block adds a match and an empty expression, which the negation wrapped as NOT (). A
negation with nothing left to negate now throws the same IllegalArgumentException an empty not {} does, as Hibernate 5 does.
not { child { or {} } } returned the node without a child, because the block was an existence check under a NOT. A block
with criteria is a join on Hibernate 5, so its negation is a neighbour that fails the criteria and a node without a
neighbour is not in it. The negation is now the conjunction of the negations of its criteria, with such a block as an
existence check of a neighbour that fails its criteria.
CriteriaEmptyJunctionSpec gains three rows (not of a block with an and, with nothing, with a property) and Neo4j no longer
skips not { child { or {} } }. H5, H7 with the fix of #17010 and Neo4j agree on all of them.
Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
Thank you. Two of the three are bugs and are fixed; the first I could not confirm as a bug, and I would like to check my reading with you.
Three rows are new (a negated block with an |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A negated empty association is refused instead of failing to parse, and a negated association that holds an empty junction returns nothing. A junction that holds only an empty association still drops the other branch.
| try { | ||
| def inner = ((Query.Junction) criterion).criteria | ||
| .collect { Query.Criterion it -> dispatchCriterion(it, scope).toString() } | ||
| .findAll { String expression -> expression } |
There was a problem hiding this comment.
or { or { child {} }; eq('name', 'orphan') } should return the orphan, because the inner junction is true. It returns nothing. The empty association is filtered out, and the junction then adds nothing, so the required child match removes the name branch. An empty junction is true. Keep that when its children add no expression.
… junction without children is
or { or { child {} }; eq('name', 'orphan') } returned nothing: the inner junction holds only an empty
association block, which adds no expression, so the junction added nothing and was dropped from the
outer or. A junction whose children add no expression is true wherever it stands, as an empty one is.
Hibernate 5, the reference, returns the nodes that have a neighbour for this shape, and so does
Neo4j now. A negation of such a junction still has nothing to negate and is refused, as on
Hibernate 5.
Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
@jamesfredley One of the three is fixed in the new commit. The other two already behave as you describe, and I checked each against Hibernate 5 first, as the reference. Fixed: If you expect the orphan from this shape, that is a difference from Hibernate 5 and not from Neo4j, and it would need a separate change for all three stores. Say so and I will open it. Already as you describe:
A negation of a junction that adds no expression still has nothing to negate and is refused, so Branch policy: the other new throws in this PR were already in it. This commit adds none. Where the PR belongs is still open; I have not moved it. If you find another shape that does not reproduce first time, a failing spec on a throwaway branch, or the few lines you ran, would help me a lot. |
Stacked on #16836 (base is its branch; merge that one first).
and { }oror { }left a dangling AND or OR in the Cypher, which Neo4j rejected. Blank expressions are now dropped from a junction. A block without criteria inside anorno longer becomes an existence branch: it keeps the match, so it still asks for an associated node, as on the datastores that join.EmptyJunctionSpecruns against a real Neo4j container. With the fix reverted, 3 of its 4 cases fail; the fourth (an empty association block in anor) pins behavior that was already right.Full Neo4j core suite on this branch: 934 tests, 0 failures, 0 errors;
codeStyleclean.Fixes #14635 once Hibernate 7 and the in-memory/Hibernate 5 parts (#17010, #17009) are in; refs #14573 and #14617.
https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL