Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/33792-cross-object-orphan-native.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@objectstack/service-analytics': patch
---

fix(service-analytics)!: the native SQL strategy evaluates a cross-object `where` leaf on an existing parent, so a detail row with no parent is not selected, as on the engine path and `/data`

Clause-②: no (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. The moved answer is an aggregate over a cross-object filter, which now leaves out the detail rows with no parent, as the engine path and the /data nested-relation filter already did: no stored row, registry key or authored value changes, so there is nothing for a migration to rewrite and no tombstone. -->

**BREAKING** for a reader of an analytics answer served by the native SQL strategy (a cube or dataset query with no bucketed time dimension, on a SQL datasource) that reads a related object's field through a relationship path (`'order.status'`) in any of the three filter positions one compile serves: the query's `where`, a measure's own `filter` (its conditional aggregate) and the dataset's own `filter`:

- FROM: a detail row whose relation field is empty, or names no existing record, was selected by `$ne`, `$nin`, `$notContains`, `$null: true`, `$eq: null`, `$exists: false` and `$empty: true` on the related field, because the `LEFT JOIN` read every related column of such a row as NULL. So the same widget answered a different total once a time bucket sent it to the engine path. TO: such a leaf is evaluated on an existing parent (the last hop's `id = id` is conjoined to it, through every hop of the path: TRUE for an existing parent, UNKNOWN for none, so a `$not` cannot flip it), and outside `$not` no such row is selected by those operators. Under `$not` the native answer is the one it gave before. The native, engine and `/data` answers agree on those operators.

**Not moved.** A parent that exists with no value in the field still satisfies `$ne`, `$nin`, `$notContains` and `$null: true`. A positive operator (`$eq` a value, `$in`, `$gt`, `$contains`, …) selected no such row before either, and its statement is unchanged. A leaf on the base relation field itself (`{ order: { $null: true } }`) reads no join and is unchanged. Two native-path answers still select such a row, unchanged by this release: a positive comparison under `$not` (`{ $not: { 'order.status': 'open' } }`, a shape the engine path refuses; write `$ne` / `$nin` inside the condition instead), and `$nin: []`, which folds to the constant TRUE and selects every row, where the engine path leaves such rows out.

The fix for an author who wants the rows with an empty relation: OR the base relation field in, `{ $or: [{ 'order.status': { $ne: 'open' } }, { order: { $null: true } }] }`. A row naming a record that no longer exists is not brought back by it, on either path.
15 changes: 15 additions & 0 deletions content/docs/ui/dashboards.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,21 @@ the base rows whose relationship points at a record it returned:
condition under `$not` (write `$ne` / `$nin` inside the condition instead), and
a related field compared with another field (`$field`).

On the native SQL path, too, a related-field condition that is not under
`$not` never selects a row with no related record (an empty relationship, or
one naming a record that no longer exists), whether it sits in the query's
filter, a measure's own `filter` or the dataset's own `filter`: `$ne`, `$nin`,
`$notContains`, `$null: true`, `$eq: null`, `$exists: false` and `$empty: true`
included, so the two paths agree on such rows. The same `$or` brings back the
rows with an empty relationship on both paths; a row naming a record that no
longer exists is not brought back by it. A related record that exists with no
value in the field still satisfies `$ne` and `$nin`. Two native-path exceptions
remain: under `$not`, which the engine path refuses, the native path still
selects such a row when the negated condition is a comparison with a value
(`{ $not: { 'order.status': 'open' } }`), so write `$ne` / `$nin` inside the
condition instead; and `$nin: []` (an empty list) selects every row on the
native path, such rows included, where the engine path leaves them out.

A related field in a **dataset's own** `filter`, or in a **measure's** own
`filter`, is still evaluated only on the native SQL path; the engine-aggregate
path refuses it (`400 INVALID_FIELD`) rather than count rows it cannot join.
Expand Down
Loading
Loading