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
1 change: 1 addition & 0 deletions paimon-python/pypaimon/filesystem/local_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def __init__(self, file_path: Path, original_path: str):
stat_info = file_path.stat()
self.path = str(file_path.absolute())
self.original_path = original_path
self.base_name = os.path.basename(original_path)
self.size = stat_info.st_size if file_path.is_file() else None
self.type = (
pyarrow.fs.FileType.Directory if file_path.is_dir()
Expand Down
10 changes: 10 additions & 0 deletions paimon-python/pypaimon/table/file_store_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ def delete_tag(self, tag_name: str) -> bool:
tag_mgr = self.tag_manager()
return tag_mgr.delete_tag(tag_name)

def list_tag(self):
"""
List all tags.

Returns:
List of name of tag
"""
tag_mgr = self.tag_manager()
return tag_mgr.list_tag()

def path_factory(self) -> 'FileStorePathFactory':
from pypaimon.utils.file_store_path_factory import FileStorePathFactory

Expand Down
18 changes: 18 additions & 0 deletions paimon-python/pypaimon/tag/tag_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import logging
import os
from typing import Optional

from pypaimon.common.file_io import FileIO
Expand Down Expand Up @@ -140,6 +141,23 @@ def create_tag(

self._create_or_replace_tag(snapshot, tag_name)

def list_tag(self):
"""List all tags."""
result = []
for tag_file in self.file_io.list_status(self.tag_directory()):
tag_file_name = None
if hasattr(tag_file, 'base_name'):
tag_file_name = tag_file.base_name
else:
try:
tag_file_name = os.path.basename(tag_file)
except TypeError:
tag_file_name = None
if tag_file_name is not None:
_, tag = tag_file_name.split("-", 1)
result.append(tag)
return result

def _create_or_replace_tag(
self,
snapshot: Snapshot,
Expand Down
19 changes: 19 additions & 0 deletions paimon-python/pypaimon/tests/table/simple_table_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,29 @@ def test_tag_create_and_delete(self):
self.assertIsNotNone(tag)
self.assertEqual(tag.id, 1)

table_write = write_builder.new_write()
table_commit = write_builder.new_commit()
data = pa.Table.from_pydict({
'pt': [1, 1],
'k': [10, 20],
'v': [100, 200]
}, schema=self.pa_schema)
table_write.write_arrow(data)
table_commit.commit(table_write.prepare_commit())
table_write.close()
table_commit.close()

table.create_tag("test_tag_2")
all_tags = set(table.list_tag())
self.assertEqual(all_tags, {"test_tag", "test_tag_2"})

# Delete the tag
result = table.delete_tag("test_tag")
self.assertTrue(result)

all_tags = table.list_tag()
self.assertEqual(all_tags, ["test_tag_2"])

# Verify tag no longer exists
self.assertFalse(tag_manager.tag_exists("test_tag"))

Expand Down