Skip to content

feat(sql-plan): composite/instance-bound joins, aggregate_source, deterministic emission, final_dedup latest - #22

Merged
dmautz1 merged 9 commits into
DocumentDrivenDX:mainfrom
dmautz1:feat/sql-plan-composite-stack
Aug 31, 2026
Merged

dmautz1 merged 9 commits into
DocumentDrivenDX:mainfrom
dmautz1:feat/sql-plan-composite-stack

Conversation

@dmautz1

@dmautz1 dmautz1 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Completes the production sql-plan port on top of #18/#19 — this is the remainder of the fork stack a production deployment currently pins (0320fe6), rebased onto main and restructured for review.

Features

  • Composite join_conditions (AND-ed column/expression equalities) + join_type: full_outer, which forces the direct strategy regardless of cardinality notation
  • Instance-bound relationships: table_instance binds a relationship to one named instance, so the same table joins twice under different keys (rule-table pattern)
  • base_table_strategy: aggregate_source — the GROUP BY is the table (third leg of the aggregate story)
  • final_dedup: latest — declared-grain QUALIFY ROW_NUMBER() = 1 at final assembly with final_dedup_keys / final_dedup_order_by; rows with a NULL dedup key pass through undeduplicated

Fixes

  • One squashed commit of six physical-name / prefixed-ref consistency fixes in the column-requirement attribution pass (~135 lines)
  • Deterministic emission: intermediate-required base columns are sorted so plan bytes don't follow the process hash seed (protects the zero-drift regenerate-and-diff KPI) — now with a regression test
  • Pyright narrowing for the physical-name canonical-column helper

Docs

  • FEAT-019 scope evidence extended with the relationship-driven plan-composition capabilities; registry row refreshed

Full local gate passes: format-check, lint, type-check, 3854 tests including DuckDB/Spark conformance.

🤖 Generated with Claude Code

dmautz1 and others added 9 commits August 31, 2026 13:27
join_conditions on OutgoingRelationship append AND-ed equalities to the
direct-join ON clause (each side a plain column or an expression,
rewritten like the primary key pair: base side against the accumulated
view, target side against the joined table; referenced base columns
reach the base view). join_type gains 'full_outer' — emitted as FULL
OUTER JOIN and forcing the direct strategy (fan-out preserved on both
sides) regardless of cardinality notation. Direct joins only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
table_instance on OutgoingRelationship binds the relationship to a single
named instance: each bound relationship supplies its own join keys/
conditions, so the same table can join twice under different aliases
(rule-table pattern: det_any keyed on determination, det_triple keyed on
the stage/status/reason triple). Unbound relationships keep applying to
every candidate-declared instance.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…table

base_table_strategy: aggregate_source emits disposition_base as a GROUP BY
over base_table: plain candidates form the group key(s), expression
candidates (aggregates — SUM/MIN_BY/…) project under their target physical
names, and final assembly passes everything through. The third leg of the
aggregate story (side-agg join, pre-agg views, now aggregation-native).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…equirement attribution

Squash of six small fixes to the base-view / join-projection column
requirement pass:

- prefixed intermediate refs (alias__col) reach the join projection,
  attributed to the real table (673a911)
- a leading-underscore canonical_name emits the physical column; final
  assembly aliases with it, matching the DDL exporter (3ebb131)
- prefixed-ref attribution runs for every expression, not only when the
  candidate lacks a plain column (96292a5)
- tables referenced only via prefixed refs keep their join (72fb62c)
- _get_table_columns returns physical names so base view, join
  projections, requirement matching, and expression rewriting agree (6e450b1)
- intermediate-referenced base columns reach the base view (edae7b6)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…tic output

_required_columns holds sets; iterating one directly leaked the process
hash seed into the base view's emitted column order, flipping plan bytes
between runs (observed: EntryDt/ID swap in a downstream consumer's
silver_service_line_billing plan). Byte-stable output is required for
regenerate-and-diff commit gates over checked-in generated SQL.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…at final assembly

Extends metadata.final_dedup with a keyed variant: QUALIFY ROW_NUMBER()
OVER (PARTITION BY final_dedup_keys ORDER BY final_dedup_order_by) = 1
wrapped around the final assembly (composes with final_filter). Rows with
a NULL in any dedup key pass through undeduplicated — identity cannot be
asserted without a key, and PARTITION BY would otherwise collapse ALL
null-key rows into one survivor. New metadata fields: final_dedup_keys
(defaults to primary_key) and final_dedup_order_by (required).

Motivation: grain contracts on conformed silver feeds — enforce 'one row
per declared key' at the table that owns the grain instead of bolting
dedupe CTEs onto every consumer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Records the sql-plan capabilities ported from production (PRs DocumentDrivenDX#18/DocumentDrivenDX#19 and
the composite stack) as source-backed scope evidence on FEAT-019, and
refreshes the registry row.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dmautz1
dmautz1 merged commit c3425d8 into DocumentDrivenDX:main Aug 31, 2026
2 checks passed
@dmautz1
dmautz1 deleted the feat/sql-plan-composite-stack branch August 31, 2026 20:20
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