Skip to content

feat(ibis): query cache with bigquery info #1167

Merged
goldmedal merged 3 commits intoCanner:mainfrom
douenergy:bigquery-query-cache
Apr 25, 2025
Merged

feat(ibis): query cache with bigquery info #1167
goldmedal merged 3 commits intoCanner:mainfrom
douenergy:bigquery-query-cache

Conversation

@douenergy
Copy link
Copy Markdown
Contributor

@douenergy douenergy commented Apr 25, 2025

We can support query cache from connection info using bigquery connection info.

Summary by CodeRabbit

  • New Features
    • Improved query caching support for BigQuery connections, ensuring cache keys are generated using relevant connection details.
  • Tests
    • Added tests to verify query caching behavior, including cache hits, cache overrides, and related response headers.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 25, 2025

Walkthrough

The _generate_cache_key method in QueryCacheManager was refactored to unify cache key construction by using a new to_key_string() method on connection info classes, replacing conditional logic for ConnectionUrl. A new base class BaseConnectionInfo was introduced with the to_key_string method, and all connection info classes now inherit from it. Two new asynchronous test functions were added in both v2 and v3 BigQuery connector test suites to verify query caching behavior and cache override functionality. No changes were made to public method signatures or other logic.

Changes

File(s) Change Summary
ibis-server/app/query_cache/init.py Refactored _generate_cache_key to use info.to_key_string() for generating cache key parts instead of conditional logic on ConnectionUrl. Removed import of ConnectionUrl. Cache key string concatenates data_source, sql, and info.to_key_string(). Debug log updated to output combined key string. No changes to public method signatures.
ibis-server/app/model/init.py Added new base class BaseConnectionInfo with method to_key_string() that concatenates secret values of all SecretStr fields. Changed all connection info classes, including ConnectionUrl, to inherit from BaseConnectionInfo instead of BaseModel. No other field or logic changes.
ibis-server/tests/routers/v2/connector/test_bigquery.py
ibis-server/tests/routers/v3/connector/bigquery/test_query.py
Added two async test functions in each file: test_query_with_cache to verify cache hit/miss behavior and test_query_with_cache_override to verify cache override functionality. Tests assert HTTP 200 status, cache-related headers, timestamps, and data type consistency for BigQuery queries. No modifications to existing tests or other logic.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant QueryCacheManager
    participant BigQuery

    Client->>API: POST /query?cacheEnable=true
    API->>QueryCacheManager: _generate_cache_key(info, sql)
    QueryCacheManager->>info: to_key_string()
    QueryCacheManager->>QueryCacheManager: Build cache key string
    API->>QueryCacheManager: Check cache for key
    alt Cache miss
        API->>BigQuery: Execute SQL query
        BigQuery-->>API: Return results
        API->>QueryCacheManager: Store results in cache
        API-->>Client: Return results with X-Cache-Hit: false
    else Cache hit
        API->>QueryCacheManager: Retrieve cached results
        API-->>Client: Return cached results with X-Cache-Hit: true
    end

    Client->>API: POST /query?cacheEnable=true&overrideCache=true
    API->>QueryCacheManager: Override cache and execute query
    API-->>Client: Return fresh results with X-Cache-Override: true
Loading

Possibly related PRs

Suggested reviewers

  • goldmedal

Poem

In the cachey warren, secrets now abound,
With keys combined, no branches confound.
Tests hop in to check if the cache is right—
Is it a hit, or a miss in the night?
Override the burrow, refresh with delight,
As rabbits ensure the cache is airtight!
🐇✨


📜 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 268e981 and 6e0bb43.

📒 Files selected for processing (1)
  • ibis-server/app/query_cache/__init__.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ibis-server/app/query_cache/init.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci
✨ 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.
    • 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 @coderabbitai in 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 @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 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.

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 bigquery ibis python Pull requests that update Python code labels Apr 25, 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 59b7c90 and 268e981.

📒 Files selected for processing (2)
  • ibis-server/app/model/__init__.py (14 hunks)
  • ibis-server/app/query_cache/__init__.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ibis-server/app/query_cache/init.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
ibis-server/app/model/__init__.py (1)
ibis-server/tests/routers/v3/connector/postgres/conftest.py (1)
  • connection_url (48-50)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci
🔇 Additional comments (3)
ibis-server/app/model/__init__.py (3)

17-27: Well-designed base class for unified connection key generation.

The new BaseConnectionInfo class provides a clean, unified way to generate cache keys from connection objects. The to_key_string() method smartly collects all SecretStr fields and joins them, which ensures consistent cache key generation across different connection types.


87-89: Appropriate inheritance for ConnectionUrl.

Moving ConnectionUrl to inherit from BaseConnectionInfo instead of directly from BaseModel ensures consistent cache key generation, which is crucial for the query caching mechanism introduced in this PR.


91-91: Consistent inheritance pattern across all connection classes.

All connection info classes now correctly inherit from BaseConnectionInfo, which establishes a consistent pattern and guarantees that the to_key_string() method is available for all connection types. This is essential for the query caching mechanism to work properly with any connection type.

Also applies to: 101-101, 120-120, 136-136, 161-161, 189-189, 205-205, 221-221, 241-241, 262-262, 271-271, 292-292, 318-318

Copy link
Copy Markdown
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

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

Thanks @douenergy 👍

@goldmedal goldmedal merged commit 4576d0d into Canner:main Apr 25, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bigquery ibis python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants