-
Notifications
You must be signed in to change notification settings - Fork 30
fix(extra_fields): Fix issue with substream partition router picking extra fields #727
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
701f93d
Fix issue with sunstream partition router picking extra fields
aldogonzalez8 2714a97
fix ruff stuff
aldogonzalez8 7d4cdf8
try to fix test import
aldogonzalez8 68ceb67
fix ruff stuff
aldogonzalez8 eb4a95e
lint stuff
aldogonzalez8 dbfa3bb
lint stuff
aldogonzalez8 d8a8fdd
merge from main
aldogonzalez8 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 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
93 changes: 93 additions & 0 deletions
93
unit_tests/sources/declarative/partition_routers/helpers.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # | ||
| # Copyright (c) 2025 Airbyte, Inc., all rights reserved. | ||
| # | ||
|
|
||
| from typing import Any, Iterable, List, Mapping, Optional, Union | ||
|
|
||
| from airbyte_cdk.models import SyncMode | ||
| from airbyte_cdk.sources.declarative.declarative_stream import DeclarativeStream | ||
| from airbyte_cdk.sources.declarative.interpolation import InterpolatedString | ||
| from airbyte_cdk.sources.streams.checkpoint import Cursor | ||
| from airbyte_cdk.sources.types import Record, StreamSlice | ||
|
|
||
|
|
||
| class MockStream(DeclarativeStream): | ||
| def __init__(self, slices, records, name, cursor_field="", cursor=None): | ||
| self.config = {} | ||
| self._slices = slices | ||
| self._records = records | ||
| self._stream_cursor_field = ( | ||
| InterpolatedString.create(cursor_field, parameters={}) | ||
| if isinstance(cursor_field, str) | ||
| else cursor_field | ||
| ) | ||
| self._name = name | ||
| self._state = {"states": []} | ||
| self._cursor = cursor | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| return self._name | ||
|
|
||
| @property | ||
| def primary_key(self) -> Optional[Union[str, List[str], List[List[str]]]]: | ||
| return "id" | ||
|
|
||
| @property | ||
| def state(self) -> Mapping[str, Any]: | ||
| return self._state | ||
|
|
||
| @state.setter | ||
| def state(self, value: Mapping[str, Any]) -> None: | ||
| self._state = value | ||
|
|
||
| @property | ||
| def is_resumable(self) -> bool: | ||
| return bool(self._cursor) | ||
|
|
||
| def get_cursor(self) -> Optional[Cursor]: | ||
| return self._cursor | ||
|
|
||
| def stream_slices( | ||
| self, | ||
| *, | ||
| sync_mode: SyncMode, | ||
| cursor_field: List[str] = None, | ||
| stream_state: Mapping[str, Any] = None, | ||
| ) -> Iterable[Optional[StreamSlice]]: | ||
| for s in self._slices: | ||
| if isinstance(s, StreamSlice): | ||
| yield s | ||
| else: | ||
| yield StreamSlice(partition=s, cursor_slice={}) | ||
|
|
||
| def read_records( | ||
| self, | ||
| sync_mode: SyncMode, | ||
| cursor_field: List[str] = None, | ||
| 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: | ||
| result = self._records | ||
| else: | ||
| result = [ | ||
| Record(data=r, associated_slice=stream_slice, stream_name=self.name) | ||
| for r in self._records | ||
| if r["slice"] == stream_slice["slice"] | ||
| ] | ||
|
|
||
| yield from result | ||
|
|
||
| # Update the state only after reading the full slice | ||
| cursor_field = self._stream_cursor_field.eval(config=self.config) | ||
| if stream_slice and cursor_field and result: | ||
| self._state["states"].append( | ||
| {cursor_field: result[-1][cursor_field], "partition": stream_slice["slice"]} | ||
| ) | ||
|
|
||
| def get_json_schema(self) -> Mapping[str, Any]: | ||
| return {} | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.