Skip to content

Extract the per-chromosome dynamic-SQL IEJoin machinery into a shared helper — Closes #217#218

Merged
conradbzura merged 1 commit into
releasefrom
217-per-chrom-helper
Jul 9, 2026
Merged

Extract the per-chromosome dynamic-SQL IEJoin machinery into a shared helper — Closes #217#218
conradbzura merged 1 commit into
releasefrom
217-per-chrom-helper

Conversation

@conradbzura

Copy link
Copy Markdown
Collaborator

Summary

The DuckDB per-chromosome dynamic-SQL scaffolding — build a string_agg over the distinct chromosomes into a SET VARIABLE __giql_..._<token> = COALESCE((...), '<empty schema>'), then read it back via query(getvariable(...)) — lived privately inside IntersectsDuckDBIEJoinTransformer. It's the mechanism that routes a range join through DuckDB's IE_JOIN by removing the low-cardinality chrom equality per partition, and two more operators need it: DISJOIN's breakpoint join (#216) and NEAREST's k-nearest sweep.

This extracts the target-agnostic pieces into a new giql/expanders/_per_chrom.py: the CHROM_LITERAL interpolation constant, new_variable_name, set_variable_statement, and dynamic_relation. The operator-specific parts (the per-chromosome SQL template, the partition source, the empty-schema fallback, and the outer projection) stay with each expander. intersects_duckdb.py is refactored to use the helper.

This is a pure refactor: the emitted SQL is byte-identical (all SQL-shape test assertions pass unchanged), so there is no behavior change. DISJOIN (#216) and NEAREST then reuse the same helper instead of duplicating the scaffolding.

Closes #217

Proposed changes

  • refactor — Add giql/expanders/_per_chrom.py (CHROM_LITERAL, sql_escape, new_variable_name, set_variable_statement, dynamic_relation) and rewrite the SET VARIABLE / getvariable construction in intersects_duckdb.py to call it.

No test changes are needed — the full non-integration suite (1031 passed) stays green with the byte-identical SQL, which is the correctness check for this refactor.

https://claude.ai/code/session_01TERWBHov76DQM3nQeT8yyy

…red helper

The DuckDB per-chromosome dynamic-SQL machinery -- the chromosome
string-literal interpolation, the collision-resistant session-variable
name, the SET VARIABLE ... = COALESCE((string_agg per chromosome), empty)
builder, and the query(getvariable(...)) relation reference -- moves from
IntersectsDuckDBIEJoinTransformer into a new giql.expanders._per_chrom
module. The operator-specific parts (the per-chromosome SQL template, the
partition source, the empty-schema fallback, and the outer projection)
stay in the expander. Emitted SQL is byte-identical (no behavior change),
readying the scaffolding for reuse by DISJOIN (#216) and NEAREST.

Claude-Session: https://claude.ai/code/session_01TERWBHov76DQM3nQeT8yyy
@conradbzura conradbzura self-assigned this Jul 9, 2026
@conradbzura conradbzura marked this pull request as ready for review July 9, 2026 14:57
@conradbzura conradbzura merged commit eee36a0 into release Jul 9, 2026
3 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.

Extract the per-chromosome dynamic-SQL IEJoin machinery into a shared helper

1 participant