-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Emit a state message even if no records were read #15067
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ac697cd
Emit a state message even if no records were read
girarda 6ffb7e0
newline
girarda 956a281
Merge branch 'master' into alex/emitstate
girarda 7f44cf1
Merge branch 'master' into alex/emitstate
girarda 68fe98c
merge
girarda dcadf70
comment
girarda a87b775
Merge branch 'master' into alex/emitstate
girarda 1e5ed36
implement logic in the abstract source
girarda ae01056
remove logic from declarative source
girarda d1c43be
comment
girarda 0aa3242
Merge branch 'master' into alex/emitstate
girarda 7a5f055
Merge branch 'master' into alex/emitstate
girarda 617d26b
bump cdk version
girarda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,9 +98,13 @@ def primary_key(self) -> Optional[Union[str, List[str], List[List[str]]]]: | |
class MockStreamWithState(MockStream): | ||
cursor_field = "cursor" | ||
|
||
def __init__(self, inputs_and_mocked_outputs: List[Tuple[Mapping[str, Any], Iterable[Mapping[str, Any]]]], name: str, state=None): | ||
super().__init__(inputs_and_mocked_outputs, name) | ||
self._state = state | ||
|
||
@property | ||
def state(self): | ||
return {} | ||
return self._state | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set a state to verify the emitted state is the same as the input state when no slices are read |
||
|
||
@state.setter | ||
def state(self, value): | ||
|
@@ -452,6 +456,74 @@ def test_with_slices(self, mocker): | |
|
||
assert expected == messages | ||
|
||
def test_no_slices(self, mocker): | ||
""" | ||
Tests that an incremental read returns at least one state messages even if no records were read: | ||
1. outputs a state message after reading the entire stream | ||
""" | ||
slices = [] | ||
stream_output = [{"k1": "v1"}, {"k2": "v2"}, {"k3": "v3"}] | ||
state = {"cursor": "value"} | ||
s1 = MockStreamWithState( | ||
[ | ||
( | ||
{ | ||
"sync_mode": SyncMode.incremental, | ||
"stream_slice": s, | ||
"stream_state": mocker.ANY, | ||
}, | ||
stream_output, | ||
) | ||
for s in slices | ||
], | ||
name="s1", | ||
state=state, | ||
) | ||
s2 = MockStreamWithState( | ||
[ | ||
( | ||
{ | ||
"sync_mode": SyncMode.incremental, | ||
"stream_slice": s, | ||
"stream_state": mocker.ANY, | ||
}, | ||
stream_output, | ||
) | ||
for s in slices | ||
], | ||
name="s2", | ||
state=state, | ||
) | ||
|
||
mocker.patch.object(MockStreamWithState, "supports_incremental", return_value=True) | ||
mocker.patch.object(MockStreamWithState, "get_json_schema", return_value={}) | ||
mocker.patch.object(MockStreamWithState, "stream_slices", return_value=slices) | ||
mocker.patch.object( | ||
MockStreamWithState, | ||
"state_checkpoint_interval", | ||
new_callable=mocker.PropertyMock, | ||
return_value=2, | ||
) | ||
|
||
src = MockSource(streams=[s1, s2]) | ||
catalog = ConfiguredAirbyteCatalog( | ||
streams=[ | ||
_configured_stream(s1, SyncMode.incremental), | ||
_configured_stream(s2, SyncMode.incremental), | ||
] | ||
) | ||
|
||
expected = [ | ||
_state({"s1": state}), | ||
_state({"s1": state, "s2": state}), | ||
] | ||
|
||
messages = _fix_emitted_at(list(src.read(logger, {}, catalog, state=defaultdict(dict)))) | ||
|
||
print(f"expected:\n{expected}") | ||
print(f"messages:\n{messages}") | ||
assert expected == messages | ||
|
||
def test_with_slices_and_interval(self, mocker): | ||
""" | ||
Tests that an incremental read which uses slices and a checkpoint interval: | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@girarda, there is an on call issue that seems related to this new change.
https://sentry.io/organizations/airbytehq/issues/3521477693/?project=6527718
https://github.com/airbytehq/oncall/issues/466
I don't understand the CDK very well. But it looks like the
stream_instance.state
is only set conditionally:That condition is different from the one here.
Should the
state
be set for more cases?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tuliren alex is on PTO - I've asked someone from the team to assist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thank you.