feat: detect self-referencing targets across pipeline statements#61
Merged
Conversation
When a multi-statement pipeline writes and reads the same table (e.g., SCD2 MERGE + INSERT on dim_customer), clgraph previously collapsed both references into a single node, losing the self-read semantic. This adds self-read node detection via AST node identity, cycle-safe dependency resolution, query-scoped self-read naming, column-granular cross-query wiring, and edge role/order annotations. Covers MERGE+INSERT, DELETE+INSERT, and single-statement INSERT...FROM self patterns. Closes Gap 4 from the CDC/SCD pipeline gap analysis.
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
dim_customer), clgraph now creates query-scoped self-read nodes instead of collapsing both references onto a single node_build_query_dependenciesand_build_table_dependenciesexclude self-dependencies, preventing topological sort cyclesedge_roleandstatement_orderannotations on all edgesINSERT INTO t SELECT ... FROM t, aliased self-referencesCloses Gap 4 from the CDC/SCD pipeline gap analysis (
docs/superpowers/specs/2026-04-13-gap4-self-referencing-target-design.md).Files Changed
models.pyDELETEtoSQLOperation,self_referenced_tables/self_ref_aliasestoParsedQuery,statement_order/edge_roletoColumnEdgemulti_query.py_extract_source_tablesto use AST node identity for target-slot detection; addedexp.Deletehandlingtable.py_build_query_dependenciesand_build_table_dependenciespipeline_lineage_builder.py_is_self_read_columnhelper,_add_self_read_cross_query_edgesmethod, edge annotationspipeline.pyget_self_read_columns(), fixedget_column()to prefer output layertest_cdc_scd_pipeline.pyTest plan
tests/test_cdc_scd_pipeline.py)