Skip to content

Commit ca167a2

Browse files
committed
fix: expose ref metadata in bindings
1 parent 0f08160 commit ca167a2

File tree

4 files changed

+72
-17
lines changed

4 files changed

+72
-17
lines changed

java/src/main/java/org/lance/Dataset.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,23 +1334,6 @@ public Map<String, String> getConfig() {
13341334

13351335
private native Map<String, String> nativeGetConfig();
13361336

1337-
/**
1338-
* Check whether the dataset uses stable row IDs.
1339-
*
1340-
* <p>Stable row IDs remain constant when rows are moved during compaction. This reads the
1341-
* manifest feature flag directly rather than the user-facing config map.
1342-
*
1343-
* @return true if the dataset was created with stable row IDs enabled
1344-
*/
1345-
public boolean hasStableRowIds() {
1346-
try (LockManager.ReadLock readLock = lockManager.acquireReadLock()) {
1347-
Preconditions.checkArgument(nativeDatasetHandle != 0, "Dataset is closed");
1348-
return nativeHasStableRowIds();
1349-
}
1350-
}
1351-
1352-
private native boolean nativeHasStableRowIds();
1353-
13541337
/**
13551338
* Get the Lance file format version of this dataset.
13561339
*
@@ -1703,6 +1686,14 @@ public void update(String tag, Ref ref) {
17031686
}
17041687
}
17051688

1689+
public void updateMetadata(String tag, Optional<String> metadata) {
1690+
Preconditions.checkArgument(tag != null, "tag cannot be null");
1691+
try (LockManager.WriteLock writeLock = lockManager.acquireWriteLock()) {
1692+
Preconditions.checkArgument(nativeDatasetHandle != 0, "Dataset is closed");
1693+
nativeUpdateTagMetadata(tag, metadata);
1694+
}
1695+
}
1696+
17061697
/**
17071698
* List all tags of the dataset.
17081699
*
@@ -1755,6 +1746,14 @@ public List<Branch> list() {
17551746
return nativeListBranches();
17561747
}
17571748
}
1749+
1750+
public void updateMetadata(String branchName, Optional<String> metadata) {
1751+
Preconditions.checkArgument(branchName != null, "branchName cannot be null");
1752+
try (LockManager.WriteLock writeLock = lockManager.acquireWriteLock()) {
1753+
Preconditions.checkArgument(nativeDatasetHandle != 0, "Dataset is closed");
1754+
nativeUpdateBranchMetadata(branchName, metadata);
1755+
}
1756+
}
17581757
}
17591758

17601759
/**
@@ -1840,6 +1839,8 @@ private native MergeInsertResult nativeMergeInsert(
18401839

18411840
private native void nativeUpdateTag(String tag, Ref ref);
18421841

1842+
private native void nativeUpdateTagMetadata(String tag, Optional<String> metadata);
1843+
18431844
private native List<Tag> nativeListTags();
18441845

18451846
private native long nativeGetVersionByTag(String tag);
@@ -1854,6 +1855,8 @@ private native Dataset nativeCreateBranch(
18541855

18551856
private native List<Branch> nativeListBranches();
18561857

1858+
private native void nativeUpdateBranchMetadata(String branch, Optional<String> metadata);
1859+
18571860
public Dataset shallowClone(String targetPath, Ref ref) {
18581861
return shallowClone(targetPath, ref, null);
18591862
}

python/python/lance/lance/__init__.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ class _Dataset:
346346
tag: str,
347347
reference: Optional[int | str | Tuple[Optional[str], Optional[int]]] = None,
348348
): ...
349+
def update_tag_metadata(
350+
self,
351+
tag: str,
352+
metadata: Optional[str] = None,
353+
) -> None: ...
349354
# Branch operations
350355
def branches(self) -> Dict[str, Branch]: ...
351356
def branches_ordered(self, order: Optional[str]) -> List[Tuple[str, Branch]]: ...
@@ -357,6 +362,11 @@ class _Dataset:
357362
**kwargs,
358363
) -> _Dataset: ...
359364
def delete_branch(self, branch: str) -> None: ...
365+
def update_branch_metadata(
366+
self,
367+
branch: str,
368+
metadata: Optional[str] = None,
369+
) -> None: ...
360370
def optimize_indices(self, **kwargs): ...
361371
def create_index(
362372
self,

python/python/tests/test_dataset.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ def test_tag(tmp_path: Path):
471471
ds.tags.delete("tag1")
472472

473473
ds.tags.create("tag1", 1)
474+
ds.tags.update_metadata("tag1", metadata="first tag")
474475
assert len(ds.tags.list()) == 1
476+
assert ds.tags.list()["tag1"]["metadata"] == "first tag"
475477

476478
with pytest.raises(ValueError):
477479
ds.tags.create("tag1", 1)
@@ -505,13 +507,25 @@ def test_tag(tmp_path: Path):
505507
):
506508
ds.tags.update("tag3", 1)
507509

510+
ds.tags.update_metadata("tag1", metadata="updated tag")
511+
ds = lance.dataset(base_dir, "tag1")
512+
assert ds.version == 1
513+
assert ds.tags.list()["tag1"]["metadata"] == "updated tag"
514+
508515
ds.tags.update("tag1", 2)
509516
ds = lance.dataset(base_dir, "tag1")
510517
assert ds.version == 2
518+
assert ds.tags.list()["tag1"]["metadata"] == "updated tag"
519+
520+
ds.tags.update_metadata("tag1", metadata=None)
521+
ds = lance.dataset(base_dir, "tag1")
522+
assert ds.version == 2
523+
assert ds.tags.list()["tag1"]["metadata"] is None
511524

512525
ds.tags.update("tag1", 1)
513526
ds = lance.dataset(base_dir, "tag1")
514527
assert ds.version == 1
528+
assert ds.tags.list()["tag1"]["metadata"] is None
515529

516530
version = ds.tags.get_version("tag1")
517531
assert version == 1
@@ -5213,6 +5227,7 @@ def test_branches(tmp_path: Path):
52135227
ds_main = lance.write_dataset(main_table, base_dir)
52145228

52155229
branch1 = ds_main.create_branch("branch1")
5230+
ds_main.branches.update_metadata("branch1", "branch one")
52165231
assert branch1.version == 1
52175232
branch1_append = pa.Table.from_pydict({"a": [7, 8], "b": [9, 10]})
52185233
branch1 = lance.write_dataset(branch1_append, branch1, mode="append")
@@ -5262,6 +5277,7 @@ def test_branches(tmp_path: Path):
52625277
assert isinstance(b1_meta["parent_version"], int)
52635278
assert b1_meta["manifest_size"] > 0
52645279
assert "create_at" in b1_meta
5280+
assert b1_meta["metadata"] == "branch one"
52655281

52665282
try:
52675283
ds_main.checkout_version("branch_not_exists")

python/src/dataset.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,7 @@ impl Dataset {
16821682
let dict = PyDict::new(py);
16831683
dict.set_item("version", tag_content.version)?;
16841684
dict.set_item("manifest_size", tag_content.manifest_size)?;
1685+
dict.set_item("metadata", tag_content.metadata.clone())?;
16851686

16861687
pylist.append((tag_name.as_str(), dict))?;
16871688
}
@@ -1699,6 +1700,7 @@ impl Dataset {
16991700
dict.set_item("branch", v.branch.clone())?;
17001701
dict.set_item("version", v.version)?;
17011702
dict.set_item("manifest_size", v.manifest_size)?;
1703+
dict.set_item("metadata", v.metadata.clone())?;
17021704
pytags.set_item(k, dict.into_py_any(py)?)?;
17031705
}
17041706
pytags.into_py_any(py)
@@ -1754,6 +1756,16 @@ impl Dataset {
17541756
Ok(())
17551757
}
17561758

1759+
#[pyo3(signature = (tag, metadata=None))]
1760+
fn update_tag_metadata(&self, tag: String, metadata: Option<String>) -> PyResult<()> {
1761+
rt().block_on(
1762+
None,
1763+
self.ds.as_ref().tags().update_metadata(&tag, metadata),
1764+
)?
1765+
.infer_error()?;
1766+
Ok(())
1767+
}
1768+
17571769
/// Check out the latest version of the current branch
17581770
fn checkout_latest(&mut self) -> PyResult<()> {
17591771
let mut new_self = self.ds.as_ref().clone();
@@ -1821,11 +1833,25 @@ impl Dataset {
18211833
dict.set_item("parent_version", meta.parent_version)?;
18221834
dict.set_item("create_at", meta.create_at)?;
18231835
dict.set_item("manifest_size", meta.manifest_size)?;
1836+
dict.set_item("metadata", meta.metadata.clone())?;
18241837
pybranches.set_item(name, dict.into_py_any(py)?)?;
18251838
}
18261839
Ok(pybranches.into())
18271840
}
18281841

1842+
#[pyo3(signature = (branch, metadata=None))]
1843+
fn update_branch_metadata(&self, branch: String, metadata: Option<String>) -> PyResult<()> {
1844+
rt().block_on(
1845+
None,
1846+
self.ds
1847+
.as_ref()
1848+
.branches()
1849+
.update_metadata(&branch, metadata),
1850+
)?
1851+
.infer_error()?;
1852+
Ok(())
1853+
}
1854+
18291855
/// List branches ordered by parent_version
18301856
fn branches_ordered(
18311857
&self,

0 commit comments

Comments
 (0)