Skip to content

Commit

Permalink
docs: document that parallelized resources usually produce one less t…
Browse files Browse the repository at this point in the history
…han the limit
  • Loading branch information
joscha committed Dec 12, 2024
1 parent 9a49868 commit b458594
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions dlt/extract/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ def add_limit(self: TDltResourceImpl, max_items: int) -> TDltResourceImpl: # no
1. Transformers won't be limited. They should process all the data they receive fully to avoid inconsistencies in generated datasets.
2. Each yielded item may contain several records. `add_limit` only limits the "number of yields", not the total number of records.
3. Async resources with a limit added may occasionally produce one item more than the limit on some runs. This behavior is not deterministic.
4. Parallelized sync resources with a limit added will usually produce one item less than the limit. This behavior is not deterministic.
Args:
max_items (int): The maximum number of items to yield
Expand Down
13 changes: 13 additions & 0 deletions tests/pipeline/test_resources_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ async def async_resource1():
assert len(result) == 13


@pytest.mark.parametrize("parallelized", [False, True])
def test_limit_sync_resource(parallelized: bool) -> None:
@dlt.resource(parallelized=parallelized)
def sync_resource1():
for i in range(1, 10):
yield i

limit = 5
result = list(sync_resource1().add_limit(limit))
allowed_result_range = range(limit - int(parallelized), limit + 1)
assert len(result) in allowed_result_range


@pytest.mark.parametrize("parallelized", [True, False])
def test_parallelized_resource(parallelized: bool) -> None:
os.environ["EXTRACT__NEXT_ITEM_MODE"] = "fifo"
Expand Down

0 comments on commit b458594

Please sign in to comment.