-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: (low code)run state migrations for concurrent streams (#316)
Co-authored-by: octavia-squidington-iii <[email protected]>
- Loading branch information
1 parent
6260248
commit 74631d8
Showing
5 changed files
with
350 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Any, Mapping | ||
|
||
from airbyte_cdk.sources.declarative.declarative_stream import DeclarativeStream | ||
from airbyte_cdk.sources.declarative.interpolation.interpolated_string import InterpolatedString | ||
from airbyte_cdk.sources.declarative.migrations.state_migration import StateMigration | ||
from airbyte_cdk.sources.types import Config | ||
|
||
|
||
class CustomStateMigration(StateMigration): | ||
declarative_stream: DeclarativeStream | ||
config: Config | ||
|
||
def __init__(self, declarative_stream: DeclarativeStream, config: Config): | ||
self._config = config | ||
self.declarative_stream = declarative_stream | ||
self._cursor = declarative_stream.incremental_sync | ||
self._parameters = declarative_stream.parameters | ||
self._cursor_field = InterpolatedString.create( | ||
self._cursor.cursor_field, parameters=self._parameters | ||
).eval(self._config) | ||
|
||
def should_migrate(self, stream_state: Mapping[str, Any]) -> bool: | ||
return True | ||
|
||
def migrate(self, stream_state: Mapping[str, Any]) -> Mapping[str, Any]: | ||
if not self.should_migrate(stream_state): | ||
return stream_state | ||
updated_at = stream_state[self._cursor.cursor_field] | ||
|
||
migrated_stream_state = { | ||
"states": [ | ||
{ | ||
"partition": {"type": "type_1"}, | ||
"cursor": {self._cursor.cursor_field: updated_at}, | ||
}, | ||
{ | ||
"partition": {"type": "type_2"}, | ||
"cursor": {self._cursor.cursor_field: updated_at}, | ||
}, | ||
] | ||
} | ||
|
||
return migrated_stream_state |
This file contains 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
Oops, something went wrong.