Skip to content

origin.expression: computed projection columns (post-1.0, additive) #159

Open

Description

@dmealing

Motivation

Projections can rename (origin.passthrough), aggregate over a relationship (origin.aggregate), and nest (origin.collection) — but can't express a per-row computed value. Real cases: a cost column = tokens × price (price @via-joined from a models table), and various rate/ratio columns that adopters hand-roll in SQL (the verify "hand-rolled aggregate" advisories that are arithmetic, not pure SUM/AVG).

Proposal (sketch)

A fourth origin, origin.expression, with @expr (a per-row expression over own + @via-joined fields) and optional @via. Rendered into the generated view SELECT via a closed, per-dialect mini-grammar (arithmetic + comparison + boolean + CASE + a small function allow-list) — not raw SQL (portable + no injection surface). Field refs resolve against the symbol table (a dangling ref fails the load), like origin.aggregate.@of. Cross-port (a DB-projection concern, so it lives where view/query codegen lives).

Post-1.0 additive per ADR-0037's framework. Phasing: (1) own-column expressions (no join) — unblocks the arithmetic advisories; (2) @via-joined expressions (reuse the reference-hop).

A downstream adopter will prototype the metadata shape against a real computed-cost case to validate the syntax before upstream implementation. Full design sketch available.

Activity

  1. dmealing commented on Jul 16, 2026

    @dmealing
    MemberAuthor

    Retired by #195: the reserved origin.expression subtype is superseded by origin.computed (shipped in #195), which carries a structured attr.expression tree (a closed node grammar: field/value refs, comparisons sharing the filter op vocabulary, isNull/isNotNull, and/or/not, coalesce) rather than a SQL string. This issue's future arithmetic (+ - * /), case/if, string functions, and @via-joined field refs become additive node kinds in that grammar — no second expression language. The grammar was designed for exactly this extension (see docs/superpowers/specs/2026-07-15-issue-195-projection-readmodel-origins-design.md §4bis).

  2. dmealing commented on Oct 2, 2026

    @dmealing
    MemberAuthor

    Status check 2026-10-02: origin.computed shipped in 0.17.0 with comparisons and coalesce. The remaining scope (arithmetic, case/when, @via) is FR-037 R5's fn growth, now tracked in #393.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions