Repository navigation
fix: align Document values() with keys() — use toMap(false) to exclude metadata fields - #6500
Conversation
…e metadata fields SQLMethodValues used document.toMap().values() which returns @Rid, @type, and @cat metadata fields alongside declared properties, while keys() only returns declared property names (getPropertyNames()). This caused keys()/values() to produce different-sized lists that were not index-aligned. Fixed by using document.toMap(false) which excludes metadata fields, matching the property set returned by getPropertyNames(). Fixes ArcadeData#6472
…fields Update withDocument() and withCollectionOfDocuments() tests to assert only declared property values (no @rid/@type/@cat), aligning with the new values() behavior that uses toMap(false).
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
…mes() PR ArcadeData#6500's own fix (toMap(false) instead of toMap()) only equalizes the SIZE of keys()/values() for a Document, not their ordering: toMap(false) copied the properties into a plain HashMap, whose iteration order (hash bucket order) can differ from getPropertyNames()'s insertion order (the properties LinkedHashMap's keySet()). For a document with 3+ properties this leaves doc.keys()[i] and doc.values()[i] still misaligned - the exact defect issue ArcadeData#6472 set out to fix - just harder to notice because it depends on the specific property names/hash codes involved. Switch MutableDocument.toMap(boolean) to build a LinkedHashMap instead, so its iteration order always matches the properties map it copies from (and getPropertyNames(), which is that same map's keySet()). This also brings MutableDocument in line with ImmutableDocument.toMap(), which already returns a LinkedHashMap sourced from the same ordered binary property scan as its own getPropertyNames(). MutableVertex/MutableEdge inherit the fix since both extend MutableDocument. Adds regression coverage: a direct toMap()/getPropertyNames() ordering check in DocumentTest, and index-alignment checks for keys()/values() in SQLMethodValuesTest covering both an in-memory document and one reloaded from storage via SQL (the exact scenario from issue ArcadeData#6472).
|
@claude review this |
|
Claude finished @lvca's task in 2m 39s —— View job Review
The core fix is sound: One real gap:
public synchronized Map<String, Object> toMap(final boolean includeMetadata) {
final Map<String, Object> result = new HashMap<>(map);
...while its Minor observations (non-blocking):
Verification note: I wasn't able to run |
…rder Follow-up to PR ArcadeData#6500 (issue ArcadeData#6472): that PR fixed the keys()/values() index-misalignment for MutableDocument by switching its toMap(boolean) from a plain HashMap to a LinkedHashMap, but DetachedDocument.toMap(boolean) had the exact same bug and was left unfixed - it also copied into a plain HashMap while its getPropertyNames() returns the same LinkedHashMap-backed map's keySet(). Document.detach() is a common pattern for handing documents outside a transaction, so keys()/values() on a detached document could still disagree by index. Switch DetachedDocument.toMap(boolean) to LinkedHashMap as well, matching MutableDocument and ImmutableDocument. Confirmed the added regression tests fail against the pre-fix code (order came back scrambled, e.g. [name, country, city, age, email] instead of insertion order) and pass with the fix.
Problem
SQLMethodValueshandles theDocumentbranch asymmetrically compared toSQLMethodKeys:keys()→document.getPropertyNames()— declared properties onlyvalues()→document.toMap().values()— declared properties plus internal metadata@rid,@type,@cat(becausetoMap()defaults totoMap(true))For the same document,
doc.keys().size() != doc.values().size()and the two lists are not index-aligned.Fix
values()now usesdocument.toMap(false)which excludes the metadata fields, matching the property set returned bygetPropertyNames(). This is the direction suggested in the issue as "more consistent with user expectations of keys()/values() as a matched pair".The
Resultbranch already operates on a map without metadata fields, so it was left unchanged.Tests
Updated
SQLMethodValuesTest:withDocument(): now asserts only the 2 declared property values (Alice,30) instead of 5 (declared + metadata)withCollectionOfDocuments(): now asserts 4 flat values (2 per document) instead of 10Verification
After the fix, for any Document:
keys().size() == values().size()Fixes #6472