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(low-code CDK): fix checkpointing for declarative streams #177

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lazebnyi
Copy link
Contributor

@lazebnyi lazebnyi commented Dec 17, 2024

What

With this PR, the get_checkpointing method has been modified so that the state will be emitted only if the state value is not equal to the previous state value. However, declarative streams do not support record-level checkpointing and instead perform slice checkpointing. In cases where a slice ends with multiple records having the same cursor value, the state message will not be emitted because _previous_state in the checkpoint reader is already updated and matches the current state.

How

Moved the record checkpoint definition after the condition that checks if checkpointing is needed, ensuring that checkpoint_interval exists and record_counter % checkpoint_interval == 0.

Summary by CodeRabbit

  • Bug Fixes

    • Improved checkpointing logic during stream data reading to reduce redundancy and enhance clarity.
    • Refined error handling for state management to ensure correct state observation.
  • New Features

    • Enhanced testing for pagination and partitioning features in the ManifestDeclarativeSource.
    • Added configuration options for incremental data synchronization, including start_date and incremental_sync.

@github-actions github-actions bot added the bug Something isn't working label Dec 17, 2024
@lazebnyi lazebnyi requested review from maxi297 and tolik0 December 17, 2024 04:32
Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes focus on refining the state management and checkpointing mechanism within the read method of the Stream class in the Airbyte CDK. The modifications aim to optimize how checkpoints are retrieved and managed during stream reading, reducing redundancy in checkpoint fetching and improving the clarity of state observation logic. The core goal is to streamline the process of tracking and managing stream states more efficiently.

Changes

File Change Summary
airbyte_cdk/sources/streams/core.py - Consolidated checkpoint retrieval logic in read method
- Refined state management error handling
- Optimized state observation process
unit_tests/sources/declarative/test_manifest_declarative_source.py - Added test_slice_checkpoint method for validating incremental sync with partitioned data
- Updated manifest structure to include incremental_sync and start_date fields
- Modified existing tests for compatibility with new configurations

Sequence Diagram(s)

sequenceDiagram
    participant Stream
    participant StateManager
    participant Logger

    Stream->>StateManager: Retrieve checkpoint
    StateManager-->>Stream: Return checkpoint
    Stream->>Stream: Check checkpoint existence
    alt Checkpoint exists
        Stream->>Logger: Yield state message
    else No checkpoint
        Stream->>Stream: Continue reading
    end
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • maxi297
  • darynaishchenko
  • pnilan

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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

🧹 Nitpick comments (1)
airbyte_cdk/sources/streams/core.py (1)

231-236: The checkpoint emission logic looks good, but should we add some debug logging? 🤔

The changes correctly ensure that state messages are only emitted when there's an actual checkpoint to emit. This fixes the issue where state messages weren't being emitted when records shared the same cursor value.

Would it be helpful to add some debug logging here to help troubleshoot state emission issues? Something like this, wdyt?

 checkpoint = checkpoint_reader.get_checkpoint()
 if checkpoint:
+    logger.debug(f"Emitting state message for checkpoint: {checkpoint}")
     airbyte_state_message = self._checkpoint_state(
         checkpoint, state_manager=state_manager
     )
     yield airbyte_state_message
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 216cd43 and d997cf0.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/streams/core.py (1 hunks)
🔇 Additional comments (1)
airbyte_cdk/sources/streams/core.py (1)

231-236: Should we verify the checkpoint structure? 🧐

Since this is a critical part of the state management logic, it might be worth adding a verification step to ensure the checkpoint has the expected structure before emitting it. This could help catch any potential issues early.

@maxi297 maxi297 requested a review from brianjlai December 17, 2024 14:07
@maxi297
Copy link
Contributor

maxi297 commented Dec 17, 2024

Should there be a test that is being updated if we change the behavior?

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

🧹 Nitpick comments (4)
unit_tests/sources/declarative/test_manifest_declarative_source.py (4)

1906-1907: Add a brief docstring for the new parameterized test?

It might be helpful to add a concise docstring at the start of this new test to clarify its purpose, e.g., "Ensures that slice-based checkpointing emits the expected number of states for pagination and partition routers." Wdyt?


1972-1981: Verify incremental sync config test coverage.

You’re passing a new "incremental_sync" structure in your manifest. Do you want to add a test scenario that checks what happens when "start_date" is not present or is an invalid format? That might future-proof your coverage. Wdyt?


2011-2036: Confirm presence of a second partition scenario.

You're partitioning with two values ["0", "1"], and your pages are arranged to produce two distinct sets of records. Do you want to add a partition scenario beyond these two (e.g., three or four partitions) to ensure the checkpoint logic holds under multiple partitions? Wdyt?


2044-2045: Check for more robust state validation.

Here you’re only verifying the total count of states. Would verifying the exact state content and timestamps provide additional confidence? Wdyt?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d997cf0 and 7a693a2.

📒 Files selected for processing (1)
  • unit_tests/sources/declarative/test_manifest_declarative_source.py (1 hunks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants