Skip to content
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

CDK Lowcode: allow parametrizing initial page when using PageIncrement #19712

Merged
merged 3 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.9.6
Low-code: Add `start_from_page` option to a PageIncrement class

## 0.9.5
Low-code: Add jinja macro `format_datetime`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,9 @@
"properties": {
"page_size": {
"type": "integer"
},
"start_from_page": {
"type": "integer"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class PageIncrement(PaginationStrategy, JsonSchemaMixin):

Attributes:
page_size (int): the number of records to request
start_from_page (int): number of the initial page
"""

page_size: int
options: InitVar[Mapping[str, Any]]
start_from_page: int = 0

def __post_init__(self, options: Mapping[str, Any]):
self._page = 0
self._page = self.start_from_page

def next_page_token(self, response: requests.Response, last_records: List[Mapping[str, Any]]) -> Optional[Any]:
if len(last_records) < self.page_size:
Expand All @@ -33,7 +35,7 @@ def next_page_token(self, response: requests.Response, last_records: List[Mappin
return self._page

def reset(self):
self._page = 0
self._page = self.start_from_page

def get_page_size(self) -> Optional[int]:
return self.page_size
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.9.5",
version="0.9.6",
davydov-d marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -10,15 +10,17 @@


@pytest.mark.parametrize(
"test_name, page_size, expected_next_page_token, expected_offset",
"test_name, page_size, start_from, expected_next_page_token, expected_offset",
[
("test_same_page_size", 2, 1, 1),
("test_larger_page_size", 3, None, 0),
("test_same_page_size_start_from_0", 2, 1, 2, 2),
("test_larger_page_size_start_from_0", 3, 1, None, 1),
("test_same_page_size_start_from_1", 2, 0, 1, 1),
("test_larger_page_size_start_from_0", 3, 0, None, 0)
],
)
def test_page_increment_paginator_strategy(test_name, page_size, expected_next_page_token, expected_offset):
paginator_strategy = PageIncrement(page_size, options={})
assert paginator_strategy._page == 0
def test_page_increment_paginator_strategy(test_name, page_size, start_from, expected_next_page_token, expected_offset):
paginator_strategy = PageIncrement(page_size, options={}, start_from_page=start_from)
assert paginator_strategy._page == start_from

response = requests.Response()

Expand All @@ -32,4 +34,4 @@ def test_page_increment_paginator_strategy(test_name, page_size, expected_next_p
assert expected_offset == paginator_strategy._page

paginator_strategy.reset()
assert 0 == paginator_strategy._page
assert start_from == paginator_strategy._page