fix(core): ensure that the RLAC can be applied when the relationship access
Description
This PR fixes the issue that the RLAC won't be applied when the relationship accesses the model. For example:
- Given a model
orderswith the columncustomer_namewhich points to the columnnamein another modelcustomerthrough the relationship. - If
customerhas the RLAC rules, the SQL trying to queryorders.customer_nameshould also apply the RLAC rules for the modelcustomer.
Changed
Because we apply the RLAC in ModelPlanNode, we can reuse the logic for the relationship accessing. Previously, we built the to-one relationship access through ModelSourceNode that won't be applied RLAC.
This PR will build PartialModelPlanNode instead of ModelSourceNode for the relationship accessing to ensure the RLAC can be used.
Summary by CodeRabbit
Summary by CodeRabbit
-
Bug Fixes
- Improved handling of required fields for partial models, ensuring correct application of row-level access control (RLAC) rules across related models and calculated fields.
- Enhanced error handling during model plan construction.
- Simplified model plan construction logic by unifying plan node creation for model targets.
-
Tests
- Added comprehensive tests to verify RLAC rule application on both base and related models, especially when using calculated fields and relationships.
- Updated test snapshots for better readability.
-
Chores
- Updated workflow to set a specific environment variable when running Rust tests on multiple platforms.
Walkthrough
The changes refine the handling of required fields and partial model plans in the logical plan analysis, separating the collection of calculated and non-calculated fields for partial models. The control flow for building partial model nodes is unified, and error handling is improved. Test code is updated to use clearer manifest definitions and verifies row-level access control in more complex model relationships. The Rust workflow is also updated to set a stack size environment variable during tests.
Changes
| Files/Paths | Change Summary |
|---|---|
| .github/workflows/rust.yml | Modified the Rust test workflow to set RUST_MIN_STACK=8388608 before running cargo test, ensuring a specific stack size during tests across platforms. |
| wren-core/core/src/logical_plan/analyze/plan.rs | Refactored required field collection: split into separate functions for calculated and non-calculated fields, renamed and updated function signatures, improved error propagation, and adjusted control flow to distinctly handle both field types during model plan building. Minor formatting adjustments included. |
| wren-core/core/src/logical_plan/analyze/relation_chain.rs | Simplified the logic for building model target nodes in relation chains: always wraps a ModelPlanNode in a PartialModelPlanNode, removing conditional logic based on calculated columns. |
| wren-core/core/src/mdl/mod.rs | Updated test code: switched to raw string literals for SQL snapshots, replaced a commented test with an active test using a detailed manifest with two related models, calculated columns, and RLAC rules. The new test checks that RLAC filters are applied to both base and related models when transforming SQL involving calculated fields and relationships. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant ModelPlanNodeBuilder
participant Analyzer
participant PartialModelCollector
User->>ModelPlanNodeBuilder: build()
ModelPlanNodeBuilder->>Analyzer: collect_partial_model_plan_for_calculation()
Analyzer-->>ModelPlanNodeBuilder: (calculated fields)
ModelPlanNodeBuilder->>PartialModelCollector: collect_partial_model_required_fields()
PartialModelCollector-->>ModelPlanNodeBuilder: (non-calculated fields)
ModelPlanNodeBuilder->>Analyzer: collect_model_required_fields()
Analyzer-->>ModelPlanNodeBuilder: (all required fields)
ModelPlanNodeBuilder-->>User: ModelPlanNode
Suggested reviewers
- wwwy3y3
- douenergy
Poem
In the warren of code, we burrowed deep,
Dividing fields—calculated, plain, and neat.
Tests now prance with RLAC in tow,
While stack size grows for tests to flow.
Models relate, and rabbits cheer—
For clearer plans are finally here! 🐇✨
[!TIP]
⚡️ Faster reviews with caching
- CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure
Review - Disable Cacheat either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off theData Retentionsetting under your Organization Settings.Enjoy the performance boost—your workflow just got faster.
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between d2bde801c89bdd4e55c29c66c23c3ea80d6fed04 and a0b1dfb84abd56bfe443be7b7ee71f5ab168d6c7.
📒 Files selected for processing (2)
wren-core/core/src/logical_plan/analyze/plan.rs(7 hunks)wren-core/core/src/logical_plan/analyze/relation_chain.rs(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- wren-core/core/src/logical_plan/analyze/relation_chain.rs
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: cargo test (macos-aarch64)
- GitHub Check: cargo test (macos)
- GitHub Check: cargo test (win64)
- GitHub Check: cargo check
- GitHub Check: ci
- GitHub Check: test
🔇 Additional comments (4)
wren-core/core/src/logical_plan/analyze/plan.rs (4)
202-216: Code structure improvement: logical separation of field collection.The refactoring to split the field collection into separate functions improves code organization. The change creates a clear distinction between collecting calculated fields (
collect_partial_model_plan_for_calculation) and non-calculated fields (collect_partial_model_required_fields), which helps enforce RLAC properly when accessing related models.
560-600: Improved error handling in new function.The implementation of
collect_partial_model_required_fieldsproperly handles errors withok_or_elseinstead ofunwrap(), which is an improvement over previous patterns. This function is crucial for enforcing RLAC on related models by ensuring non-calculated fields are properly collected.
602-610: Better function interface for collecting required fields.The updated function signature with explicit
qualified_columnparameter makes the function interface clearer and aligns with the same pattern used in other field collection functions. The comments also clarify that it collects both calculated and non-calculated source columns depending on context.
10-11: Added import for better error handling.The addition of
internal_datafusion_errto the imports supports the improved error handling approach used in the refactored functions.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
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.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Thanks @goldmedal