Skip to content

Fix: Normalize schema names for correct name comparison#296

Merged
Aaron ("AJ") Steers (aaronsteers) merged 5 commits into
airbytehq:mainfrom
nakamichiworks:issue-279
Aug 10, 2024
Merged

Fix: Normalize schema names for correct name comparison#296
Aaron ("AJ") Steers (aaronsteers) merged 5 commits into
airbytehq:mainfrom
nakamichiworks:issue-279

Conversation

@nakamichiworks

@nakamichiworks nakamichi (nakamichiworks) commented Jul 13, 2024

Copy link
Copy Markdown
Contributor

Fixes #279.

Since sqlalchemy always returns normalized schema names, user given schema name must be also normalized for correct comparison.

Summary by CodeRabbit

  • Bug Fixes
    • Improved schema name normalization in SQL processing, enhancing compatibility with various SQL engine dialects.
    • Enhanced robustness of schema existence checks by standardizing both target schema names and existing schema lists.

@coderabbitai

coderabbitai Bot commented Jul 13, 2024

Copy link
Copy Markdown
Contributor
Walkthrough

Walkthrough

The sql_processor.py file in the Airbyte project has been updated to enhance the processing of schema names. The _ensure_schema_exists method now employs normalization techniques to standardize target schema names and existing schemas, ensuring consistency and improving the reliability of schema existence checks.

Changes

Files/Paths Change Summary
airbyte/_future_cdk/sql_processor.py Modified _ensure_schema_exists to normalize both target schema names and existing schemas for consistency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SQLProcessor
    participant Normalizer
    Note over SQLProcessor: Before the change
    User->>SQLProcessor: Call _ensure_schema_exists()
    SQLProcessor->>SQLProcessor: Get schema name from config
    SQLProcessor->>SQLProcessor: Check schema existence
    Note over SQLProcessor: After the change
    User->>SQLProcessor: Call _ensure_schema_exists()
    SQLProcessor->>Normalizer: Normalize schema name
    Normalizer-->>SQLProcessor: Return normalized schema name
    SQLProcessor->>Normalizer: Normalize existing schemas list
    Normalizer-->>SQLProcessor: Return normalized schemas list
    SQLProcessor->>SQLProcessor: Check schema existence
Loading

Assessment against linked issues

Objective Addressed Explanation
Add an option not to create schema for SnowflakeCache (#279) The change does not add an option to avoid schema creation.

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@aaronsteers

Copy link
Copy Markdown
Member

CodeRabbit (@coderabbitai) review

@coderabbitai

coderabbitai Bot commented Jul 18, 2024

Copy link
Copy Markdown
Contributor
Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 326683c and 658f745.

Files selected for processing (1)
  • airbyte/_future_cdk/sql_processor.py (1 hunks)
Additional comments not posted (1)
airbyte/_future_cdk/sql_processor.py (1)

306-307: LGTM! But verify the normalization method usage in the codebase.

The code changes are approved.

However, ensure that the normalize_name method from the SQL engine dialect is used correctly across the codebase.

Verification successful

The normalize_name method is used correctly and only in the intended context.

  • The normalize_name method from the SQL engine dialect is used only in the _ensure_schema_exists method in the airbyte/_future_cdk/sql_processor.py file and is implemented correctly.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the normalize_name method from the SQL engine dialect.

# Test: Search for the usage of normalize_name method. Expect: Only occurances of the correct usage.
rg --type python -A 5 $'normalize_name'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify the usage of the normalize_name method from the SQL engine dialect.

# Test: Search for the usage of normalize_name method. Expect: Only occurrences of the correct usage.
rg --glob '*.py' -A 5 'normalize_name'

Length of output: 466

@aaronsteers

Aaron ("AJ") Steers (aaronsteers) commented Jul 18, 2024

Copy link
Copy Markdown
Member

nakamichi (@nakamichiworks) - Thanks for submitting this! Can you clarify for me if the issue is related to casing or any other specific normalization issue?

For context on casing, we have an internal LowerCaseNormalizer class which we apply in all cases, and for Snowflake we are using settings that are intentionally case insensitive or case-normalized. It sounds like we are/were neglecting to normalize the schema name as we do for other fields such as column names and table names. Does that sound correct?

Comment thread airbyte/_future_cdk/sql_processor.py Outdated
@nakamichiworks

Copy link
Copy Markdown
Contributor Author

Thanks for your review and sorry for a late reply.

LowerCaseNormalizer is sufficient to resolve my original issue and I have updated the PR to use it.

However, it might be best to define and use something like SQLAlchemyNormalizer for consistency because schema names returned by SqlProcessorBase._get_schemas_list() is possibly normalized by sqlalchemy's Inspector.get_schema_names(), whose implementation depends on DB dialects (Snowflake implementation is here).

@aaronsteers

Aaron ("AJ") Steers (aaronsteers) commented Aug 9, 2024

Copy link
Copy Markdown
Member

/test-pr

PR test job started... Check job output.

❌ Tests failed.

@aaronsteers

Aaron ("AJ") Steers (aaronsteers) commented Aug 9, 2024

Copy link
Copy Markdown
Member

Thanks for your review and sorry for a late reply.

LowerCaseNormalizer is sufficient to resolve my original issue and I have updated the PR to use it.

However, it might be best to define and use something like SQLAlchemyNormalizer for consistency because schema names returned by SqlProcessorBase._get_schemas_list() is possibly normalized by sqlalchemy's Inspector.get_schema_names(), whose implementation depends on DB dialects (Snowflake implementation is here).

Thank you for this suggestion. I am a bit wary to adopt Snowflake's own case normalization because some string casings are sometimes-unreachable given Snowflake's odd "case-unaware, case-sensitive" handling. Instead, we try to exclusively interface with Snowflake using the QUOTED_IDENTIFIERS_IGNORE_CASE setting enabled - expecting all-lowercase identifiers in Python and all-uppercase when it comes to Snowflake's internal handling.

Since MIxeD case identifiers are sometimes unreachable, we essentially disallow them in PyAirbyte-managed tables/schemas/columns. It's not a perfect solution, per se, and we will certainly consider adapting the internal dialect version in the future. 👍

@aaronsteers

Aaron ("AJ") Steers (aaronsteers) commented Aug 10, 2024

Copy link
Copy Markdown
Member

/test-pr

PR test job started... Check job output.

❌ Tests failed.

Edit: Failure is false-positive. All checks successful! 🙌 ✅

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an option not to create schema for SnowflakeCache

2 participants