-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jay Chia
committed
Dec 5, 2023
1 parent
4def95c
commit 82271d5
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from __future__ import annotations | ||
|
||
import contextlib | ||
|
||
import pytest | ||
|
||
import daft | ||
|
||
|
||
@contextlib.contextmanager | ||
def override_merge_scan_tasks_configs(merge_scan_tasks_min_size_bytes: int, merge_scan_tasks_max_size_bytes: int): | ||
config = daft.context.get_context().daft_config | ||
original_merge_scan_tasks_min_size_bytes = config.merge_scan_tasks_min_size_bytes | ||
original_merge_scan_tasks_max_size_bytes = config.merge_scan_tasks_max_size_bytes | ||
|
||
try: | ||
daft.context.set_config( | ||
merge_scan_tasks_min_size_bytes=merge_scan_tasks_min_size_bytes, | ||
merge_scan_tasks_max_size_bytes=merge_scan_tasks_max_size_bytes, | ||
) | ||
yield | ||
finally: | ||
daft.context.set_config( | ||
merge_scan_tasks_min_size_bytes=original_merge_scan_tasks_min_size_bytes, | ||
merge_scan_tasks_max_size_bytes=original_merge_scan_tasks_max_size_bytes, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def csv_files(tmpdir): | ||
"""Writes 3 CSV files, each of 10 bytes in size, to tmpdir and yield tmpdir""" | ||
|
||
for i in range(3): | ||
path = tmpdir / f"file.{i}.csv" | ||
path.write_text("a,b,c\n1,2,", "utf8") # 10 bytes | ||
|
||
return tmpdir | ||
|
||
|
||
def test_merge_scan_task_exceed_max(csv_files): | ||
with override_merge_scan_tasks_configs(0, 0): | ||
df = daft.read_csv(str(csv_files)) | ||
assert ( | ||
df.num_partitions() == 3 | ||
), "Should have 3 partitions since all merges are more than the maximum (>0 bytes)" | ||
|
||
|
||
def test_merge_scan_task_below_max(csv_files): | ||
with override_merge_scan_tasks_configs(1, 20): | ||
df = daft.read_csv(str(csv_files)) | ||
assert ( | ||
df.num_partitions() == 2 | ||
), "Should have 2 partitions [(CSV1, CSV2), (CSV3)] since the second merge is too large (>20 bytes)" | ||
|
||
|
||
def test_merge_scan_task_above_min(csv_files): | ||
with override_merge_scan_tasks_configs(0, 40): | ||
df = daft.read_csv(str(csv_files)) | ||
assert ( | ||
df.num_partitions() == 2 | ||
), "Should have 2 partitions [(CSV1, CSV2), (CSV3)] since the first merge is above the minimum (>0 bytes)" | ||
|
||
|
||
def test_merge_scan_task_below_min(csv_files): | ||
with override_merge_scan_tasks_configs(35, 40): | ||
df = daft.read_csv(str(csv_files)) | ||
assert ( | ||
df.num_partitions() == 1 | ||
), "Should have 1 partition [(CSV1, CSV2, CSV3)] since both merges are below the minimum and maximum" |