Add per-row arithmetic and date/datetime math operators - #48
Merged
Conversation
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.
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the operator additions discussed in #47.
Summary
unit_price * quantity AS subtotal,sum(unit_price * quantity),order_date + 30 days,shipped_at - ordered_at > 48h).eachAdd/eachSubtract/eachMultiply/eachDividewith the same broadcast-scalar / zip-array polymorphism as0.2.0'seach*comparisons; returnsnumericArrayReturning.eachDateAddDays/eachDateDiffDays(days as the unit).eachDatetimeAddSeconds/eachDatetimeDiffSeconds(seconds as the unit). Larger units expressed via composition witheachMultiply— nointervaltype introduced.CLAUDE.mdrewritten around the "two operator families" model; previously-outdated rules about fields in arithmetic/comparison are replaced with a "where each family fits" table.selectcolumns,sum(eachMultiply(...)), date offsets, and datetime-diff filtering.0.1.0-preview.0.2.0→0.1.0-preview.0.3.0.Closes #47.
Test plan
Draft202012Validator.check_schema)validatejob) goes green on PR