Repository navigation
Description
Summary
Regression introduced by PR #7845 (commit 5f4ee25c0c, "Fix issues #7774, #7773, #7766, #7765"), in the part that fixes #7773.
#7773 was about SELECT * plus an extra projection item. On such a row Projection.calculateSingle() sets both the backing element (for the *) and explicit content entries, so Result.toJSON()'s isElement() short-circuit answered the record and dropped the computed alias. The fix skips that short-circuit whenever hasProjectedProperties() is true.
The trouble is that hasProjectedProperties() is content != null && !content.isEmpty(), and a plain SELECT * populates content too. So a statement that reshapes nothing now also takes the new path, and the property loop emits only what getPropertyNames() lists. For anything that is not a plain document that is strictly less than the record's own toJSON():
- every row loses
@cat(d/v/e), the only thing in the JSON that says whether the row is a document, a vertex or an edge; - an EDGE row additionally loses
@inand@out, so the serialized edge no longer says which vertices it connects and cannot be reconstructed from its JSON at all.
What worked before and does not now: before the PR ResultInternal had no toJSON() override, so every isElement() row, SELECT * included, went through Result.toJSON()'s return getElement().get().toJSON(); and got the full record form. Today SELECT FROM E1 still answers the full form while SELECT * FROM E1 does not, so two statements returning the same rows serialize them differently. #7773 explicitly asked for the plain SELECT * case not to change, and the fix's own test is named after that promise.
The stated goal of #7773, the two serializers agreeing, is also still unmet in the other direction: JsonSerializer.serializeResult does emit @cat.
Where (HEAD 06b033d)
engine/src/main/java/com/arcadedb/query/sql/executor/ResultInternal.java:373-383
@Override
public JSONObject toJSON() {
if (isElement() && !hasProjectedProperties())
return getElement().get().toJSON();
final JSONObject result = new JSONObject();
for (final String prop : getPropertyNames())
result.put(prop, valueToJSON(getProperty(prop)));
return result;
}engine/src/main/java/com/arcadedb/query/sql/executor/ResultInternal.java:357-359, the predicate that is doing the work, whose own javadoc describes it as a DISTINCT helper:
public boolean hasProjectedProperties() {
return content != null && !content.isEmpty();
}The diff that introduced it, for reference, is BaseExpression-adjacent in the same commit; before 5f4ee25c0c there was no toJSON() override on ResultInternal at all.
Repro
One vertex type V1 with two vertices, one edge E1 carrying w = 5, one document type T. Printing the row's own toJSON() next to the backing record's:
SELECT * FROM E1
isElement=true hasProjected=true names=[w, @rid, @type]
row.toJSON = {"w":5,"@rid":"#4:0","@type":"E1"}
element.toJSON = {"w":5,"@cat":"e","@type":"E1","@rid":"#4:0","@in":"#1:1","@out":"#1:0"}
SELECT FROM E1
isElement=true hasProjected=false names=[w]
row.toJSON = {"w":5,"@cat":"e","@type":"E1","@rid":"#4:0","@in":"#1:1","@out":"#1:0"}
element.toJSON = {"w":5,"@cat":"e","@type":"E1","@rid":"#4:0","@in":"#1:1","@out":"#1:0"}
SELECT * FROM V1 LIMIT 1
isElement=true hasProjected=true names=[name, @rid, @type]
row.toJSON = {"name":"a","@rid":"#1:0","@type":"V1"}
element.toJSON = {"name":"a","@cat":"v","@type":"V1","@rid":"#1:0"}
SELECT * FROM T
isElement=true hasProjected=true names=[name, n, @rid, @type]
row.toJSON = {"name":"n1","n":1,"@rid":"#5:0","@type":"T"}
element.toJSON = {"name":"n1","n":1,"@cat":"d","@type":"T","@rid":"#5:0"}
hasProjected printing true for SELECT * FROM E1 and false for SELECT FROM E1 is precisely the branch that changed, and names shows @cat / @in / @out are not reachable as ordinary row properties either.
Reachable from plain SQL through the asJSON() method, which is the path the fix's own last test exercises:
SELECT $a.asJSON() AS j FROM V1 LET $a = (SELECT * FROM E1) LIMIT 1
-> [{"w":5,"@rid":"#4:0","@type":"E1"}]
SELECT $a.asJSON() AS j FROM V1 LET $a = (SELECT FROM E1) LIMIT 1
-> [{"w":5,"@cat":"e","@type":"E1","@rid":"#4:0","@in":"#1:1","@out":"#1:0"}]
An earlier, independent run on a differently built schema (a vertex type P and an edge type K carrying w = 7) reached the same conclusion by a different route:
SELECT * FROM P (vertex)
toJSON = {"name":"a","@rid":"#1:0","@type":"P"}
record = {"name":"a","@cat":"v","@type":"P","@rid":"#1:0"}
SELECT * FROM K (edge)
toJSON = {"w":7,"@rid":"#4:0","@type":"K"}
record = {"w":7,"@cat":"e","@type":"K","@rid":"#4:0","@in":"#1:1","@out":"#1:0"}
SELECT FROM P (no star, short-circuit still taken)
toJSON = {"name":"a","@cat":"v","@type":"P","@rid":"#1:0"}
SQL: SELECT $a.asJSON() ... LET $a = (SELECT * FROM K) => {"w":7,"@rid":"#4:0","@type":"K"}
Why the PR's own test did not catch it
engine/src/test/java/com/arcadedb/query/sql/executor/Issue7773ResultToJSONProjectedRowTest.java:95-109:
@Test
void plainSelectStarIsUnchangedAndStillCarriesRidAndType() throws Exception {
TestHelper.executeInNewDatabase("issue7773PlainStar", (db) -> {
db.command("sql", "CREATE DOCUMENT TYPE T");
db.command("sql", "INSERT INTO T SET n = 1");
try (final ResultSet rs = db.query("sql", "SELECT * FROM T")) {
final Result row = rs.next();
final JSONObject json = row.toJSON();
assertThat(json.getInt("n")).isEqualTo(1);
assertThat(json.has("@rid")).isTrue();
assertThat(json.has("@type")).isTrue();
}
});
}The test asserts "unchanged" while checking only n, @rid and @type. It never checks @cat, and it uses a DOCUMENT type, so it cannot see the @in / @out loss at all. No test in the PR uses a vertex or an edge.
Suggested fix
Keep the property loop, which is what #7773 needs, but seed it from the record's structural attributes when the row still carries an element, instead of from nothing. When isElement(), start the object from getElement().get().toJSON()'s @cat / @type / @rid / @in / @out entries and then let the row's own properties overwrite and the exclusions remove. That keeps a reshaped row's alias and makes an unreshaped one byte-for-byte what it used to be.
The alternative, having Projection.calculateSingle() not count the implicit @rid / @type it writes for a bare * as "projected properties", restores the short-circuit for the plain case but leaves SELECT *, n+1 AS z on an EDGE still dropping @in / @out, which no reading of #7773 wants. The attribute-seeding form fixes both.
Whichever form is chosen, plainSelectStarIsUnchangedAndStillCarriesRidAndType should assert the whole object against the record's own toJSON(), and should be repeated on a vertex type and an edge type.
Scope / confidence
Reproduced at HEAD 06b033d by two independent investigations, on different schemas and through different entry points, with matching results.
Refutation attempts that failed:
- "the HTTP/query surface does not use
Result.toJSON(), so nothing observable changed." The HTTP handlers go throughJsonSerializer.serializeResult, which is unchanged, butResult.toJSON()is not dead: theasJSON()SQL method (reproduced above),Result.valueToJSON()'s recursion into a nestedResult, the AI tool dispatcher's per-row JSON, the Postgres wire's serialization of a nestedResultvalue, and the Bolt executor's first-result rendering all call it. - "maybe
SELECT *never produced@in/@outthrough this path." It did. The pre-fix code had no override, so theisElement()short-circuit answeredgetElement().get().toJSON()for exactly these rows, andSELECT FROM E1, which still takes that short-circuit today, shows what that form contains. - "maybe a plain
SELECT *does not setcontent." It does;hasProjectedProperties()printstrueforSELECT * FROM E1andfalseforSELECT FROM E1in the run above. - "maybe
@cat/@in/@outare reachable as ordinary properties of the row." They are not. The printed key set for aSELECT *edge row is[w, @rid, @type].
What would falsify it: a decision that SELECT * is meant to answer only the projected columns and that dropping the edge endpoints is intended. That cannot be reconciled with the fix's own test asserting plain SELECT * is "unchanged", nor with SELECT FROM E1 still answering the full form.
Activity
fix(#7868,#7905,#7858,#7906,#7895): carry the owner row, answer trans…
fix(#7868,#7858,#7895): one singleton row for every family this catal…
fix(#7895): SELECT *, !@Rid means what it says - the toJSON seed must…
Merge pull request #7929 from ArcadeData/fix/issues-7868-7905-7858-79…
lvca commentedon Sep 18, 2026
Fixed in #7929, released in 26.10.1.
A regression in 26.10.1 development:
SELECT * FROM ...lost@catfrom every row, and lost@inand@outon edges, when the row was converted to JSON (for example via theasJSON()SQL method). A serialized edge no longer said which vertices it connected, so it could not be rebuilt from its own JSON, whileSELECT FROM ...on the same rows still returned the full form.SELECT *now returns the same JSON as the record itself. Excluding an attribute explicitly, for exampleSELECT *, !@rid, still leaves it out.❤️ 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.