-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Truncate the table if the size exceeds more then 2GB
- Loading branch information
1 parent
3d9ae37
commit 2ed1a10
Showing
2 changed files
with
48 additions
and
3 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
41 changes: 41 additions & 0 deletions
41
deltacat/tests/compute/compactor_v2/utils/test_primary_key_index.py
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,41 @@ | ||
import pyarrow as pa | ||
from deltacat.compute.compactor_v2.utils.primary_key_index import ( | ||
group_by_pk_hash_bucket, | ||
) | ||
|
||
|
||
class TestGroupByPkHashBucket: | ||
def test_sanity(self): | ||
record = pa.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) | ||
pk = pa.array(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]) | ||
record_batch = pa.RecordBatch.from_arrays([record, pk], names=["record", "pk"]) | ||
table = pa.Table.from_batches([record_batch]) | ||
grouped_array = group_by_pk_hash_bucket(table, 3, ["pk"]) | ||
|
||
assert len(grouped_array) == 3 | ||
total_records = 0 | ||
for arr in grouped_array: | ||
if arr is not None: | ||
total_records += len(arr[1]) | ||
|
||
assert total_records == len(table) | ||
|
||
def test_when_record_batches_exceed_int_max_size(self): | ||
record = pa.array(["12bytestring" * 90_000_000]) | ||
record_batch = pa.RecordBatch.from_arrays([record], names=["pk"]) | ||
table = pa.Table.from_batches([record_batch, record_batch]) | ||
|
||
grouped_array = group_by_pk_hash_bucket(table, 3, ["pk"]) | ||
|
||
assert len(grouped_array) == 3 | ||
assert len(grouped_array[2].to_batches()) == 2 # two record batches preserved | ||
|
||
def test_when_record_batches_less_than_int_max_size(self): | ||
record = pa.array(["12bytestring" * 90_000]) | ||
record_batch = pa.RecordBatch.from_arrays([record], names=["pk"]) | ||
table = pa.Table.from_batches([record_batch, record_batch]) | ||
|
||
grouped_array = group_by_pk_hash_bucket(table, 3, ["pk"]) | ||
|
||
assert len(grouped_array) == 3 | ||
assert len(grouped_array[1].to_batches()) == 1 # truncated to one record batch |