Skip to content

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

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.

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