Skip to content

Commit

Permalink
refactor: Experiment with default offset paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Feb 5, 2024
1 parent 2b97aa0 commit e5d11d0
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 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 Down Expand Up @@ -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 e5d11d0

Please sign in to comment.