-
Notifications
You must be signed in to change notification settings - Fork 4.5k
low-code: Yield records from generators instead of keeping them in in-memory lists #36406
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 16 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3110caa
yield from generators
girarda 10640ab
update interfaces and fix the tests
girarda 148419e
fix some mypy issues
girarda 3a7a0b8
fix the rest of mypy issues
girarda 09e8696
update the schema
girarda 30ba4d4
Add last_page_size and last_record to pagination context
girarda 97449e6
boundaries check
girarda a7b57dd
add a test
girarda ea63f36
format
girarda d89dcbe
Merge branch 'master' into alex/replace_last_records_from_paginators
girarda 2aaa8d4
missing unit test
girarda 4e193d3
Merge branch 'alex/replace_last_records_from_paginators' of github.co…
girarda 7b514e0
missing newline
girarda 855e77f
merge
girarda 834fc96
fix imports
girarda 341d671
update unit tests
girarda db9721b
merge
girarda 28583e5
fixes
girarda f75fb47
Revert "Airbyte CDK: use pytz.utc instead of datetime.utc (#38026)"
girarda d92ec4c
Merge branch 'master' into alex/records_generator
girarda 5ce3693
Revert "Revert "Airbyte CDK: use pytz.utc instead of datetime.utc (#3…
girarda cbf9d12
typing
girarda b0456d1
Merge branch 'master' into alex/records_generator
girarda 43983ed
Revert "Revert "Revert "Airbyte CDK: use pytz.utc instead of datetime…
girarda cf0670c
remove unused variable
girarda c7b94f9
hack. revert this before merging
girarda 6732c79
Revert "hack. revert this before merging"
girarda ff3a83e
Revert "Revert "Revert "Revert "Airbyte CDK: use pytz.utc instead of …
girarda 9be956c
merge master
girarda 2cdcc4e
format
girarda 69f5fb7
fix merge
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 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# | ||
|
||
from dataclasses import InitVar, dataclass | ||
from typing import Any, List, Mapping, MutableMapping, Optional, Union | ||
from typing import Any, Mapping, MutableMapping, Optional, Union | ||
|
||
import requests | ||
from airbyte_cdk.sources.declarative.decoders.decoder import Decoder | ||
|
@@ -101,8 +101,10 @@ def __post_init__(self, parameters: Mapping[str, Any]) -> None: | |
self.url_base = InterpolatedString(string=self.url_base, parameters=parameters) | ||
self._token = self.pagination_strategy.initial_token | ||
|
||
def next_page_token(self, response: requests.Response, last_records: List[Record]) -> Optional[Mapping[str, Any]]: | ||
self._token = self.pagination_strategy.next_page_token(response, last_records) | ||
def next_page_token( | ||
self, response: requests.Response, last_page_size: int, last_record: Optional[Record] | ||
) -> Optional[Mapping[str, Any]]: | ||
self._token = self.pagination_strategy.next_page_token(response, last_page_size, last_record) | ||
if self._token: | ||
return {"next_page_token": self._token} | ||
else: | ||
|
@@ -164,9 +166,9 @@ def _get_request_options(self, option_type: RequestOptionType) -> MutableMapping | |
and isinstance(self.page_token_option, RequestOption) | ||
and self.page_token_option.inject_into == option_type | ||
): | ||
options[self.page_token_option.field_name.eval(config=self.config)] = self._token | ||
options[self.page_token_option.field_name.eval(config=self.config)] = self._token # type: ignore # field_name is known to be an interpolated string | ||
if self.page_size_option and self.pagination_strategy.get_page_size() and self.page_size_option.inject_into == option_type: | ||
options[self.page_size_option.field_name.eval(config=self.config)] = self.pagination_strategy.get_page_size() | ||
options[self.page_size_option.field_name.eval(config=self.config)] = self.pagination_strategy.get_page_size() # type: ignore # field_name is known to be an interpolated string | ||
return options | ||
|
||
|
||
|
@@ -185,12 +187,14 @@ def __init__(self, decorated: Paginator, maximum_number_of_pages: int = 5) -> No | |
self._decorated = decorated | ||
self._page_count = self._PAGE_COUNT_BEFORE_FIRST_NEXT_CALL | ||
|
||
def next_page_token(self, response: requests.Response, last_records: List[Record]) -> Optional[Mapping[str, Any]]: | ||
def next_page_token( | ||
self, response: requests.Response, last_page_size: int, last_record: Optional[Record] | ||
) -> Optional[Mapping[str, Any]]: | ||
if self._page_count >= self._maximum_number_of_pages: | ||
return None | ||
|
||
self._page_count += 1 | ||
return self._decorated.next_page_token(response, last_records) | ||
return self._decorated.next_page_token(response, last_page_size, last_record) | ||
|
||
def path(self) -> Optional[str]: | ||
return self._decorated.path() | ||
|
@@ -201,7 +205,7 @@ def get_request_params( | |
stream_state: Optional[StreamState] = None, | ||
stream_slice: Optional[StreamSlice] = None, | ||
next_page_token: Optional[Mapping[str, Any]] = None, | ||
) -> MutableMapping[str, Any]: | ||
) -> Mapping[str, Any]: | ||
return self._decorated.get_request_params(stream_state=stream_state, stream_slice=stream_slice, next_page_token=next_page_token) | ||
|
||
def get_request_headers( | ||
|
@@ -219,7 +223,7 @@ def get_request_body_data( | |
stream_state: Optional[StreamState] = None, | ||
stream_slice: Optional[StreamSlice] = None, | ||
next_page_token: Optional[Mapping[str, Any]] = None, | ||
) -> Optional[Union[Mapping[str, Any], str]]: | ||
) -> Union[Mapping[str, Any], str]: | ||
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. this never returns |
||
return self._decorated.get_request_body_data(stream_state=stream_state, stream_slice=stream_slice, next_page_token=next_page_token) | ||
|
||
def get_request_body_json( | ||
|
@@ -228,7 +232,7 @@ def get_request_body_json( | |
stream_state: Optional[StreamState] = None, | ||
stream_slice: Optional[StreamSlice] = None, | ||
next_page_token: Optional[Mapping[str, Any]] = None, | ||
) -> Optional[Mapping[str, Any]]: | ||
) -> Mapping[str, Any]: | ||
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. this never returns |
||
return self._decorated.get_request_body_json(stream_state=stream_state, stream_slice=stream_slice, next_page_token=next_page_token) | ||
|
||
def reset(self) -> None: | ||
|
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.
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.
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.
sigh i hate these so much