Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Enhance trino connector #1207

Merged
merged 5 commits into from
Jan 23, 2025
Merged

Conversation

wwwy3y3
Copy link
Member

@wwwy3y3 wwwy3y3 commented Jan 22, 2025

Fix SSL issue

ref: #1106

Support using multiple catalog.schema

Users could now specify more than one catalog.schema
Screenshot 2025-01-23 at 5 07 33 AM
ref: #546

Summary by CodeRabbit

  • New Features

    • Enhanced Trino data source connection to support multiple schemas.
    • Updated form and validation for Trino connection properties to allow multiple schema inputs.
    • Improved password input security in connection setup.
  • Bug Fixes

    • Refined schema handling for Trino data source connections.
  • Documentation

    • Updated error messages to clarify schema input requirements.

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce enhanced support for multiple schemas in Trino data source connections across the Wren UI project. The modifications span several files, updating the connection information handling to allow multiple schemas instead of a single schema. This involves changes to the data source adaptor, connection info interfaces, form components, and error text dictionary to support a more flexible schema configuration approach.

Changes

File Change Summary
wren-ui/src/apollo/server/adaptors/ibisAdaptor.ts Added toMultipleIbisConnectionInfos import and modified getTables method to handle multiple connection information.
wren-ui/src/apollo/server/dataSource.ts Introduced toMultipleIbisConnectionInfos function, updated IDataSourceConnectionInfo interface, modified Trino data source connection handling.
wren-ui/src/apollo/server/repositories/projectRepository.ts Changed schema property to schemas in TRINO_CONNECTION_INFO interface.
wren-ui/src/components/pages/setup/dataSources/TrinoProperties.tsx Renamed form fields from "Catalog" and "Schema" to "Schemas", updated validation, changed Password input type.
wren-ui/src/utils/error/dictionary.ts Added new error text entry for schemas requirement.
wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts Updated mockTrinoConnectionInfo to replace catalog with schemas, adjusted test logic accordingly.

Sequence Diagram

sequenceDiagram
    participant UI as Trino Properties UI
    participant Repo as Project Repository
    participant Adaptor as Ibis Adaptor
    participant DataSource as Data Source Handler

    UI->>Repo: Submit connection info with multiple schemas
    Repo->>DataSource: Process connection info
    DataSource->>DataSource: Convert to multiple connection infos
    DataSource-->>Adaptor: Provide connection details
    Adaptor->>Adaptor: Fetch tables for each connection
    Adaptor-->>UI: Return consolidated table list
Loading

Poem

🐰 Schemas dancing, multiple and bright,
Trino's connections now take flight!
From single path to broader view,
Our rabbit code leaps right on through!
Flexibility springs with each new line,
Connecting data, simply divine! 🔗


📜 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 b706a06 and ecb5272.

📒 Files selected for processing (1)
  • wren-ui/src/utils/error/dictionary.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

Copy link
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

🔭 Outside diff range comments (1)
wren-ui/src/components/pages/setup/dataSources/TrinoProperties.tsx (1)

Line range hint 85-90: Fix inconsistency in required validation for Password field

The Password field has required set to true in the Form.Item, but required is set to false in the validation rules. This inconsistency may lead to incorrect form validation. If the Password field is intended to be required, set required: true in the validation rules.

Apply this diff to fix the validation rule:

          <Form.Item
            label="Password"
            name="password"
            required
            rules={[
              {
-               required: false,
+               required: true,
                message: ERROR_TEXTS.CONNECTION.PASSWORD.REQUIRED,
              },
            ]}
          >
🧹 Nitpick comments (4)
wren-ui/src/apollo/server/adaptors/ibisAdaptor.ts (2)

276-286: Add type annotations to getTablesByConnectionInfo for type safety

Adding explicit type annotations to the getTablesByConnectionInfo function's parameters and return type improves type safety and code readability.

Apply this diff to add type annotations:

