source-klaivyo-native: better sorting and filtering handling#4062
Open
source-klaivyo-native: better sorting and filtering handling#4062
Conversation
`fetch_incremental_resources` assumed that using the `LowerBoundOperator.GREATER_THAN` caused Klaviyo to _not_ return results whose cursor field was at the lower bound. Turns out, that's not necessarily true, and the Klaviyo API sometimes returns results that are on the lower bound when using the greater than operator. We can easily address this by just ignoring any results received that are not greater than the log cursor.
…mail campaigns The Klaviyo API occasionally returns archived email campaigns in slightly unsorted order despite the `sort` query parameter, causing the connector to crash with a "Received documents out of order from the Klaviyo API." error. This commits adds an `assume_sorted` flag to `IncrementalStream`. For streams where it's `True`, we continue validating the API returns results in sorted order and emitting checkpoints before processing the entire set of results. For streams where it's `False`, we now skip the ordering validation and only checkpoint after emitting all documents in the set of results. Since we've consistently observed the Klaviyo API return archived email campaigns in unsorted order, this commit also sets `assume_sorted` on the `EmailCampaignsArchived` class to `False`. We've only observed the `EmailCampaignsArchived` stream receive unsorted results, so I'm holding off setting `assume_sorted=False` for any other streams for now. If we observe more `Received documents out of order from the Klaviyo API` for other streams, we can either set `assume_sorted=False` on more streams or find a more robust general purpose solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This PR's scope addresses some connector bugs where the Klaviyo API is not sorting / filtering results as expected:
greater-thanoperator. These are now skipped.sortquery parameter. This caused the connector to crash with aReceived documents out of order from the Klaviyo API.error since the connector validates the "records are sorted" assumption. Anassume_sortedflag onIncrementalStreamnow relaxed that assumption and associated check. Only theEmailCampaignsArchivedhasassume_sortedset toFalsefor now. If we observe more streams receive unsorted results, we can set theirassume_sortedtoFalseas needed or potentially come up with a more robust solution.Workflow steps:
(How does one use this feature, and how has it changed)
Documentation links affected:
(list any documentation links that you created, or existing ones that you've identified as needing updates, along with a brief description)
Notes for reviewers:
(anything that might help someone review this PR)