Skip to content

fix(core): fix RLAC for model with an alias#1245

Merged
douenergy merged 3 commits intoCanner:mainfrom
goldmedal:fix/1222-rlac-alias
Jul 8, 2025
Merged

fix(core): fix RLAC for model with an alias#1245
douenergy merged 3 commits intoCanner:mainfrom
goldmedal:fix/1222-rlac-alias

Conversation

@goldmedal
Copy link
Copy Markdown
Contributor

@goldmedal goldmedal commented Jul 4, 2025

DataFusion plan a filter in the subquery to the plan like

SELECT int_col, double_col FROM (SELECT int_col, double_col, CAST(date_string_col as VARCHAR) FROM alltypes_plain where int_col > 1) d
-----
Logical Plan: Projection: d.int_col, d.double_col
  SubqueryAlias: d
    Projection: alltypes_plain.int_col, alltypes_plain.double_col, CAST(alltypes_plain.date_string_col AS Utf8View)
      Filter: alltypes_plain.int_col > Int64(1)
        TableScan: alltypes_plain

We need to follow the pattern to build our custom plan for datafusion unparsing.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of row-level security (RLS) filters to ensure correct query generation and aliasing, aligning with expected SQL behavior.
  • Tests

    • Updated test snapshots to reflect changes in the structure of queries with RLS filters.
    • Added a new test to verify correct SQL generation for models with RLS filters and table aliases.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 4, 2025

Walkthrough

The changes update the logical plan generation for models with row-level security (RLS) filters by inserting a projection after the filter to align with DataFusion's planning behavior. Additionally, an asynchronous test is added to verify correct SQL transformation and alias handling when RLS is applied to models. Test snapshots in both Rust and Python are updated to reflect the new nested subquery structure for RLAC filters.

Changes

File(s) Change Summary
.../logical_plan/analyze/model_generation.rs Modified RLS logic: after applying the filter, a projection is inserted to select all columns by index.
.../mdl/mod.rs Updated RLAC test snapshots with additional nested subquery layer; added async test test_rlac_alias_model to verify SQL aliasing with RLAC.
wren-core-py/tests/test_modeling_core.py Updated test_rlac snapshot to reflect additional nested subquery layer in SQL after RLAC transformation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LogicalPlanBuilder
    participant RLSFilter
    participant Projection

    User->>LogicalPlanBuilder: Build model plan with RLS
    LogicalPlanBuilder->>RLSFilter: Apply RLS filter
    RLSFilter->>Projection: Insert projection selecting all columns
    Projection->>LogicalPlanBuilder: Return updated plan
Loading

Assessment against linked issues

Objective Addressed Explanation
Correct alias conversion in RLS conditions for models with row-level access control (#1222)
Ensure SQL transformation applies RLAC filters to aliased tables and preserves aliasing (#1222)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested reviewers

  • douenergy
  • wwwy3y3

Poem

A bunny hops through logic's maze,
With filters set and columns ablaze.
Aliases now dance in line,
Security rules enforced just fine.
Tests ensure the code is sound—
In wren’s core, solutions found!
🐇✨


📜 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 0d2e339 and 0c567cc.

📒 Files selected for processing (1)
  • wren-core-py/tests/test_modeling_core.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: goldmedal
PR: Canner/wren-engine#1161
File: ibis-server/app/routers/v3/connector.py:78-83
Timestamp: 2025-05-05T02:27:29.829Z
Learning: The row-level access control implementation in Wren Engine filters headers with the prefix `X_WREN_VARIABLE_PREFIX` in `EmbeddedEngineRewriter.get_session_properties` and validates session property expressions in `access_control.rs` to ensure they only contain literal values, preventing SQL injection.
Learnt from: goldmedal
PR: Canner/wren-engine#1161
File: wren-core/core/src/logical_plan/analyze/access_control.rs:0-0
Timestamp: 2025-04-30T01:18:21.776Z
Learning: In the `collect_condition` function of the row-level access control implementation, compound identifiers are intentionally ignored rather than causing failures when processing expressions. This is by design as confirmed by the team.
wren-core-py/tests/test_modeling_core.py (1)
Learnt from: goldmedal
PR: Canner/wren-engine#1161
File: ibis-server/app/routers/v3/connector.py:78-83
Timestamp: 2025-05-05T02:27:29.829Z
Learning: The row-level access control implementation in Wren Engine filters headers with the prefix `X_WREN_VARIABLE_PREFIX` in `EmbeddedEngineRewriter.get_session_properties` and validates session property expressions in `access_control.rs` to ensure they only contain literal values, preventing SQL injection.
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: cargo test (amd64)
  • GitHub Check: clippy
  • GitHub Check: check Cargo.toml formatting
  • GitHub Check: cargo test (macos)
  • GitHub Check: cargo test (macos-aarch64)
  • GitHub Check: cargo test (win64)
  • GitHub Check: ci
  • GitHub Check: test
🔇 Additional comments (1)
wren-core-py/tests/test_modeling_core.py (1)

318-318: Test update correctly reflects the core logic changes.

The updated expected SQL query structure properly reflects the new nested subquery behavior where an additional projection is inserted after applying the RLAC filter. This aligns with the changes in the core Rust logic that now insert a projection after the filter to match DataFusion's planning behavior, resulting in the deeper nesting structure observed in the test assertion.

✨ 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.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 explain its main purpose.
    • @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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

@github-actions github-actions bot added core rust Pull requests that update Rust code labels Jul 4, 2025
@github-actions github-actions bot added the python Pull requests that update Python code label Jul 4, 2025
@goldmedal goldmedal requested a review from douenergy July 4, 2025 06:56
@douenergy douenergy merged commit d58efb2 into Canner:main Jul 8, 2025
15 checks passed
@douenergy
Copy link
Copy Markdown
Contributor

Thanks @goldmedal

@goldmedal goldmedal deleted the fix/1222-rlac-alias branch July 8, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core python Pull requests that update Python code rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alias is not converted when row level access control is configured

2 participants