Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions lance_ray/compaction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from collections.abc import Callable
from typing import Any, Optional, cast
from typing import Any, Optional

import lance
from lance.lance import CompactionMetrics
Expand Down Expand Up @@ -139,13 +139,7 @@ def compact_files(
logger.info("Starting distributed compaction")

# Step 1: Create the compaction plan
# Compaction.plan requires a dict; CompactionOptions is a TypedDict, so
# an empty instance stands in for "all defaults" when the caller omits it.
# It is declared with ``total=True`` upstream even though every key is
# optional at runtime, hence the cast instead of ``CompactionOptions()``.
compaction_plan = Compaction.plan(
dataset, compaction_options or cast(CompactionOptions, {})
)
compaction_plan = Compaction.plan(dataset, compaction_options or {})

logger.info(f"Compaction plan created with {compaction_plan.num_tasks()} tasks")

Expand Down
30 changes: 10 additions & 20 deletions tests/test_distributed_compaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import tempfile
from collections.abc import Iterator
from pathlib import Path
from typing import Any, cast
from unittest.mock import MagicMock, patch

import lance
Expand All @@ -22,15 +21,6 @@ def temp_dir() -> Iterator[str]:
yield temp_dir


def _compaction_options(**options: Any) -> CompactionOptions:
"""Build a partial ``CompactionOptions``.

pylance declares the TypedDict as total even though every key is optional
at runtime, so a partial literal cannot be spelled out directly.
"""
return cast(CompactionOptions, options)


def create_dataset_with_fragments(
path: str | Path, fragment_data: list[pd.DataFrame]
) -> lance.LanceDataset:
Expand Down Expand Up @@ -95,7 +85,7 @@ def test_basic_compaction(self, temp_dir: str) -> None:
assert dataset.count_rows() == 20, "Should have 20 total rows"

# Configure compaction to merge fragments (target 100 rows per fragment)
compaction_options = _compaction_options(
compaction_options = CompactionOptions(
target_rows_per_fragment=100,
num_threads=1,
)
Expand Down Expand Up @@ -182,7 +172,7 @@ def test_deletion_compaction(self, temp_dir: str) -> None:
assert dataset.count_rows() == 11, "Should have 11 rows after deletion"

# Configure compaction to materialize deletions
compaction_options = _compaction_options(
compaction_options = CompactionOptions(
materialize_deletions=True,
materialize_deletions_threshold=0.5, # 50% threshold
num_threads=1,
Expand Down Expand Up @@ -230,7 +220,7 @@ def test_compaction_with_many_fragments(self, temp_dir: str) -> None:
assert dataset.count_rows() == 5000, "Should have 5000 total rows"

# Configure compaction to merge small fragments
compaction_options = _compaction_options(
compaction_options = CompactionOptions(
target_rows_per_fragment=20,
num_threads=1,
)
Expand Down Expand Up @@ -271,7 +261,7 @@ def test_compaction_no_work_needed(self, temp_dir: str) -> None:
assert len(dataset.get_fragments()) == 1, "Should start with 1 fragment"

# Configure compaction with target that matches current state
compaction_options = _compaction_options(
compaction_options = CompactionOptions(
target_rows_per_fragment=100,
num_threads=1,
)
Expand Down Expand Up @@ -307,7 +297,7 @@ def test_compaction_with_ray_remote_args(self, temp_dir: str) -> None:
create_dataset_with_fragments(dataset_path, [fragment1, fragment2])

# Configure compaction
compaction_options = _compaction_options(
compaction_options = CompactionOptions(
target_rows_per_fragment=100,
num_threads=1,
)
Expand Down Expand Up @@ -346,7 +336,7 @@ def test_compaction_with_storage_options(self, temp_dir: str) -> None:
create_dataset_with_fragments(dataset_path, [fragment1, fragment2])

# Configure compaction
compaction_options = _compaction_options(
compaction_options = CompactionOptions(
target_rows_per_fragment=100,
num_threads=1,
)
Expand Down Expand Up @@ -385,7 +375,7 @@ def test_compaction_auto_adjust_workers(self, temp_dir: str) -> None:
create_dataset_with_fragments(dataset_path, [fragment1, fragment2])

# Configure compaction
compaction_options = _compaction_options(
compaction_options = CompactionOptions(
target_rows_per_fragment=100,
num_threads=1,
)
Expand Down Expand Up @@ -430,7 +420,7 @@ def test_compaction_preserves_data(self, temp_dir: str) -> None:
)

# Configure and execute compaction
compaction_options = _compaction_options(
compaction_options = CompactionOptions(
target_rows_per_fragment=100,
num_threads=1,
)
Expand Down Expand Up @@ -503,7 +493,7 @@ def test_compaction_with_directory_namespace(self, temp_dir: str) -> None:
assert len(dataset.get_fragments()) == 2, "Should start with 2 fragments"
assert dataset.count_rows() == 20, "Should have 20 total rows"

compaction_options = _compaction_options(
compaction_options = CompactionOptions(
target_rows_per_fragment=100,
num_threads=1,
)
Expand Down Expand Up @@ -581,7 +571,7 @@ def test_compact_database_two_tables_both_compacted(self, temp_dir: str) -> None

database = ["compact_db"]
table_names = ["table_a", "table_b"]
compaction_options = _compaction_options(
compaction_options = CompactionOptions(
target_rows_per_fragment=100,
num_threads=1,
)
Expand Down
Loading