ForeverAngry commented on issue #2222:
URL:
https://github.com/apache/iceberg-python/issues/2222#issuecomment-3093115176
I think this would probably require an update to the table `__init__.py`
file, soemthing like this:
```python
def scan_by_tag(
self,
tag_name: str,
row_filter: Union[str, BooleanExpression] = ALWAYS_TRUE,
selected_fields: Tuple[str, ...] = ("*",),
case_sensitive: bool = True,
options: Properties = EMPTY_DICT,
limit: Optional[int] = None,
) -> DataScan:
"""
Fetch a DataScan for the snapshot referenced by the given tag.
Args:
tag_name: Name of the tag to scan
row_filter: A string or BooleanExpression that describes the
desired rows
selected_fields: A tuple of strings representing the column
names to return
case_sensitive: If True column matching is case sensitive
options: Additional Table properties as a dictionary of string
key value pairs
limit: An integer representing the number of rows to return
Returns:
A DataScan for the snapshot referenced by the given tag
Raises:
ValueError: If the tag does not exist or is not a valid tag
"""
snapshot_id = self.get_snapshot_id_by_tag(tag_name)
return self.scan(
row_filter=row_filter,
selected_fields=selected_fields,
case_sensitive=case_sensitive,
snapshot_id=snapshot_id,
options=options,
limit=limit,
)
def get_snapshot_id_by_tag(self, tag_name: str) -> int:
"""
Get the snapshot ID associated with a given tag.
Args:
tag_name (str): The name of the tag.
Returns:
int: The snapshot ID associated with the tag.
Raises:
ValueError: If the tag does not exist or is not a valid tag.
"""
ref = self._transaction.table_metadata.refs.get(tag_name)
if ref is None or ref.snapshot_ref_type != SnapshotRefType.TAG:
raise ValueError(f"Tag '{tag_name}' does not exist or is not a
valid tag.")
return ref.snapshot_id
```
@kevinjqliu @jayceslesar any thoughts?
Im happy to add it, if it would be helpful.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]