frs_candidates_pick: score + filter + dedup candidates per key (v0.31.0)#209
Merged
NewGraphEnvironment merged 6 commits intoMay 11, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
R/frs_candidates_pick.R + man/frs_candidates_pick.Rd + NAMESPACE
export. Function signature follows table_<role> / col_<role> /
exp_<role> conventions:
frs_candidates_pick(
conn, table_in, table_to, col_key,
exp_score = NULL, exp_filter = NULL, order_by
)
SQL: optional WITH scored AS (SELECT *, (<exp_score>) AS score
FROM <table_in>) CTE when exp_score supplied; SELECT DISTINCT ON
(<col_key>) * FROM (scored | table_in); optional WHERE <exp_filter>;
ORDER BY <col_key>, <caller's order_by clauses>. col_key prepended
to order_by to satisfy PostgreSQL DISTINCT ON requirement.
Reserved-column collision check on `score` when exp_score is set.
RPostgres can't run multi-statement SQL, so DROP and CREATE split
into separate .frs_db_execute calls.
Reuses fresh helpers: .frs_validate_identifier, .frs_db_execute,
.frs_table_columns. Mirrors frs_point_match scaffold structure
end-to-end.
Roxygen cross-refs frs_network_features and frs_point_match
(siblings in @family network) regenerated.
Lint clean; load_all signature verified.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
tests/testthat/test-frs_candidates_pick.R mirrors the test-frs_point_match
three-tier structure:
Tier 1 -- validation (7 tests): required args (table_in, table_to,
col_key, order_by); .frs_validate_identifier rejection for bad
identifiers; exp_score / exp_filter must be non-empty character
when supplied.
Tier 2 -- SQL composition via local_mocked_bindings on
.frs_db_execute + .frs_table_columns (5 tests):
- full path: DROP, CREATE, WITH scored CTE, exp_score inline, DISTINCT
ON (col_key), WHERE exp_filter, ORDER BY col_key + caller's clauses
- exp_score=NULL omits WITH scored CTE
- exp_filter=NULL omits WHERE clause
- reserved-column collision: rejects table_in with `score` column
when exp_score is set
- existing `score` column allowed when exp_score is NULL (caller
references it in order_by directly)
Total: 25 PASS / 0 FAIL on filter=frs_candidates_pick.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Validated frs_candidates_pick against bcfp's PSCIS-to-stream dedup
step using bcfp's pre-computed pscis_streams_150m as input (where
bcfp has already applied modelled-side dedup + computed name_score,
width_order_score, weighted_distance per 04_pscis.sql).
Acceptance: 102 / 102 ref picks identical, 0 missing.
ours: 106 picks | ref: 102 picks
identical pairs: 102
only in ours: 4 (all in bcfishpass.pscis_not_matched_to_streams --
bcfp's downstream suspect_match >50m filter routes
these to a separate "not matched" table; that filter
is caller-level, not primitive-level)
only in ref: 0
The dedup step is BYTE-IDENTICAL. The 4 "extras" are bcfp's downstream
routing logic that doesn't belong in this primitive.
Closes the BULK 5-diff gap from fresh#206 -- the snap-layer divergence
that fresh#206 documented as "needs frs_candidates_pick" is now
resolved at the dedup-step level. link#154 will compose
frs_point_snap(num_features=N) + frs_candidates_pick + frs_point_match
to reproduce the full bcfp PSCIS-build pipeline byte-identically (with
optional caller-level suspect_match filter on top for full
pscis-vs-pscis_not_matched routing).
Validation script: /tmp/fresh_207_live_validation.R
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
DESCRIPTION 0.30.0 -> 0.31.0 (minor bump per R-package conventions for new exported function). NEWS.md 0.31.0 entry covers: - generic over any score+filter+dedup-per-key workflow - BULK byte-identical (102/102 ref picks identical, 0 missing) - table_/col_/exp_<role> convention compliance - 3-step composition story (frs_point_snap + frs_candidates_pick + frs_point_match) that reproduces bcfp PSCIS pipeline byte-identically - first consumer link#154 R CMD check (--no-tests): 0 errors / 4 warnings / 4 notes -- identical to main per side-by-side check (same as v0.30.0 baseline). lintr clean on the new R file. 25 PASS / 0 FAIL on filter=frs_candidates_pick. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Closes #207. Ships
frs_candidates_pick()— fourth primitive in fresh's point-handling family (alongsidefrs_point_snap,frs_network_features,frs_point_match). Given a candidates table where multiple rows can share the same key, optionally score per row via a caller-supplied SQL expression, optionally filter via a caller-supplied WHERE clause, then keep one row per key viaDISTINCT ON (col_key) ORDER BY ....table_<role>/col_<role>/exp_<role>conventions (link/CLAUDE.md):Live byte-identical parity vs bcfp
BULK PSCIS-to-stream selection: 102 / 102 ref picks identical, 0 missing. Closes the BULK 5-diff gap from fresh#206 at the dedup-step level.
Approach: stage
bcfishpass.pscis_streams_150m(bcfp's pre-computed candidates with name_score, width_order_score, weighted_distance, multiple_match_ind) as input, callfrs_candidates_pickwith bcfp's exact filter + ORDER BY:Diff vs
bcfishpass.pscis(xref-excluded subset):ours 106 / ref 102 / identical 102 / only-ours 4 / only-ref 0. The 4 "extras" all live inbcfishpass.pscis_not_matched_to_streams— bcfp's downstreamsuspect_matchfilter (>50m distance) routes those to a separate table. That's a caller-level downstream filter, not a primitive responsibility.Test plan
exp_*non-empty character, reserved-column collision whenexp_scoreset, existing-score-column-allowed-when-exp_score-NULL edge case) and SQL composition (DROP + CREATE,WITH scored ASCTE present/absent,SELECT DISTINCT ON (col_key),WHEREpresent/absent, ORDER BY containing col_key first then caller's clauses).R CMD check --no-tests: 0 errors / 4 warnings / 4 notes — identical to main.lintr::lint("R/frs_candidates_pick.R"): zero lints.Composition story
With #206 + #207 shipped, the bcfp PSCIS-build pipeline reproduces byte-identically via composition:
This three-step chain is exactly what link#154 wires into
lnk_pipeline_crossingsto close the BULK mapping_code parity gap.🤖 Generated with Claude Code