Skip to content

fix(core): fix count statement for BigQuery#1274

Merged
douenergy merged 2 commits intoCanner:mainfrom
goldmedal:fix/bigquery-count
Jul 30, 2025
Merged

fix(core): fix count statement for BigQuery#1274
douenergy merged 2 commits intoCanner:mainfrom
goldmedal:fix/bigquery-count

Conversation

@goldmedal
Copy link
Copy Markdown
Contributor

@goldmedal goldmedal commented Jul 29, 2025

Description

We fixed the alias name of BigQuery in Canner/datafusion#1
However, we didn't apply it in our inner dialect.

Summary by CodeRabbit

  • New Features

    • Improved support for BigQuery by handling column aliases with special characters, ensuring compatibility with BigQuery's naming requirements.
    • Added a new test to verify row count queries on BigQuery data sources, confirming accurate results and data types.
  • Bug Fixes

    • Minor cleanup of test case comments for clarity.
    • Updated SQL transformation output for BigQuery to reflect new alias encoding style.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 29, 2025

Walkthrough

A new test for counting rows in the BigQuery connector was added. The BigQuery dialect now includes logic to override column aliases containing unsupported special characters, encoding them for compatibility. The Wren dialect delegates alias override logic to its inner dialect. Minor comment removals were made in the test file. A test snapshot was updated to reflect alias mangling in SQL output.

Changes

Cohort / File(s) Change Summary
BigQuery Connector Test Enhancements
ibis-server/tests/routers/v3/connector/bigquery/test_query.py
Added a test for counting rows via BigQuery; updated manifest with dataSource; removed minor comments in test cases.
BigQuery Dialect Alias Override
wren-core/core/src/mdl/dialect/inner_dialect.rs
Added col_alias_overrides method to InnerDialect trait; implemented in BigQueryDialect to encode special characters in aliases.
Wren Dialect Delegation
wren-core/core/src/mdl/dialect/wren_dialect.rs
Added col_alias_overrides method to WrenDialect, delegating to its inner dialect.
Test Snapshot Update
wren-core/core/src/mdl/mod.rs
Updated expected SQL snapshot in test_unnest_as_table_factor to reflect mangled alias formatting for BigQuery dialect.

Sequence Diagram(s)

sequenceDiagram
    participant Test as test_count
    participant Client as BigQuery Client
    participant API as /query endpoint
    participant DB as BigQuery

    Test->>API: POST /query (count rows in orders)
    API->>Client: Prepare SQL with column aliases
    Client->>DB: Execute query
    DB-->>Client: Return result
    Client-->>API: Response with row count
    API-->>Test: Response (status 200, count = 15000)
Loading
sequenceDiagram
    participant User as User Code
    participant Wren as WrenDialect
    participant Inner as InnerDialect (BigQueryDialect)

    User->>Wren: col_alias_overrides(alias)
    Wren->>Inner: col_alias_overrides(alias)
    Inner-->>Wren: Encoded or unchanged alias
    Wren-->>User: Result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

bigquery

Poem

A dialect hops with careful cheer,
Encoding names for BigQuery to hear.
Tests count rows with bunny delight,
Ensuring aliases are handled right.
Through Rusty fields and SQL streams,
This code now works just like our dreams!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 39e9078 and 5c53bc1.

📒 Files selected for processing (1)
  • wren-core/core/src/mdl/mod.rs (1 hunks)
⏰ 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: ci
  • GitHub Check: cargo test (macos-aarch64)
  • GitHub Check: cargo check
  • GitHub Check: cargo test (macos)
  • GitHub Check: cargo test (win64)
  • GitHub Check: test
🔇 Additional comments (1)
wren-core/core/src/mdl/mod.rs (1)

1192-1192: LGTM! Test snapshot correctly updated for BigQuery dialect changes.

This snapshot update properly reflects the new BigQuery alias mangling behavior where special characters in identifiers are encoded (e.g., (_40, )_41, ,_44) to comply with BigQuery's identifier restrictions. The change aligns perfectly with the PR objective of fixing BigQuery alias handling.

✨ 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.
    • 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 generate unit tests to generate unit tests for 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 ibis rust Pull requests that update Rust code python Pull requests that update Python code labels Jul 29, 2025
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: 0

🧹 Nitpick comments (1)
wren-core/core/src/mdl/dialect/inner_dialect.rs (1)

97-118: Improve efficiency by avoiding unnecessary string allocation.

The implementation correctly handles BigQuery's special character restrictions, but there's a minor inefficiency on line 116 where alias.to_string() is called even when no transformation is needed.

Apply this diff to avoid unnecessary allocation:

        if alias.chars().any(|c| special_chars.contains(&c)) {
            let mut encoded_name = String::new();
            for c in alias.chars() {
                if special_chars.contains(&c) {
                    encoded_name.push_str(&format!("_{}", c as u32));
                } else {
                    encoded_name.push(c);
                }
            }
            Ok(Some(encoded_name))
        } else {
-            Ok(Some(alias.to_string()))
+            Ok(None)
        }

This change aligns with the trait's design where None indicates no override is needed, avoiding the allocation when the original alias is acceptable.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e8d92f4 and 39e9078.

📒 Files selected for processing (3)
  • ibis-server/tests/routers/v3/connector/bigquery/test_query.py (4 hunks)
  • wren-core/core/src/mdl/dialect/inner_dialect.rs (2 hunks)
  • wren-core/core/src/mdl/dialect/wren_dialect.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
ibis-server/tests/routers/v3/connector/bigquery/test_query.py (1)

Learnt from: goldmedal
PR: #1029
File: ibis-server/app/model/metadata/object_storage.py:44-44
Timestamp: 2025-01-07T03:56:21.741Z
Learning: When working with DuckDB in Python, use conn.execute("DESCRIBE SELECT * FROM table").fetchall() to get column types instead of accessing DataFrame-style attributes like dtype or dtypes.

⏰ 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 check
  • GitHub Check: cargo test (macos)
  • GitHub Check: cargo test (win64)
  • GitHub Check: ci
  • GitHub Check: cargo test (macos-aarch64)
  • GitHub Check: test
🔇 Additional comments (5)
wren-core/core/src/mdl/dialect/inner_dialect.rs (1)

52-54: LGTM! Well-designed trait extension.

The addition of col_alias_overrides method to the InnerDialect trait follows good design principles with a sensible default implementation returning Ok(None).

wren-core/core/src/mdl/dialect/wren_dialect.rs (1)

95-97: LGTM! Consistent delegation pattern.

The delegation to the inner dialect follows the established pattern used by other methods in this implementation, maintaining clean separation of concerns.

ibis-server/tests/routers/v3/connector/bigquery/test_query.py (3)

13-13: LGTM! Appropriate manifest configuration.

Adding the BigQuery data source specification ensures the correct dialect handling for these tests.


363-363: LGTM! Clean header specification.

The removal of extraneous comments leaves clean, focused header configuration.

Also applies to: 381-381


392-410: LGTM! Excellent validation of alias encoding.

The test effectively validates the BigQuery column alias encoding functionality. The expected column name "count_40_42_41" correctly represents the encoded form of "count(*)" where:

  • (_40
  • *_42
  • )_41

This confirms the special character encoding logic is working as intended.

@goldmedal goldmedal requested a review from douenergy July 29, 2025 09:34
@douenergy douenergy merged commit 2d9bbd2 into Canner:main Jul 30, 2025
15 checks passed
@douenergy
Copy link
Copy Markdown
Contributor

Thanks @goldmedal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core ibis 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.

2 participants