Skip to content

feat(match): add contains, datetime-hours and geo-radius comparators (#795) - #852

Merged
athvin merged 3 commits into
mainfrom
issue/795-classic-comparators
Nov 8, 2026
Merged

athvin merged 3 commits into
mainfrom
issue/795-classic-comparators

Conversation

@athvin

@athvin athvin commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Closes #795

🚧 Claimed by an agent session — 2026-11-08T11:43:02Z, session 01a1b892-4cde-7a53-bb3e-9ed2e764acdc on Mac.
The claim is this open draft PR: closing it releases the ticket.

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

Adds the three missing Classic comparators to er-compile::resolve_level_pair: contains (bidirectional substring, blank-guarded), datetime_within_hours:<n> (elapsed-time via epoch seconds), and geo_within_km:<km> (Haversine over a "lat,lng" text column, malformed values deny). All three join the UnknownLevel known-comparator list and the group-capable token list.

Why

Spec unit 1.6 (#795, parent #513): the comparison-operator pillar has three gaps — substring containment, hour-granular datetime tolerance, and geolocation radius. The spec's 65% default-similarity bullet is decided not to build; rationale on the issue.

Proof

make check in the worktree (result recorded below once green). Behavioral coverage: comparator_sql_behaviour.rs gains three DuckDB-evaluated probes — contains both directions plus the blank-guard case, datetime across an hour boundary (the case date_diff('hour') gets wrong), Haversine at known distances plus malformed-point denial — run with DEDUPE_E2E_EXTENSIONS=1 cargo test -p er-compile --test main (26 passed). The boundary case failed against date_diff semantics by construction and passes against epoch arithmetic.

Risk & rollback

Purely additive: three new tokens; no existing token's emitted SQL changes, so COMPARATOR_ALGORITHM_VERSION stays at 1 per its own doc comment (bump on semantics change, never on addition). Rollback: git revert <merge-sha> — compiled models are untouched because none can reference tokens that did not exist.

Post-merge ledger

Closed by: agent · session 01a1b892-4cde-7a53-bb3e-9ed2e764acdc on Mac · 2026-11-08T13:00:00Z

  • main is green with this change on it — merge SHA 79121d80 (confirmed
    on origin/main); rust, frontend, infra, devcontainer all success
    on that exact SHA (push-triggered runs).
  • images — success on 79121d80 (Rust sources changed, so the engine
    and control-plane images rebuilt).
  • deploy converged — run 42481744391: deployment "web-api-green" successfully rolled out, then cut-over Release "er-platform" has been upgraded. STATUS: deployed (2026-11-08T12:48:43Z).
  • the push-only surface no pull request can pre-test — deploy green above;
    drift scheduled daily, last run 2026-11-08T06:02Z success on b4b0b0fb
    (this diff adds no terraform/helm, nothing for drift to find); kind nightly
    leg last ran 2026-11-08T06:44Z success.
  • the board card — issue feat(match): add the three missing Classic comparators — contains, datetime tolerance, geo radius #795 CLOSED via the Closes #795 reference;
    card read back at Done after the close (project build(deps): bump actions/checkout from 4.2.2 to 7.0.1 #2 item-list).
  • follow-ups — none deferred. The spec's 65% default-similarity bullet was
    a decision, not work: answered on feat(match): add the three missing Classic comparators — contains, datetime tolerance, geo radius #795 (keep explicit per-level thresholds).
  • what was learned is written down — the token table in
    .claude/skills/er-matching/references/config-to-model.md gained the three
    rows in this PR; the DuckDB NaN-sorts-above-everything hazard is recorded in
    the geo_within_km guard comment in er-compile/src/lib.rs and pinned by
    unit tests.

Specific to this change

Context — plan, discoveries, measurements, files

Plan

  • Probe the existing comparator shape (numeric_within guards, parameter helper, group-capable list).
  • Add the three tokens + error-list updates in rust/crates/er-compile/src/lib.rs.
  • Unit tests: bad-parameter paths, UnknownLevel message names the new tokens.
  • Behavioral DuckDB probes in comparator_sql_behaviour.rs (observed failing first: the geo probe caught a real paren bug in the Haversine SQL before it ever passed).
  • Answer the 65%-default question on the issue → decided: keep explicit thresholds, do not port the default.
  • make check.
  • pr-review → mark ready → land.

Discoveries

  • The scope comment's geo concern (no geo columns in entities/) is answered by the encoding: the token compares a single "lat,lng" text column via split_part + try_cast, so no schema or standardize change is required and any source that can produce text can carry a point. Malformed values deny rather than error — the contract numeric_within already keeps.
  • DuckDB contains(x, '') is true for every x — the empty-string guard is load-bearing, not defensive.
  • date_diff('hour', …) counts hour boundaries: 00:59 vs 01:00 reads as an hour apart. The datetime token is epoch-seconds arithmetic instead; the behavioral probe asserts the boundary case.
  • COMPARATOR_ALGORITHM_VERSION deliberately not bumped: its doc comment scopes bumps to semantics changes of existing tokens; additions leave every compiled model's frozen SQL valid.
  • Skill reference .claude/skills/er-matching/references/config-to-model.md carries a hand-maintained token table — extended with the three rows (the drift risk the table's intro warns about).

Measurements

Files

  • rust/crates/er-compile/src/lib.rs — the three comparator arms, both error-message lists, unit tests.
  • rust/crates/er-compile/tests/comparator_sql_behaviour.rs — three behavioral probes + bad-parameter tokens.
  • .claude/skills/er-matching/references/config-to-model.md — token table rows.

…795)

- contains: bidirectional substring, blank-guarded (contains(x,'') is
  true for every x in DuckDB)
- datetime_within_hours:<n>: elapsed-time tolerance via epoch seconds,
  not date_diff('hour') which counts boundaries
- geo_within_km:<km>: Haversine over a "lat,lng" text column; malformed
  points deny via try_cast guards, the numeric_within contract
- all three named in UnknownLevel and the group-capable token list
- behavioral DuckDB probes for each (the geo probe caught a paren bug
  before first pass); bad-parameter paths covered in both tiers
- er-matching config-to-model token table extended
- 65% default similarity decided against on the issue: explicit
  per-level thresholds stay
pr-review surfaced it: 'NaN'.parse::<f64>() succeeds and NaN <= 0.0 is
false in Rust, so a bare sign guard passes NaN through — and in DuckDB
NaN sorts above every number, so distance <= NaN is TRUE for every
pair: the level that matches everything. Guard is now is_finite && > 0,
with NaN/inf unit tests. Also uniform skip notices across the three new
behavioral probes.
@athvin
athvin marked this pull request as ready for review November 8, 2026 12:29
@athvin
athvin merged commit 79121d8 into main Nov 8, 2026
44 checks passed
@athvin
athvin deleted the issue/795-classic-comparators branch November 8, 2026 12:57
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.

feat(match): add the three missing Classic comparators — contains, datetime tolerance, geo radius

2 participants