Skip to content

fix(arith): one typed arithmetic and comparison evaluator - #156

Merged
jsam merged 3 commits into
mainfrom
fix/typed-arithmetic
Oct 3, 2026
Merged

jsam merged 3 commits into
mainfrom
fix/typed-arithmetic

Conversation

@jsam

@jsam jsam commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

What: Adds value::arith, one evaluator for head, assignment and comparison arithmetic, plus constant folding. Ints use checked i64 ops and give Null on overflow. A Float operand promotes the result to Float, and / always gives Float. Timestamp ± Int stays a Timestamp. A non-numeric operand gives Null. Timestamp-vs-Float comparisons work. Folded and runtime comparisons treat Null the same way. Body and negated atoms with expression arguments (e(X, Y + 1)) are now rejected; before, they were silently read as e(X, Y).

Why: Float columns failed comparisons and float constants were truncated when folded. i64 overflow wrapped or panicked (including MIN / -1). Large ints lost precision going through f64. Null or String operands counted as 0.

Tests: new tests/typed_arithmetic_tests.rs plus unit tests in value::arith. cargo fmt --check, cargo clippy --workspace --all-targets --all-features -D warnings and cargo test --workspace all pass. Snapshot tests: 1149 passed, 0 failed.

@jsam
jsam force-pushed the fix/aggregate-correctness branch from 3ae7ef4 to 9ae5c19 Compare October 3, 2026 10:09
@jsam
jsam force-pushed the fix/typed-arithmetic branch from 81efe72 to a330631 Compare October 3, 2026 10:12
@jsam
jsam force-pushed the fix/aggregate-correctness branch from 9ae5c19 to f75206f Compare October 3, 2026 11:01
Base automatically changed from fix/aggregate-correctness to main October 3, 2026 11:01
jsam added 3 commits October 3, 2026 13:07
Head, assignment and comparison arithmetic plus constant folding now share
value::arith: checked i64 (Null on overflow), Float promotion, / as Float,
Timestamp +/- Int stays Timestamp, Null for non-numeric operands.

Fixes float columns failing comparisons, float constants truncated when
folded, i64 wrap/panic on overflow and MIN / -1, and large ints losing
precision through f64.
e(X, Y + 1) and !e(X, Y + 1) were silently read as e(X, Y). Arithmetic and
function-call arguments in body and negated atoms now fail rule validation
and IR building with an error that suggests binding a variable instead.
…mpare

Timestamp vs Float comparisons now compare as f64 instead of failing.
Folded column comparisons use arith::compare, so Null and non-numeric
columns behave the same whether or not the right side is constant.
Remove the int-only ArithExpr::try_eval_constant.
@jsam
jsam force-pushed the fix/typed-arithmetic branch from a330631 to 3d29c2f Compare October 3, 2026 11:07
@jsam
jsam merged commit 7832176 into main Oct 3, 2026
0 of 12 checks passed
@jsam
jsam deleted the fix/typed-arithmetic branch October 3, 2026 11:07
jsam added a commit that referenced this pull request Oct 3, 2026
#156's rejection test predates #154, which reports statement failures in
QueryResult.errors instead of an Err.

Co-authored-by: Claude Opus 5.5 <[email protected]>
jsam added a commit that referenced this pull request Oct 3, 2026
* fix(arith): evaluate arithmetic with one typed Value evaluator

Head, assignment and comparison arithmetic plus constant folding now share
value::arith: checked i64 (Null on overflow), Float promotion, / as Float,
Timestamp +/- Int stays Timestamp, Null for non-numeric operands.

Fixes float columns failing comparisons, float constants truncated when
folded, i64 wrap/panic on overflow and MIN / -1, and large ints losing
precision through f64.

* fix(ir): reject expression arguments in body atoms

e(X, Y + 1) and !e(X, Y + 1) were silently read as e(X, Y). Arithmetic and
function-call arguments in body and negated atoms now fail rule validation
and IR building with an error that suggests binding a variable instead.

* fix(arith): compare timestamps with floats and fold through arith::compare

Timestamp vs Float comparisons now compare as f64 instead of failing.
Folded column comparisons use arith::compare, so Null and non-numeric
columns behave the same whether or not the right side is constant.
Remove the int-only ArithExpr::try_eval_constant.
jsam added a commit that referenced this pull request Oct 3, 2026
#156's rejection test predates #154, which reports statement failures in
QueryResult.errors instead of an Err.
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.

1 participant