Repository navigation
Description
Summary
keys() and values() are an index-aligned pair: the n-th key names the n-th value. That rule was
stated and fixed once, for a Document receiver. A Result receiver - which is what a row of a
sub-query, a LET variable or any nested result set is - breaks it in two separate ways, both
because values() goes through ResultInternal.toMap():
- Metadata leaks into the values.
ResultInternal.toMap()answerselement.toMap()for a row
that wraps a record, andDocument.toMap()istoMap(true). So the record's@cat,@typeand
@rid- and, on an edge,@inand@out- come back as unlabelled data values. A two-property
document answers 2 keys and 5 values; an edge with one property answers 1 key and 6 values. - The values are the RECORD's, not the ROW's.
ResultInternal.toMap()is, by its own comment,
"deliberately element-first, which is the opposite precedence to
getProperty()/getPropertyNames()".keys()usesgetPropertyNames(). So on a row that
overrides a property of its element,keys()lists the row's names andvalues()returns the
element's values, and the pair reports a value the row does not have.
Where (HEAD ac84740)
engine/src/main/java/com/arcadedb/query/sql/method/collection/SQLMethodValues.java52-57:
line 55return new ArrayList<>(document.toMap(false).values());with the keys()/values() on a Document are not parallel arrays: values() includes internal fields (@rid/@type/@cat) that keys() omits #6472 comment at 53-54,
and line 57return result.toMap().values();engine/src/main/java/com/arcadedb/query/sql/method/collection/SQLMethodKeys.java50-55:
document.getPropertyNames()andresult.getPropertyNames().engine/src/main/java/com/arcadedb/query/sql/executor/ResultInternal.java582-601 (toMap(),
element-first by design) and 386 (getPropertyNames(), content-first).- The contract that makes
toMap()the metadata overload:
engine/src/main/java/com/arcadedb/database/Document.java149-154.
Repro
Embedded, built from this revision. D1 holds {n:1, s:'x'} at #1:0; V1/R1 hold one vertex
{n:1} and one edge {w:7}.
Control, a Document receiver - correct:
select @this.keys() as k, @this.values() as v from D1
-> {k: [n, s], v: [1, x]}
A Result receiver, same record:
select $a[0].keys() as k, $a[0].values() as v from D1 let $a = (select from D1)
-> {k: [n, s], v: [1, x, d, D1, #1:0]}
select $a[0].keys().size() as nk, $a[0].values().size() as nv from D1 let $a = (select from D1)
-> {nk: 2, nv: 5}
select $a[0].keys() as k, $a[0].values() as v from D1 let $a = (select from V1 where n=1)
-> {k: [n], v: [1, v, V1, #2:0]}
select $a[0].keys() as k, $a[0].values() as v from D1 let $a = (select from R1)
-> {k: [w], v: [7, e, R1, #5:0, #2:1, #2:0]}
The second half, on a row that overrides one of its element's properties:
select $a[0].s as s, $a[0].keys() as k, $a[0].values() as v
from D1 let $a = (select *, 'OVERRIDE' as s from D1)
-> {s: OVERRIDE, k: [n, s, @rid, @type], v: [1, x, d, D1, #1:0]}
$a[0].s is OVERRIDE; the s slot of values() is x.
A row with no element behind it is correct (let $a = (select n from D1) gives k: [n], v: [1]),
which is what confines this to element-backed rows.
Suggested fix
values() must read from the same place keys() reads from. The smallest correct change is to make
the Result branch walk result.getPropertyNames() and collect result.getProperty(name), which
fixes both halves at once: no metadata, and the row's own values with the row's own precedence.
Better, because it stops the pair drifting a third time: give the two methods one shared helper that
turns any receiver into the ordered name/value view both of them project, and have keys() return
its keys and values() its values. The Document branch was already aligned by hand once (#6472)
and the Result branch three lines below it was not; two methods in two files each dispatching over
four receiver types is how that happened.
Leave ResultInternal.toMap() alone. Its element-first precedence is deliberate and documented
(it is what JsonSerializer flattens a whole-entity projection through), so it is the wrong map for
this caller rather than a wrong map.
Scope / confidence
Reproduced through the SQL engine against a database built from this revision, for a document, a
vertex, an edge, an element-free projection row (the negative control) and an overriding row.
Refutations tried: (a) that values() on a Result is documented to include metadata while
keys() is not - the method's own comment states the opposite rule for the branch three lines up,
and Map and Document receivers both honour it; (b) that a Result receiver is an internal shape
users cannot reach - let $a = (select ...) and any sub-query row reach it, shown above;
(c) that the length mismatch alone explains it, so the override case is the same defect counted
twice - it is not, the override case keeps the same length and changes a value, and it comes from
the precedence half of ResultInternal.toMap() rather than from the metadata half, so a fix that
only switched to a toMap(false)-equivalent would leave it.
Not established, and recorded rather than claimed: select *, 'OVERRIDE' as s from D1 itself
renders "s":"x" in the row it returns while getProperty("s") answers OVERRIDE. That is the
same element-first precedence, reached through JsonSerializer rather than through values(), and
ResultInternal.toMap()'s comment says the precedence is deliberate for a different reason
(issue #5613), so settling whether the rendered row is right needs the projection semantics
decided first.
Activity
Merge pull request #9866 from ArcadeData/worktree-arcadedb-9843-9844-…
lvca commentedon Oct 12, 2026
Fixed in #9866 (26.11.1).
Confirmed: on a sub-query row (or a
LETvariable),values()returned the record's@cat,@typeand@ridas extra values, and for a row that overrode a property it returned the record's value instead of the row's.It now returns exactly one value per
keys()entry, in the same order, using the row's own value.keys()andvalues()share one code path, so they can't drift apart again.❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
Fix keys()/values() alignment on a result row, retention after BACKUP…
Fix keys()/values() alignment on a result row, retention after BACKUP…