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

Fix: Resolve issues in Postgres name normalization when names are >63 characters #359

Merged
merged 14 commits into from
Sep 9, 2024

Conversation

aaronsteers
Copy link
Contributor

@aaronsteers aaronsteers commented Sep 9, 2024

Summary by CodeRabbit

  • New Features
    • Expanded test coverage by adding a new scenario to the expected output structure.
    • Enhanced flexibility in test validations by dynamically calculating the expected count of processed records.
    • Introduced new options in the record retrieval process to control normalization of field names and pruning of undeclared fields, improving usability.
    • Added Postgres-specific name normalization to ensure compliance with naming conventions and improve performance.
  • Bug Fixes
    • Updated the expected number of processed records in various tests to align with changes in the output structure.

Copy link

coderabbitai bot commented Sep 9, 2024

Warning

Rate limit exceeded

@aaronsteers has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 7 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between abf16e9 and 2b2774d.

Walkthrough

Walkthrough

This pull request introduces modifications to the expected_test_stream_data function by adding a new entry for "primary-key-with-dot" with a corresponding list of column-value pairs. It also updates several assertions across multiple test functions to dynamically calculate the expected number of processed records. Additionally, the get_records method in airbyte/sources/base.py has been enhanced with two new optional parameters, improving its flexibility in handling field names and undeclared fields. Furthermore, a new PostgresNormalizer class is introduced to handle name normalization specific to Postgres, ensuring compliance with naming constraints.

Changes

Files Change Summary
tests/integration_tests/test_source_test_fixture.py Added a new key "primary-key-with-dot" to expected_test_stream_data() and modified assertions to dynamically calculate expected processed records.
airbyte/sources/base.py Expanded the get_records method to include normalize_field_names and prune_undeclared_fields parameters, with updated docstring and logic.
airbyte/_processors/sql/postgres.py Introduced PostgresNormalizer class for name normalization in Postgres, including a method to truncate names and optimize with caching.

Possibly related PRs

Suggested labels

enable-ai-review


Do you think we should include a brief description of the purpose of the new parameters in the get_records method in the Walkthrough section? Wdyt?


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 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 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 or @coderabbitai title 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

@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

tests/integration_tests/test_source_test_fixture.py Outdated Show resolved Hide resolved
Copy link

@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: 0

Outside diff range, codebase verification and nitpick comments (1)
airbyte/shared/sql_processor.py (1)

500-512: The modified logic in the _get_temp_table_name method looks good! 👍

  • Checking the length of batch_id and constructing the suffix differently based on the length is a good way to ensure that the resulting table name is unique and adheres to potential database constraints on name lengths.
  • Using the first 6 and last 3 characters of batch_id when the length exceeds 9 characters is a nice approach to maintain uniqueness while limiting the suffix length.
  • The comments provide a clear explanation of the reasoning behind the changes and the potential database constraints that are being addressed.

Just a minor suggestion: What do you think about using a ternary operator instead of the if-else block? Something like this:

suffix = f"{batch_id[:6]}{batch_id[-3:]}" if len(batch_id) > 9 else batch_id

This could make the code a bit more concise. But it's totally up to you! The current implementation is perfectly fine as well.

Tools
Ruff

503-508: Use ternary operator suffix = f"{batch_id[:6]}{batch_id[-3:]}" if len(batch_id) > 9 else batch_id instead of if-else-block

(SIM108)


503-503: Magic value used in comparison, consider replacing 9 with a constant variable

(PLR2004)

@aaronsteers aaronsteers changed the title Chore: fix tests Fix: Resolve issues in normalization for Postgres Sep 9, 2024
@aaronsteers aaronsteers changed the title Fix: Resolve issues in normalization for Postgres Fix: Resolve issues in Postgres name normalization when names are >63 characters Sep 9, 2024
@aaronsteers
Copy link
Contributor Author

aaronsteers commented Sep 9, 2024

/fix-pr

Auto-Fix Job Info

This job attempts to auto-fix any linting or formating issues. If any fixes are made,
those changes will be automatically committed and pushed back to the PR.
(This job requires that the PR author has "Allow edits from maintainers" enabled.)

PR auto-fix job started... Check job output.

✅ Changes applied successfully.

@aaronsteers
Copy link
Contributor Author

aaronsteers commented Sep 9, 2024

/fix-pr

Auto-Fix Job Info

This job attempts to auto-fix any linting or formating issues. If any fixes are made,
those changes will be automatically committed and pushed back to the PR.
(This job requires that the PR author has "Allow edits from maintainers" enabled.)

PR auto-fix job started... Check job output.

✅ Changes applied successfully.

@aaronsteers aaronsteers marked this pull request as ready for review September 9, 2024 19:47
@aaronsteers aaronsteers enabled auto-merge (squash) September 9, 2024 19:47
@aaronsteers
Copy link
Contributor Author

aaronsteers commented Sep 9, 2024

/fix-pr

Auto-Fix Job Info

This job attempts to auto-fix any linting or formating issues. If any fixes are made,
those changes will be automatically committed and pushed back to the PR.
(This job requires that the PR author has "Allow edits from maintainers" enabled.)

PR auto-fix job started... Check job output.

✅ Changes applied successfully.

Copy link

@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: 0

Outside diff range, codebase verification and nitpick comments (1)
tests/unit_tests/test_text_normalization.py (1)

190-231: Great addition of test cases for the PostgresNormalizer!

The changes to the test_lower_case_normalizer function look good:

  • The addition of the normalizer_class parameter allows the function to test different normalizer classes, which is a nice improvement.
  • The additional test cases for the PostgresNormalizer class ensure that it behaves as expected, especially regarding the truncation behavior for long strings.

Just one small suggestion: What do you think about renaming the function to test_normalizer since it now tests multiple normalizer classes?

@aaronsteers aaronsteers linked an issue Sep 9, 2024 that may be closed by this pull request
@aaronsteers aaronsteers merged commit ddbf6f4 into main Sep 9, 2024
13 checks passed
@aaronsteers aaronsteers deleted the chore--test-fixes branch September 9, 2024 20:34
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.

hubspot connection bug
1 participant