Skip to content

Arithmetic expression support - #13

Merged
colemancda merged 2 commits into
masterfrom
feature/arithmetic-expression
Aug 16, 2026
Merged

Arithmetic expression support#13
colemancda merged 2 commits into
masterfrom
feature/arithmetic-expression

Conversation

@colemancda

Copy link
Copy Markdown
Member

Implements ArithmeticExpression (CoreModel 2.11.0) as native SQL, replacing the previous invalidPredicate rejection.

Translation

(a <op> b) <operator> constant compiles to a parenthesized SQL expression with positional bindings, recursively for nested operands. SQLite's native operators match CoreModel's in-memory engine where it matters:

  • / truncates when both operands are INTEGER (7 / 2 is 3) and promotes to REAL when either is floating point
  • division or remainder by zero yields SQL NULL, which fails every comparison — the same observable outcome as the engine's nil

Deliberate divergence handling

  • .modulus with a statically-known non-integer operand is rejected (invalidPredicate) rather than translated: SQLite's % casts operands to INTEGER, but CoreModel defines remainder for integers only, and a silently cast result would differ between backends. Operand types are resolved from the entity description (composite element columns included); unknown types (e.g. a custom function's result) pass through, where NULL propagation makes a wrong guess harmless.
  • The only knowing divergence is at the edges of Int64: the in-memory engine wraps, SQLite promotes an overflowing INTEGER result to a REAL approximation. Documented in the source.

Testing

10 new tests against real SQLite files: integer add/divide/modulus, truncation, division-by-zero across three operators, float promotion, float-modulus rejection, nested expressions, compound predicates — plus a sweep asserting SQL and in-memory evaluation return identical row sets for the same inputs. All 127 tests pass.

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Swift

Swift / code-coverage/llvm-cov

The overall coverage in commit 26e78be in the feature/arithmetic-e... branch is 98%. The coverage in commit 1cdf583 in the master branch is 99%.

Show a code coverage summary of the most impacted files.
File master 1cdf583 feature/arithmetic-e... 26e78be +/-
Sources/CoreMod...Predicate.swift 99% 96% -3%

@colemancda
colemancda merged commit b413e5d into master Aug 16, 2026
28 checks passed
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