Architecture decision record · ADR-0022

Server-side tree data in the wire protocol

RowsRequest.tree?: { keys: Scalar[] } asks for one level of the tree.

Status
Proposed
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
None

Context

AG Grid Enterprise has server-side tree data. The grid option treeData: true turns it on. The client asks for one level at a time. The request groupKeys is the path of keys from a root to the parent row. Three callbacks read each row: isServerSideGroup (the row can expand), getServerSideGroupKey (the key of the row in the path) and getChildCount (the number of child rows). The names come from entities/gridOptions.ts at the commit that ADR 0005 pins.

The Lattice protocol (ADR 0005) has group levels, but not tree data. The parity matrix lists "Server-side tree data (E)" as planned. Two table shapes are common for a tree in SQL: a self-referencing parent column, and a materialized path.

Decision drivers

Not recorded in the original ADR.

Options considered

Not recorded in the original ADR.

Decision

The request and the response

  • RowsRequest.tree?: { keys: Scalar[] } asks for one level of the tree. keys is the path of row keys from a root to the parent row. Empty keys gives the roots.
  • In a tree response, each row has $count (GROUP_COUNT_KEY): the number of its direct child rows that match the filter and the quick search. So the count of a child level is the $count of its parent row. A row with $count > 0 can expand, and its group key is its row key. $count is in the row also when columns does not name it.
  • The filter and the quick search apply to each level and to $count. A parent row that does not match the filter is not in its level, also when a child matches.
  • Sort, paging (offset and cursor) and projection are the same as for leaf rows. The key is the last sort key.

The allow-list

The server, not the request, gives the shape of the tree. A ColumnSchema can have one of two new flags:

  • parent: true: the column holds the key of the parent row, or null for a root. It has the type of the key.
  • path: true: a string column that holds the keys of the ancestors from the root, joined with TREE_PATH_SEPARATOR (/). A root has the empty string. The path of row 8 under 2 and 4 is 2/4.

The two shapes give the same response for the same tree. A protocol test runs every tree case on both datasets and compares the rows.

Semantics of a path

  • Parent column: the level is the rows whose parent is the last key (null for the roots). Each key must also be a child of the key before it, and the first key must be a root. The chain uses all the rows in the server scope, not the filter. A server writes one flat exists (select 1 from t where key = k_i and parent = k_{i-1}) for each key. There is no recursive query.
  • Path column: the level is the rows whose path equals the keys joined with /.
  • A path that is not a real chain gives no rows and count: 0 in both shapes.
  • $count is a correlated count of the child rows: child.parent = row.key, or child.path = prefix || cast(row.key as text). prefix is a bound parameter.

The trust boundary

parseRowsRequest checks tree:

  • tree is an object with only keys.
  • The allow-list must have a key column and a parent or path column, else invalid.
  • tree cannot have group.by, pivot or aggregate, else invalid. This keeps the SQL of each port small. A later version can add them.
  • keys.length is at most LIMITS.maxTreeDepth (16), else too_deep. So the chain has at most 16 exists tests, and each one has two bound parameters.
  • Each key has the type of the key column and is not null. A number key is a safe integer, so each port writes it in a path in the same way (4, not 4.0). With a path column, a string key cannot contain /. These errors have the code invalid. The rules for strings (length, U+0000, lone surrogates) also apply.

Version

The change is additive inside version 1. A request without tree gives the same response as before. A server that does not know tree rejects it with unknown_key, so a client sees the gap and does not get flat rows. ADR 0005 item 7 records the change.

Conformance

The suite has two new datasets, tree_parent and tree_path: the same eleven-row tree in the two shapes. Each tree case runs on both datasets, with the dataset name in the case name. The cases cover the roots, two levels, a row with no children, a broken chain, a missing key, the filter and search on the level and on $count, sort with nulls, projection, offset paging, a cursor page, a cursor walk and seven error cases. One more error case asks for tree data on people. The suite has 122 cases (81 before).

AG Grid

  • fromAgGrid(request, { columns, treeData: true }) reads groupKeys as tree.keys, typed by the key column. It rejects rowGroupCols with tree data.
  • agGridTree(key) gives the AG Grid options treeData, isServerSideGroup ($count > 0), getServerSideGroupKey (the row key as a string) and getChildCount ($count).
  • In @ember-lattice/data-ag-grid, toAgGridRequest writes tree.keys as string groupKeys with no row group columns. The tree.getChildCount option of agGridDataSource gives each backend row its $count.

The client

ServerRowModel takes tree: { key, label }. Each tree level is a node with its own block cache (the existing Switchyard block machines). A row with $count > 0 is a group row with its own row ID. Its children load when it expands and comes into view. The group cell shows the label column and $count. arrayDataSource has the tree capability when its allow-list has a parent or path column.

Consequences

  • Each server port must port the new parser rules and the tree SQL. The Node (Kysely), Rails (Arel) and Python (SQLAlchemy) ports pass the tree cases on SQLite and Postgres.
  • The key column must be an integer or a string column. A path built from a real number key in SQLite (4.0) does not match.
  • MySQL concatenates with concat(), not ||. All three ports write concat() for MySQL. Only compiled-SQL tests check this, because no MySQL gate runs.
  • A filter hides a parent row that does not match, also when a child matches. Tree filter modes that keep the ancestors of a match need a recursive query. That is not in version 1.
  • $count costs one correlated subquery for each row of the page. An index on the parent or path column keeps it fast.

Confirmation

Not recorded in the original ADR.

Interview record

Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.

QuestionAnswerSource
Where does the text of this page come from?From the Markdown file docs/adr/0022-server-tree-data.md at commit 4c77ac4. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so.Document: docs/adr/0022-server-tree-data.md

Changelog

DateAuthorChange
2026-12-02Joe GaudetStatus in the Markdown file: proposed, 2026-12-02.
2026-12-03Joe GaudetCommit 7ce4af2: Lattice 1.0 (#1)
2026-12-04Joe Gaudet (agent)Converted from docs/adr/0022-server-tree-data.md to this page. The text is the text of the Markdown file.

The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.