Skip to content

Add per-row arithmetic and date/datetime math operators - #48

Merged
kudima03 merged 2 commits into
mainfrom
feat/each-arithmetic-and-date-math
May 25, 2026
Merged

Add per-row arithmetic and date/datetime math operators#48
kudima03 merged 2 commits into
mainfrom
feat/each-arithmetic-and-date-math

Conversation

@kudima03

@kudima03 kudima03 commented May 25, 2026

Copy link
Copy Markdown
Owner

Implements the operator additions discussed in #47.

Summary

  • Closes the gap that made per-row computed columns inexpressible (e.g. unit_price * quantity AS subtotal, sum(unit_price * quantity), order_date + 30 days, shipped_at - ordered_at > 48h).
  • Numeric: eachAdd / eachSubtract / eachMultiply / eachDivide with the same broadcast-scalar / zip-array polymorphism as 0.2.0's each* comparisons; returns numericArrayReturning.
  • Date math: eachDateAddDays / eachDateDiffDays (days as the unit).
  • Datetime math: eachDatetimeAddSeconds / eachDatetimeDiffSeconds (seconds as the unit). Larger units expressed via composition with eachMultiply — no interval type introduced.
  • CLAUDE.md rewritten around the "two operator families" model; previously-outdated rules about fields in arithmetic/comparison are replaced with a "where each family fits" table.
  • README extended with per-operator subsections covering all new operators.
  • Four new samples covering computed select columns, sum(eachMultiply(...)), date offsets, and datetime-diff filtering.
  • Version bump 0.1.0-preview.0.2.00.1.0-preview.0.3.0.

Closes #47.

Test plan

  • Schema is well-formed (Draft202012Validator.check_schema)
  • All 20 bundled samples validate against the new schema
  • CI (validate job) goes green on PR

Closes the gap that made per-row computed columns inexpressible. Adds
to the each* family established in 0.2.0:

- eachAdd / eachSubtract / eachMultiply / eachDivide (numeric)
  values items accept numericReturning or numericArrayReturning,
  result is numericArrayReturning; usable in select, aggregate args,
  and right operand of each* comparisons.
- eachDateAddDays / eachDateDiffDays (days as the unit)
- eachDatetimeAddSeconds / eachDatetimeDiffSeconds (seconds as the unit)

Larger date/datetime units are obtained by composition with eachMultiply
(e.g. add N hours = eachDatetimeAddSeconds(dt, eachMultiply(n, 3600))).
No interval type or per-unit operator family is introduced.

CLAUDE.md rewritten around the "two operator families" model;
previously-outdated rules about fields in arithmetic/comparison are
replaced with a where-each-family-fits table. README extended with
per-operator subsections and four new samples covering computed
columns, sum-of-product, date offsets, and datetime-diff filtering.

Version bump 0.1.0-preview.0.2.0 -> 0.1.0-preview.0.3.0. Refs #47.
@kudima03 kudima03 self-assigned this May 25, 2026
… semantics

Mirrors the date/datetime math operators for the time type with seconds as
the unit, restoring symmetry across all temporal types. eachTimeAddSeconds
returns timeArrayReturning; eachTimeDiffSeconds returns numericArrayReturning.
Wrap-around behaviour at the day boundary is deliberately interpreter-
defined.

Adds a dedicated "Broadcast vs zip" subsection to CLAUDE.md, README, and
CHANGELOG interpreter notes. Explains that any each* slot accepting both
*Returning and *ArrayReturning fixes a row count N from the surrounding
context, broadcasts scalars to length N, zips arrays element-wise, then
applies the operator. Key point: the result is *ArrayReturning even when
every operand is scalar (eachAdd(2, 3) over 4 rows yields [5, 5, 5, 5]),
which is why eachX cannot be optimized into its single-value sibling.

Sample 21 demonstrates eachTimeAddSeconds and eachTimeDiffSeconds over
clock_in / clock_out time fields.
@kudima03
kudima03 merged commit b4309c7 into main May 25, 2026
1 check passed
@kudima03
kudima03 deleted the feat/each-arithmetic-and-date-math branch May 25, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add per-row arithmetic and date/datetime math operators (each* family)

1 participant