Skip to content

fix(core): add quotes for the model subquery alias#1283

Merged
douenergy merged 2 commits intoCanner:mainfrom
goldmedal:fix/rlac-case-sensitive
Aug 15, 2025
Merged

fix(core): add quotes for the model subquery alias#1283
douenergy merged 2 commits intoCanner:mainfrom
goldmedal:fix/rlac-case-sensitive

Conversation

@goldmedal
Copy link
Copy Markdown
Contributor

@goldmedal goldmedal commented Aug 14, 2025

I missed to add quotes for the alias of the model subquery. It causes some case-sensitive issues.

Summary by CodeRabbit

  • New Features

    • Improved support for Unicode model and column names in generated SQL.
  • Bug Fixes

    • Model aliases are now properly quoted to handle special or non-ASCII characters.
    • More reliable combination and application of row-level access filters in query generation.
  • Tests

    • Added and adjusted tests covering Unicode identifiers, row-level access control, and related behavior.

@github-actions github-actions bot added core rust Pull requests that update Rust code labels Aug 14, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 14, 2025

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 2c7abed and b3f2272.

📒 Files selected for processing (3)
  • wren-core/core/src/logical_plan/analyze/model_generation.rs (1 hunks)
  • wren-core/core/src/mdl/function.rs (2 hunks)
  • wren-core/core/src/mdl/mod.rs (1 hunks)
 _______________________________________________________________________________________________________________
< Make quality a requirements issue. Involve your users in determining the project's real quality requirements. >
 ---------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

Walkthrough

Updated a lifetime annotation on quote_identifier, adjusted RLAC filter reduction and alias quoting in model generation, added a Unicode-focused RLAC unit test, and replaced a test clone with a borrowed reference in function tests. No public API semantics changed.

Changes

Cohort / File(s) Summary
Identifier quoting
wren-core-base/src/mdl/utils.rs
Signature change: quote_identifier now returns Cow<'_, str> (explicit lifetime); function body unchanged.
RLAC reduction & aliasing
wren-core/core/src/logical_plan/analyze/model_generation.rs
Rewrote RLAC filter reduction to use pattern matching; apply alias(quoted(model_plan.plan_name()))? when attaching alias; minor control-flow refactor for an error expression.
Tests: Unicode RLAC
wren-core/core/src/mdl/mod.rs
Added test_rlac_unicode_model_column_name to validate RLAC behavior with Unicode model/column names and proper quoting/aliasing in Unparse mode.
Tests: avoid clone
wren-core/core/src/mdl/function.rs
Test update: use std::slice::from_ref(&list_type) instead of &[list_type.clone()] to avoid cloning in the test setup.

Sequence Diagram(s)

sequenceDiagram
  participant Analyzer
  participant ModelGen
  participant Quoter as IdentifierQuoter
  participant Planner

  Analyzer->>ModelGen: analyze(manifest, Unparse)
  ModelGen->>ModelGen: reduce RLAC filters (pattern match)
  ModelGen->>Quoter: quoted(model_plan.plan_name())
  Quoter-->>ModelGen: quoted alias
  ModelGen->>Planner: build plan with alias + RLAC
  Planner-->>Analyzer: transformed plan/SQL
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • douenergy

Poem

A rabbit taps code with a gentle hop,
Quoting names that never stop.
Filters weave through Unicode light,
Aliases snug, everything right.
Hop on—tests pass by moonlight. 🐇✨

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
wren-core/core/src/mdl/mod.rs (1)

2526-2564: Great addition: Unicode RLAC coverage with quoted model alias

This test validates the intended behavior: model subquery alias is quoted and Unicode identifiers are preserved and qualified in the RLAC filter. Nicely scoped and aligned with the PR goal.

Consider adding a companion test where the model name contains a double quote to ensure escaping works as expected end-to-end. For example, a model named VTU"藝人 and asserting the final SQL remains valid after quoting and escaping.

wren-core/core/src/logical_plan/analyze/model_generation.rs (1)

100-111: Simplify filter reduction for clarity and fewer branches

Current reduction nests two if-let blocks. You can achieve the same behavior more readably by flattening first and then reducing Expr directly.

Apply this diff:

-                    let rls_filter = filters
-                        .into_iter()
-                        .reduce(|acc, filter| {
-                            if let Some(acc) = acc {
-                                if let Some(filter) = filter {
-                                    Some(acc.and(filter))
-                                } else {
-                                    Some(acc)
-                                }
-                            } else {
-                                filter
-                            }
-                        })
-                        .flatten();
+                    let rls_filter = filters
+                        .into_iter()
+                        .flatten()
+                        .reduce(|acc, filter| acc.and(filter));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ffaa7f and 1098bc2.

📒 Files selected for processing (3)
  • wren-core-base/src/mdl/utils.rs (1 hunks)
  • wren-core/core/src/logical_plan/analyze/model_generation.rs (3 hunks)
  • wren-core/core/src/mdl/mod.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
wren-core/core/src/mdl/mod.rs (4)
wren-core/core/src/mdl/context.rs (1)
  • new (339-361)
wren-core/core/src/logical_plan/analyze/model_anlayze.rs (2)
  • new (74-84)
  • analyze (47-66)
wren-core-base/src/mdl/builder.rs (1)
  • new_required (177-183)
wren-core/core/src/logical_plan/analyze/access_control.rs (1)
  • build_headers (563-571)
wren-core/core/src/logical_plan/analyze/model_generation.rs (1)
wren-core/core/src/mdl/utils.rs (1)
  • quoted (209-211)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: cargo test (macos)
  • GitHub Check: cargo test (macos-aarch64)
  • GitHub Check: cargo check
  • GitHub Check: cargo test (win64)
  • GitHub Check: test
  • GitHub Check: ci
🔇 Additional comments (2)
wren-core-base/src/mdl/utils.rs (1)

46-52: Explicit lifetime on Cow is correct and harmless

Making the lifetime explicit as Cow<'_, str> is idiomatic and keeps the function signature precise without changing behavior. Call sites that rely on type inference remain unaffected.

wren-core/core/src/logical_plan/analyze/model_generation.rs (1)

237-238: Non-early return error style is fine

Returning plan_err!("...") as the tail expression maintains behavior and keeps the control flow consistent. No issues here.

@goldmedal goldmedal force-pushed the fix/rlac-case-sensitive branch from 2c7abed to b3f2272 Compare August 14, 2025 06:20
@douenergy
Copy link
Copy Markdown
Contributor

Thanks @goldmedal

@douenergy douenergy merged commit 2f722ad into Canner:main Aug 15, 2025
12 of 13 checks passed
nhaluc1005 pushed a commit to nhaluc1005/text2sql-practice that referenced this pull request Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants