feat(wren-core): RLAC subqueries on MDL models + to-many calc on non-PK column#2335
feat(wren-core): RLAC subqueries on MDL models + to-many calc on non-PK column#2335goldmedal wants to merge 2 commits into
Conversation
Materialize the source model's primary key when building a TO-MANY calculated field, so the calculated subquery can be joined back even when the relationship is keyed on a non-PK column (e.g. `customer.mock_id = whitelist.mock_id`). Also use physical columns (instead of visible columns) in `Lineage` and the `WrenMDL` symbol table so hidden calculated columns participate in lineage and qualified-name resolution. This lets hidden RLAC helper fields be referenced inside RLAC expressions while remaining non-selectable by users. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
RLAC conditions can now reference other Wren models via subqueries, e.g. `c_custkey IN (SELECT allowed_id FROM allowed WHERE allowed_user = @session_user)`. - A new `RlacContextProvider` resolves table references to MDL models during expression parsing. The default `SessionState::create_logical_expr` builds a context provider with an empty table map and never consults the catalog, so previously any table reference inside an RLAC condition failed with "table not found". - RLAC parsing moves from `ModelGenerationRule` to `ModelAnalyzeRule`. The pre-parsed filter is carried on `ModelPlanNode::rlac_filter` and exposed via `expressions()`, so the analyzer's subquery traversal rewrites inner `TableScan`s into `ModelPlanNode`s — the referenced models' own RLAC/CLAC and remote table mapping apply transitively. - Cycle detection via a shared `building_models` stack on `ModelAnalyzeRule`: A↔B and self-referential RLAC now report a planning error instead of looping. - `collect_condition` skips bare identifiers inside subqueries (they belong to a different scope) while still collecting `@property` references everywhere. - `extract_models` keeps models referenced solely by another model's RLAC subquery condition, recursively, so manifest extraction doesn't trim them. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
WalkthroughExtended row-level access control to parse and rewrite subqueries referencing other MDL models with cycle detection. Refactored RLAC filter computation to occur once during model analysis, storing the filter on ChangesRLAC Subquery Support with Cycle Detection
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Two related improvements to the wren-core access-control / calculated-field machinery, backported as two commits:
1.
fix(wren-core): to-many calculated field joined on a non-PK columncustomer.mock_id = whitelist.mock_id).Lineageand theWrenMDLsymbol table so hidden calculated columns participate in lineage / qualified-name resolution — enabling hidden RLAC helper fields that are usable inside RLAC expressions yet non-selectable by users.2.
feat(wren-core): RLAC conditions may use subqueries on MDL modelsc_custkey IN (SELECT allowed_id FROM allowed WHERE allowed_user = @session_user).RlacContextProviderresolves table references to MDL models during expression parsing. The defaultSessionState::create_logical_expruses an empty table map and never consults the catalog, so such references previously failed with table not found.ModelGenerationRuletoModelAnalyzeRule. The pre-parsed filter is carried onModelPlanNode::rlac_filterand exposed viaexpressions(), so the analyzer's subquery traversal rewrites innerTableScans intoModelPlanNodes — referenced models' own RLAC/CLAC and remote-table mapping apply transitively.building_modelsstack: A↔B and self-referential RLAC now report a planning error instead of looping.collect_conditionskips bare identifiers inside subqueries (different scope) while still collecting@propertyreferences everywhere.extract_models(wren-core-py) keeps a model referenced solely by another model's RLAC subquery condition, recursively (multi-hop chains).Test plan
cargo test --lib --tests --binsundercore/wren-core— 140 passed; sqllogictest (view/tpch/type/model) greencargo test --no-default-featuresundercore/wren-core-py— 31 passed, incl. new 3-hop RLAC-chain extraction casescargo fmt --all+cargo clippy --all-targets --all-features -- -D warningsclean (both crates)test_to_many_calculate_join_with_normal_column,test_rlac_on_to_many_calculated_field,test_rlac_on_to_many_hidden_calculated_field,test_rlac_with_cross_model_subquery,test_rlac_subquery_applies_inner_rlac,test_rlac_subquery_cycle_detected,test_rlac_self_reference_is_cycle🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Improvements