-          const getTablesByConnectionInfo = async (ibisConnectionInfo) => {
+          const getTablesByConnectionInfo = async (
+            ibisConnectionInfo: IbisConnectionInfo,
+          ): Promise<CompactTable[]> => {

296-301: Consider handling individual connection failures when fetching tables

Currently, if fetching tables from one of the multiple connections fails, the entire operation will fail due to the use of Promise.all. Consider using Promise.allSettled to handle individual failures, allowing the successful retrieval of tables from other connections while appropriately handling or logging the errors from failed connections.

wren-ui/src/utils/error/dictionary.ts (1)

47-47: Improve error message wording for SCHEMAS.REQUIRED

Consider rephrasing the error message for better clarity and grammar:

Apply this diff to update the error message:

        SCHEMAS: {
-          REQUIRED: 'Please input list of catalog.schema separated by comma.',
+          REQUIRED: 'Please input a list of catalog.schema entries separated by commas.',
        },
wren-ui/src/apollo/server/dataSource.ts (1)

181-198: Enhance error handling for schema parsing.

The schema parsing logic could be more robust. Consider these improvements:

  1. Trim whitespace from schema parts
  2. Validate schema format before splitting
-      const [catalog, schema] = schemas.split(',')?.[0]?.split('.') ?? [];
+      const firstSchema = schemas.split(',')[0]?.trim();
+      if (!firstSchema) {
+        throw new Error('No valid schema provided');
+      }
+      const [catalog, schema] = firstSchema.split('.');
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 97a9341 and 5df49fd.

📒 Files selected for processing (5)
  • wren-ui/src/apollo/server/adaptors/ibisAdaptor.ts (2 hunks)
  • wren-ui/src/apollo/server/dataSource.ts (3 hunks)
  • wren-ui/src/apollo/server/repositories/projectRepository.ts (1 hunks)
  • wren-ui/src/components/pages/setup/dataSources/TrinoProperties.tsx (2 hunks)
  • wren-ui/src/utils/error/dictionary.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (7)
wren-ui/src/apollo/server/adaptors/ibisAdaptor.ts (1)

17-20: Importing toMultipleIbisConnectionInfos to handle multiple connections

The addition of toMultipleIbisConnectionInfos enhances the ability to process multiple Ibis connection information objects, aligning with the new requirement to support multiple catalog.schema configurations.

wren-ui/src/components/pages/setup/dataSources/TrinoProperties.tsx (2)

54-64: Update Schemas field to support multiple catalog.schema configurations

The changes to the Schemas field appropriately reflect the support for multiple catalog.schema configurations, enhancing the flexibility of the Trino connector as per the PR objectives.


90-90: Use of Input.Password for password field

Changing the password input to Input.Password enhances security by masking user input, providing a better user experience.

wren-ui/src/apollo/server/repositories/projectRepository.ts (1)

56-56: Verify backward compatibility of the schema property rename.

The change from schema to schemas in the TRINO_CONNECTION_INFO interface might break existing code that relies on the old property name.

Let's check for any existing usage of the old property name:

✅ Verification successful

The schema property rename is safe to proceed with

The rename from schema to schemas in TRINO_CONNECTION_INFO interface is actually a bug fix that better reflects the expected format of multiple catalog.schema entries. No usage of the old property name was found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct usage of the old schema property
rg -l "schema.*:.*string.*TRINO_CONNECTION_INFO" || rg -l "TRINO_CONNECTION_INFO.*schema.*:.*string"

# Search for destructuring of the old schema property from TRINO_CONNECTION_INFO
rg "const.*{.*schema.*}.*as.*TRINO_CONNECTION_INFO"

Length of output: 292


Script:

#!/bin/bash
# Find the interface definition and any related types
rg -l "interface.*TRINO_CONNECTION_INFO"

# Search for any usage of .schema property
rg "\.schema\b" --type typescript

# Search for schema in type definitions
rg "schema.*:.*string" --type typescript

# Search for any destructuring patterns with schema
rg "{[^}]*schema[^}]*}" --type typescript

Length of output: 389


Script:

#!/bin/bash
# View the content of the file containing the interface
cat wren-ui/src/apollo/server/repositories/projectRepository.ts

# Search for any schema-related patterns
rg "\.schema\b"

# Search for schema in type definitions with fixed regex
rg "schema: string"

# Search for TRINO_CONNECTION_INFO usage
rg "TRINO_CONNECTION_INFO"

Length of output: 15160

wren-ui/src/apollo/server/dataSource.ts (3)

50-57: LGTM! Well-structured null-safe implementation.

The new toMultipleIbisConnectionInfos function safely handles data sources that don't support multiple connection infos by returning null.


62-62: LGTM! Good use of optional method.

Making toMultipleIbisConnectionInfos optional in the interface allows for gradual adoption by different data sources.


192-192: LGTM! Proper SSL handling.

The SSL implementation correctly prefixes the host with https:// when SSL is enabled.

wren-ui/src/apollo/server/dataSource.ts Outdated Show resolved Hide resolved
Copy link
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: 2

🧹 Nitpick comments (1)
wren-ui/src/apollo/server/adaptors/ibisAdaptor.ts (1)

296-301: Handle Partial Failures When Fetching Tables

Currently, if one of the connections fails in Promise.all, the entire operation will fail. Consider handling partial failures so that tables from successful connections are returned, and errors are logged or communicated appropriately.

You might modify the implementation to use Promise.allSettled and process the results accordingly:

- const results = await Promise.all(
-   multipleIbisConnectionInfos.map(getTablesByConnectionInfo),
- );
+ const results = await Promise.allSettled(
+   multipleIbisConnectionInfos.map(getTablesByConnectionInfo),
+ );
+ const tables = results
+   .filter(result => result.status === 'fulfilled')
+   .flatMap(result => result.value);
+ if (tables.length === 0) {
+   throw new Error('Failed to retrieve tables from all connections');
+ }
+ return tables;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5df49fd and 01b432a.

📒 Files selected for processing (3)
  • wren-ui/src/apollo/server/adaptors/ibisAdaptor.ts (2 hunks)
  • wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts (2 hunks)
  • wren-ui/src/apollo/server/dataSource.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
wren-ui/src/apollo/server/adaptors/ibisAdaptor.ts (1)

276-287: Correct Implementation of Multiple Connection Infos

The addition of the getTablesByConnectionInfo function and handling multiple Ibis connection infos enhances the getTables method to support multiple schemas effectively. The asynchronous implementation using async/await is well-structured.

wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts (1)

77-77: Update Mock Trino Connection Info Structure

The change from catalog to schemas in mockTrinoConnectionInfo correctly reflects the new structure supporting multiple schemas. This aligns the test data with the updated function expectations.

wren-ui/src/apollo/server/dataSource.ts (3)

50-57: Well-Designed toMultipleIbisConnectionInfos Function

The introduction of the toMultipleIbisConnectionInfos function is thoughtfully implemented, enhancing the ability to handle multiple schemas within the data source configuration.


181-199: Consider Reusing Schema Parsing Logic to Avoid Duplication

In the toIbisConnectionInfo method for Trino, you're performing schema parsing similar to toMultipleIbisConnectionInfos. To maintain DRY (Don't Repeat Yourself) principles, consider reusing the parseSchema helper function to avoid code duplication and ensure consistent validation.

Since a similar suggestion was made in a previous review, applying this change will improve maintainability and consistency in your codebase.


200-243: Effective Handling of Multiple Schemas for Trino

The toMultipleIbisConnectionInfos method effectively parses and validates multiple schemas, and constructs the corresponding connection information objects. This implementation enhances the flexibility and scalability of the Trino connector.

Copy link
Contributor

@andreashimin andreashimin left a comment

Choose a reason for hiding this comment

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

besides a nitpick, others lgtm

wren-ui/src/utils/error/dictionary.ts Outdated Show resolved Hide resolved
@wwwy3y3 wwwy3y3 merged commit 83d4da4 into main Jan 23, 2025
6 of 7 checks passed
@wwwy3y3 wwwy3y3 deleted the feature/enhance-trino-connector branch January 23, 2025 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants