wren-engine icon indicating copy to clipboard operation
wren-engine copied to clipboard

chore(tool): add Postgres data source for the local run script

Open goldmedal opened this issue 7 months ago • 1 comments

  • Add postgres data source
  • Fix the function list path
  • Fix inptu dialect

Summary by CodeRabbit

  • New Features

    • Added support for running queries against Postgres data sources.
  • Bug Fixes

    • Improved handling of environment variables to ensure correct loading.
    • Fixed path construction for function list files to prevent missing slashes.
  • Other Improvements

    • Unified query result output for a cleaner display.
    • Enhanced error handling for unsupported data sources.

goldmedal avatar May 06 '25 08:05 goldmedal

Walkthrough

The script query_local_run.py is updated to support Postgres as a data source in addition to MySQL. It now loads environment variables with override, corrects the function list path, and unifies result printing. Unsupported data sources now raise an exception instead of printing a message.

Changes

File(s) Change Summary
ibis-server/tools/query_local_run.py Added Postgres support, corrected environment variable loading, fixed function list path, unified result printing, and now raises exceptions for unsupported data sources.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    participant MySQL
    participant Postgres

    User->>Script: Run query_local_run.py with data source
    Script->>Script: Load environment variables (override)
    Script->>Script: Determine data source (MySQL or Postgres)
    alt MySQL
        Script->>MySQL: Validate and connect using MySqlConnectionInfo
    else Postgres
        Script->>Postgres: Validate and connect using PostgresConnectionInfo
    else Unsupported
        Script->>Script: Raise Exception
    end
    Script->>Script: Execute query, limit to 10 rows, convert to DataFrame
    Script->>User: Print query results

Possibly related PRs

  • Canner/wren-engine#1171: Adds a new script for importing data into MySQL and initially added MySQL support to query_local_run.py; both PRs modify query_local_run.py to handle MySQL connections.

Suggested labels

ibis, python

Suggested reviewers

  • douenergy

Poem

A hop, a skip, a Postgres leap,
Now queries run both wide and deep.
MySQL and friends, together they play,
Results in a DataFrame, printed today.
If the source is unknown, don’t despair—
An exception hops up, handled with care!
🐇✨


📜 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 c0f888d4e4b99003866ae212e7f5b9c9135992a0 and 933d42a765c730bc6a5b202fbb2a262e2fc758a6.

📒 Files selected for processing (1)
  • ibis-server/tools/query_local_run.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
ibis-server/tools/query_local_run.py (2)
ibis-server/app/model/__init__.py (2)
  • MySqlConnectionInfo (161-186)
  • PostgresConnectionInfo (189-202)
ibis-server/app/model/data_source.py (3)
  • DataSourceExtension (70-240)
  • get_mysql_connection (154-170)
  • get_postgres_connection (173-180)
🪛 Ruff (0.8.2)
ibis-server/tools/query_local_run.py

64-64: print found

(T201)


68-68: print found

(T201)


69-69: print found

(T201)


84-84: print found

(T201)


85-85: print found

(T201)


86-86: print found

(T201)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci
🔇 Additional comments (7)
ibis-server/tools/query_local_run.py (7)

17-17: Added PostgresConnectionInfo import to support new data source.

Great addition to support Postgres as a data source alongside MySQL. This utilizes the existing PostgresConnectionInfo model from app.model.


33-33: LGTM: Environment variable override behavior improvement.

Setting override=True ensures environment variables are replaced if they're already set, which is important for consistent script behavior when run multiple times or in different environments.


62-62: LGTM: Fixed function list path construction.

Adding a slash before the data source filename ensures the path is correctly formed regardless of whether function_list_path ends with a slash.


67-67: Improved SQL dialect handling.

Changing from read="trino" to read=None allows the SQL parser to infer the input dialect rather than assuming it's always Trino. This is a good improvement for flexibility.


77-80: Added Postgres data source support following established patterns.

The implementation correctly follows the same pattern as the existing data sources:

  1. Validates connection info using PostgresConnectionInfo
  2. Creates a connection using DataSourceExtension.get_postgres_connection

This maintains consistency in how data sources are handled throughout the codebase.


81-81: LGTM: Improved error handling for unsupported data sources.

Raising an exception instead of just printing a message is better practice as it makes the error more explicit and prevents silent failures.


83-86: Good refactoring: Unified query execution and result printing.

Instead of having separate blocks for each data source, the code now uses a single unified block for executing the query and printing results. This eliminates duplicate code and ensures consistent behavior across all data sources.

🧰 Tools
🪛 Ruff (0.8.2)

84-84: print found

(T201)


85-85: print found

(T201)


86-86: print found

(T201)

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

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.

coderabbitai[bot] avatar May 06 '25 08:05 coderabbitai[bot]

Thanks @goldmedal

douenergy avatar May 12 '25 05:05 douenergy