Skip to content

Commit

Permalink
refactor: Use the default offset paginator (#265)
Browse files Browse the repository at this point in the history
Should be possible with meltano/sdk#1918
  • Loading branch information
edgarrmondragon authored Jul 10, 2024
1 parent 74e03eb commit 88bc922
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions tap_dbt/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,9 @@

from tap_dbt.client import DBTStream

if t.TYPE_CHECKING:
import requests

SCHEMAS_DIR = Path(__file__).parent / Path("./schemas")


class DbtPaginator(BaseOffsetPaginator):
"""dbt API paginator."""

def has_more(self, response: requests.Response) -> bool:
"""Returns True until there are no more pages to retrieve.
The API returns an 'extra' key with information about pagination:
"extra":{"filters":{"limit":100,"offset":2,"account_id":1},"order_by":"id","pagination":{"count":100,"total_count":209}}}
"""
data = response.json()
extra = data.get("extra", {})
filters = extra.get("filters", {})
pagination = extra.get("pagination", {})

offset = filters.get("offset", 0)
total_count = pagination.get("total_count")
count = pagination.get("count")

# The pagination has more records when:
# total_count is still greater than count and offset combined
return count + offset < total_count


class AccountBasedStream(DBTStream):
"""A stream that requires an account ID."""

Expand All @@ -59,7 +33,7 @@ def partitions(self) -> list[dict]:
)
raise ValueError(errmsg)

def get_new_paginator(self) -> DbtPaginator:
def get_new_paginator(self) -> BaseOffsetPaginator:
"""Return a new paginator instance for this stream."""
page_size = self.config["page_size"]

Expand All @@ -68,7 +42,7 @@ def get_new_paginator(self) -> DbtPaginator:
page_size,
)

return DbtPaginator(start_value=0, page_size=page_size)
return BaseOffsetPaginator(start_value=0, page_size=page_size)

def get_url_params(
self,
Expand Down

0 comments on commit 88bc922

Please sign in to comment.