Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(python): add experimental parameter enable_move_stable_row_ids for pylance #3216

Merged
merged 1 commit into from
Dec 9, 2024
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
17 changes: 14 additions & 3 deletions python/python/lance/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,13 @@ def __getstate__(self):
)

def __setstate__(self, state):
self._uri, self._storage_options, version, manifest, default_scan_options = (
state
)
(
self._uri,
self._storage_options,
version,
manifest,
default_scan_options,
) = state
self._ds = _Dataset(
self._uri,
version,
Expand Down Expand Up @@ -3409,6 +3413,7 @@ def write_dataset(
data_storage_version: Optional[str] = None,
use_legacy_format: Optional[bool] = None,
enable_v2_manifest_paths: bool = False,
enable_move_stable_row_ids: bool = False,
) -> LanceDataset:
"""Write a given data_obj to the given uri

Expand Down Expand Up @@ -3462,6 +3467,11 @@ def write_dataset(
versions on object stores. This parameter has no effect if the dataset
already exists. To migrate an existing dataset, instead use the
:meth:`LanceDataset.migrate_manifest_paths_v2` method. Default is False.
enable_move_stable_row_ids : bool, optional
Experimental parameter: if set to true, the writer will use move-stable row ids.
These row ids are stable after compaction operations, but not after updates.
This makes compaction more efficient, since with stable row ids no
secondary indices need to be updated to point to new row ids.
"""
if use_legacy_format is not None:
warnings.warn(
Expand Down Expand Up @@ -3495,6 +3505,7 @@ def write_dataset(
"storage_options": storage_options,
"data_storage_version": data_storage_version,
"enable_v2_manifest_paths": enable_v2_manifest_paths,
"enable_move_stable_row_ids": enable_move_stable_row_ids,
}

if commit_lock:
Expand Down
35 changes: 35 additions & 0 deletions python/python/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,41 @@ def test_asof_checkout(tmp_path: Path):
assert len(ds.to_table()) == 9


def test_enable_move_stable_row_ids(tmp_path: Path):
table = pa.Table.from_pylist(
[{"name": "Alice", "age": 20}, {"name": "Bob", "age": 30}]
)
lance.write_dataset(table, tmp_path, enable_move_stable_row_ids=True)
ds = lance.write_dataset(
table, tmp_path, enable_move_stable_row_ids=True, mode="append"
)
table_before = ds.scanner(with_row_id=True, with_row_address=True).to_table()
assert len(table_before) == 4
assert table_before["_rowid"][0].as_py() == 0
assert table_before["_rowid"][1].as_py() == 1
assert table_before["_rowid"][2].as_py() == 2
assert table_before["_rowid"][3].as_py() == 3

assert table_before["_rowaddr"][0].as_py() == 0
assert table_before["_rowaddr"][1].as_py() == 1
assert table_before["_rowaddr"][2].as_py() == (1 << 32) + 0
assert table_before["_rowaddr"][3].as_py() == (1 << 32) + 1

ds.optimize.compact_files()

table_after = ds.scanner(with_row_id=True, with_row_address=True).to_table()
assert len(table_after) == 4
assert table_after["_rowid"][0].as_py() == 0
assert table_after["_rowid"][1].as_py() == 1
assert table_after["_rowid"][2].as_py() == 2
assert table_after["_rowid"][3].as_py() == 3

assert table_after["_rowaddr"][0].as_py() == (2 << 32) + 0
assert table_after["_rowaddr"][1].as_py() == (2 << 32) + 1
assert table_after["_rowaddr"][2].as_py() == (2 << 32) + 2
assert table_after["_rowaddr"][3].as_py() == (2 << 32) + 3


def test_v2_manifest_paths(tmp_path: Path):
lance.write_dataset(
pa.table({"a": range(100)}), tmp_path, enable_v2_manifest_paths=True
Expand Down
5 changes: 5 additions & 0 deletions python/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,11 @@ pub fn get_write_params(options: &PyDict) -> PyResult<Option<WriteParams>> {
});
}

if let Some(enable_move_stable_row_ids) =
get_dict_opt::<bool>(options, "enable_move_stable_row_ids")?
{
p.enable_move_stable_row_ids = enable_move_stable_row_ids;
}
if let Some(enable_v2_manifest_paths) =
get_dict_opt::<bool>(options, "enable_v2_manifest_paths")?
{
Expand Down
Loading