Skip to content

The #7773 toJSON() fix also fires for a plain SELECT *, so an edge row loses @cat, @in and @out and a vertex row loses @cat #7895

Closed

Description

@rspereiratech

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 @in and @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 through JsonSerializer.serializeResult, which is unchanged, but Result.toJSON() is not dead: the asJSON() SQL method (reproduced above), Result.valueToJSON()'s recursion into a nested Result, the AI tool dispatcher's per-row JSON, the Postgres wire's serialization of a nested Result value, and the Bolt executor's first-result rendering all call it.
  • "maybe SELECT * never produced @in / @out through this path." It did. The pre-fix code had no override, so the isElement() short-circuit answered getElement().get().toJSON() for exactly these rows, and SELECT FROM E1, which still takes that short-circuit today, shows what that form contains.
  • "maybe a plain SELECT * does not set content." It does; hasProjectedProperties() prints true for SELECT * FROM E1 and false for SELECT FROM E1 in the run above.
  • "maybe @cat / @in / @out are reachable as ordinary properties of the row." They are not. The printed key set for a SELECT * 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

  1. added
    engine
    on Sep 18, 2026
  2. added this to the 26.10.1 milestone on Sep 18, 2026
  3. added
    in progress
    on Sep 18, 2026
  4. self-assigned this
    on Sep 18, 2026
  5. added 4 commits that reference this issue on Sep 18, 2026
  6. lvca commented on Sep 18, 2026

    @lvca
    Member

    Fixed in #7929, released in 26.10.1.

    A regression in 26.10.1 development: SELECT * FROM ... lost @cat from every row, and lost @in and @out on edges, when the row was converted to JSON (for example via the asJSON() SQL method). A serialized edge no longer said which vertices it connected, so it could not be rebuilt from its own JSON, while SELECT 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 example SELECT *, !@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.

  7. removed
    in progress
    on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenginesql

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions