Skip to content

DMS: Fix handling of primary keys #104

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

Merged
merged 1 commit into from
Jun 16, 2025
Merged

DMS: Fix handling of primary keys #104

merged 1 commit into from
Jun 16, 2025

Conversation

amotl
Copy link
Member

@amotl amotl commented Jun 13, 2025

Problem

With DMS, the SQL DDL statement didn't include the primary key definition.

References

Copy link

coderabbitai bot commented Jun 13, 2025

Warning

Rate limit exceeded

@amotl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 44 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

Reviewing files that changed from the base of the PR and between 06590ef and 711ced3.

📒 Files selected for processing (5)
  • CHANGES.md (1 hunks)
  • src/commons_codec/model.py (2 hunks)
  • src/commons_codec/transform/aws_dms.py (8 hunks)
  • src/commons_codec/transform/dynamodb.py (1 hunks)
  • tests/transform/test_aws_dms.py (2 hunks)

"""

Walkthrough

The changes update AWS DMS to CrateDB translation by adding explicit handling of primary key columns as OBJECT(STRICT) with type resolution. The to_sql method now creates tables with separate PK, typed, and untyped columns, and insert statements include all three with conflict handling. Tests were expanded to verify these behaviors. The changelog documents the fix.

Changes

File(s) Change Summary
CHANGES.md Added an entry about fixing primary key handling in the "Unreleased" section.
src/commons_codec/transform/aws_dms.py Added PK_COLUMN, TYPED_COLUMN, UNTYPED_COLUMN constants; added pk_clause, resolve_type, decode_record methods; updated to_sql and related methods to handle PK and typed/untyped columns.
src/commons_codec/model.py Added UniversalRecord.from_record class method to partition record into pk, typed, and untyped parts.
src/commons_codec/transform/dynamodb.py Simplified decode_record method to use UniversalRecord.from_record instead of manual key extraction.
tests/transform/test_aws_dms.py Expanded tests for create-table DDL with PK column; split insert tests into with and without PK cases; updated SQL expectations.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Translator as DMSTranslatorCrateDBRecord
    participant UniversalRecord as UniversalRecord

    Test->>Translator: to_sql(MSG_CONTROL_CREATE_TABLE)
    Translator->>Translator: pk_clause()
    Translator->>Translator: resolve_type() (for each PK column)
    Translator-->>Test: CREATE TABLE ... with PK, typed, untyped columns

    Test->>Translator: to_sql(MSG_LOAD or MSG_INSERT)
    Translator->>Translator: decode_record(record)
    Translator->>UniversalRecord: from_record(record, primary_keys)
    UniversalRecord-->>Translator: UniversalRecord instance
    Translator-->>Test: INSERT INTO ... (pk, data, aux) ON CONFLICT DO NOTHING
Loading

Poem

🐇 Hopping through the code so bright,
Primary keys now shine in light.
Objects strict and types aligned,
In tables new, their place defined.
Tests all pass, the changelog sings,
A rabbit's joy in coding things!
✨🌿
"""

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch fix-dms-pk
  • Post Copyable Unit Tests in Comment

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:

‼️ 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 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 auto-generate unit tests to generate unit tests for 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.

@amotl amotl requested review from hammerhead and surister June 13, 2025 16:23
coderabbitai[bot]

This comment was marked as resolved.

@amotl amotl force-pushed the fix-dms-pk branch 2 times, most recently from 2d28683 to f4ea9fd Compare June 13, 2025 19:04
@amotl amotl marked this pull request as ready for review June 13, 2025 19:09
@amotl amotl force-pushed the fix-dms-pk branch 3 times, most recently from 578cffe to 06590ef Compare June 16, 2025 19:32
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: 2

🧹 Nitpick comments (1)
src/commons_codec/transform/aws_dms.py (1)

86-89: Guard against duplicate PKs when processing repeated create-table events

self.primary_keys.extend(pks) runs only once, but pks can still contain duplicates which would later produce data['id']=:id AND data['id']=:id … clauses.

-            self.primary_keys.extend(pks)
+            for pk in pks:
+                if pk not in self.primary_keys:
+                    self.primary_keys.append(pk)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f4ea9fd and 06590ef.

📒 Files selected for processing (5)
  • CHANGES.md (1 hunks)
  • src/commons_codec/model.py (2 hunks)
  • src/commons_codec/transform/aws_dms.py (8 hunks)
  • src/commons_codec/transform/dynamodb.py (1 hunks)
  • tests/transform/test_aws_dms.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGES.md
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/commons_codec/transform/dynamodb.py (1)
src/commons_codec/model.py (2)
  • UniversalRecord (137-164)
  • from_record (151-164)
🪛 GitHub Check: codecov/patch
src/commons_codec/transform/dynamodb.py

[warning] 136-136: src/commons_codec/transform/dynamodb.py#L136
Added line #L136 was not covered by tests

src/commons_codec/model.py

[warning] 161-161: src/commons_codec/model.py#L161
Added line #L161 was not covered by tests

🔇 Additional comments (2)
src/commons_codec/transform/dynamodb.py (1)

136-138: Nice simplification – leverages the new UniversalRecord.from_record()

The refactor removes hand-rolled splitting logic and delegates to the shared helper, improving consistency across translators.
No issues spotted here.

tests/transform/test_aws_dms.py (1)

230-253: Tests clearly cover both PK and non-PK insert paths

Good job extending coverage – both branches of insert logic are now exercised.

... by inheriting fragments of the translation logic from the
DynamoDB CDC handler.
@amotl amotl merged commit cc52e20 into main Jun 16, 2025
20 checks passed
@amotl amotl deleted the fix-dms-pk branch June 16, 2025 20:22
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.

2 participants