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

feat(ibis): postgreSQL, PostGIS support for IBIS Server.

Open eren-ture opened this issue 7 months ago • 3 comments

Inclusions

  • Added an ExtensionHandler class to handle database extensions. Created the postgis_handler method to define columns as geometry or geography.

  • Added new column types GEOMETRY and GEOGRAPHY to the RustWrenEngineColumnType enum to represent PostGIS-specific data types.

Proof of Work

image image

Issue

When the frontend is asked to display the values, it obviously fails. I unfortunately don't know much about frontend development, ad cannot fix this issue. image

Summary by CodeRabbit

  • New Features
    • Added support for recognizing and displaying PostGIS extension column types (GEOMETRY and GEOGRAPHY) in PostgreSQL metadata.
    • Metadata extraction now includes extension-specific columns, providing more accurate information for tables using supported PostgreSQL extensions.

eren-ture avatar May 06 '25 13:05 eren-ture

[!IMPORTANT]

Review skipped

Review was skipped due to path filters

:no_entry: Files ignored due to path filters (1)
  • ibis-server/poetry.lock is excluded by !**/*.lock

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

"""

Walkthrough

The changes introduce support for PostgreSQL extensions, specifically PostGIS, in the metadata extraction process. This is achieved by extending the column type enum to include geometry types and adding an ExtensionHandler class that augments table metadata with extension-specific information during table list retrieval. Additionally, tests were added to validate PostGIS spatial queries. New dependencies for spatial data handling were also added.

Changes

File(s) Change Summary
ibis-server/app/model/metadata/dto.py Extended the RustWrenEngineColumnType enum by adding two new members: GEOMETRY and GEOGRAPHY, representing PostGIS extension types.
ibis-server/app/model/metadata/postgres.py Added the ExtensionHandler class to handle PostgreSQL extensions and augment table metadata. Integrated this handler into PostgresMetadata.get_table_list to support PostGIS by updating column types for geometry and geography columns.
ibis-server/tests/routers/v2/connector/test_postgres.py Added a pytest fixture to start a PostGIS-enabled PostgreSQL container and load spatial data. Added an async test to query PostGIS geometry data and verify spatial calculations through the API.
ibis-server/pyproject.toml Added new dependencies: geopandas and geoalchemy2 for spatial data support.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PostgresMetadata
    participant ExtensionHandler
    participant Database

    Client->>PostgresMetadata: get_table_list()
    PostgresMetadata->>Database: Query standard table metadata
    Database-->>PostgresMetadata: Return tables and columns
    PostgresMetadata->>ExtensionHandler: augment(tables)
    ExtensionHandler->>Database: get_extensions()
    Database-->>ExtensionHandler: Return installed extensions
    ExtensionHandler->>Database: Query PostGIS columns (if present)
    Database-->>ExtensionHandler: Return geometry/geography columns
    ExtensionHandler->>PostgresMetadata: Return augmented tables
    PostgresMetadata-->>Client: Return final table list with extension types

Poem

In the warren of code, new tunnels appear,
PostGIS now whispers, "Geometry is here!"
Columns grow clever, with types fresh and bright,
Extensions now handled, metadata’s delight.
With paws on the schema and nose to the ground,
This rabbit ensures all the columns are found!
🐇✨ """


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.

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

This is very interesting use case! @wwwy3y3 @andreashimin take a closer look!

chilijung avatar May 06 '25 14:05 chilijung

Thanks @eren-ture for the contribution. It's awesome. 👍 However, it's better to add the corresponding test case for it. You can add the test case in ibis-server/tests/routers/v2/connector/test_postgres.py https://github.com/Canner/wren-engine/blob/c0f888d4e4b99003866ae212e7f5b9c9135992a0/ibis-server/tests/routers/v2/connector/test_postgres.py#L742

Maybe add a test case called test_metadata_list_tables_with_postgis. I think you need to prepare the testing data by initializing the testing Postgres with PostGIS and try to list tables from it. We use testcontainer to create the testing PG when testing. You can refer to postgres() to see how we initialize a testing database. https://github.com/Canner/wren-engine/blob/c0f888d4e4b99003866ae212e7f5b9c9135992a0/ibis-server/tests/routers/v2/connector/test_postgres.py#L136

I expected you might implement another method called postgres_gis() for another instance.

goldmedal avatar May 06 '25 17:05 goldmedal

Hi @goldmedal, I'm currently working on writing the tests. I'm more on the data side than software, but I'll probably get some commits out soon.

eren-ture avatar May 12 '25 09:05 eren-ture

Hi @goldmedal, I'm currently working on writing the tests. I'm more on the data side than software, but I'll probably get some commits out soon.

Thanks. I'm looking forward to them. 👍

goldmedal avatar May 12 '25 09:05 goldmedal

@eren-ture Thanks for all the hard work! Could you update the Poetry lock file? It looks like the CI failed because it needs to be updated. You can just run poetry lock.

douenergy avatar May 21 '25 02:05 douenergy

@eren-ture Thanks for all the hard work! Could you update the Poetry lock file? It looks like the CI failed because it needs to be updated. You can just run poetry lock.

It's a pleasure. Thanks for the help.

I believe lock function added the packages "sqlalchemy" and "greenlet" to the main group. I don't know if that's intentional. Wanted to raise attention to it.

eren-ture avatar May 22 '25 09:05 eren-ture

I rebased with main and ran poetry lock. Hopefully this should merge.

eren-ture avatar May 23 '25 12:05 eren-ture