Skip to content

Commit

Permalink
[low-code connectors] Get parent stream's full slice (#15631)
Browse files Browse the repository at this point in the history
* always access parent stream using full_refresh mode

* Update test

* fix substream slicer

* bump
  • Loading branch information
girarda authored Aug 18, 2022
1 parent 81eac50 commit 313ac11
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions airbyte-cdk/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.1.76
- Bugfix: Correctly set parent slice stream for sub-resource streams

## 0.1.75
- Improve `filter_secrets` skip empty secret

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def stream_slices(self, sync_mode: SyncMode, stream_state: StreamState) -> Itera
stream_state_field = parent_stream_config.stream_slice_field
for parent_stream_slice in parent_stream.stream_slices(sync_mode=sync_mode, cursor_field=None, stream_state=stream_state):
empty_parent_slice = True
parent_slice = parent_stream_slice.get("slice")
parent_slice = parent_stream_slice

for parent_record in parent_stream.read_records(
sync_mode=SyncMode.full_refresh, cursor_field=None, stream_slice=parent_stream_slice, stream_state=None
Expand Down
2 changes: 1 addition & 1 deletion airbyte-cdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name="airbyte-cdk",
version="0.1.75",
version="0.1.76",
description="A framework for writing Airbyte Connectors.",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def read_records(
stream_slice: Mapping[str, Any] = None,
stream_state: Mapping[str, Any] = None,
) -> Iterable[Mapping[str, Any]]:
# The parent stream's records should always be read as full refresh
assert sync_mode == SyncMode.full_refresh
if not stream_slice:
yield from self._records
else:
Expand All @@ -64,7 +66,7 @@ def read_records(
stream=MockStream([{}], [], "first_stream"), parent_key="id", stream_slice_field="first_stream_id", options={}
)
],
[{"first_stream_id": None, "parent_slice": None}],
[{"first_stream_id": None, "parent_slice": {}}],
),
(
"test_single_parent_slices_with_records",
Expand All @@ -76,7 +78,7 @@ def read_records(
options={},
)
],
[{"first_stream_id": 1, "parent_slice": None}, {"first_stream_id": 2, "parent_slice": None}],
[{"first_stream_id": 1, "parent_slice": {}}, {"first_stream_id": 2, "parent_slice": {}}],
),
(
"test_with_parent_slices_and_records",
Expand All @@ -89,10 +91,10 @@ def read_records(
)
],
[
{"parent_slice": "first", "first_stream_id": 0},
{"parent_slice": "first", "first_stream_id": 1},
{"parent_slice": "second", "first_stream_id": 2},
{"parent_slice": "third", "first_stream_id": None},
{"parent_slice": {"slice": "first"}, "first_stream_id": 0},
{"parent_slice": {"slice": "first"}, "first_stream_id": 1},
{"parent_slice": {"slice": "second"}, "first_stream_id": 2},
{"parent_slice": {"slice": "third"}, "first_stream_id": None},
],
),
(
Expand All @@ -112,12 +114,12 @@ def read_records(
),
],
[
{"parent_slice": "first", "first_stream_id": 0},
{"parent_slice": "first", "first_stream_id": 1},
{"parent_slice": "second", "first_stream_id": 2},
{"parent_slice": "third", "first_stream_id": None},
{"parent_slice": "second_parent", "second_stream_id": 10},
{"parent_slice": "second_parent", "second_stream_id": 20},
{"parent_slice": {"slice": "first"}, "first_stream_id": 0},
{"parent_slice": {"slice": "first"}, "first_stream_id": 1},
{"parent_slice": {"slice": "second"}, "first_stream_id": 2},
{"parent_slice": {"slice": "third"}, "first_stream_id": None},
{"parent_slice": {"slice": "second_parent"}, "second_stream_id": 10},
{"parent_slice": {"slice": "second_parent"}, "second_stream_id": 20},
],
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from setuptools import find_packages, setup

MAIN_REQUIREMENTS = [
"airbyte-cdk~=0.1.73",
"airbyte-cdk~=0.1.76",
]

TEST_REQUIREMENTS = [
Expand Down

0 comments on commit 313ac11

Please sign in to comment.