Skip to content

Commit aa9af88

Browse files
authored
chore: add experimental blob metadata functions (#1300)
1 parent aa2f73a commit aa9af88

File tree

1 file changed

+89
-6
lines changed

1 file changed

+89
-6
lines changed

bigframes/operations/blob.py

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,49 @@ def __init__(self, *args, **kwargs):
3434

3535
super().__init__(*args, **kwargs)
3636

37+
def uri(self) -> bigframes.series.Series:
38+
"""URIs of the Blob.
39+
40+
.. note::
41+
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
42+
43+
Returns:
44+
BigFrames Series: URIs as string."""
45+
s = bigframes.series.Series(self._block)
46+
47+
return s.struct.field("uri")
48+
49+
def authorizer(self) -> bigframes.series.Series:
50+
"""Authorizers of the Blob.
51+
52+
.. note::
53+
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
54+
55+
Returns:
56+
BigFrames Series: Autorithers(connection) as string."""
57+
s = bigframes.series.Series(self._block)
58+
59+
return s.struct.field("authorizer")
60+
61+
def version(self) -> bigframes.series.Series:
62+
"""Versions of the Blob.
63+
64+
.. note::
65+
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
66+
67+
Returns:
68+
BigFrames Series: Version as string."""
69+
# version must be retrived after fetching metadata
70+
return self._apply_unary_op(ops.obj_fetch_metadata_op).struct.field("version")
71+
3772
def metadata(self) -> bigframes.series.Series:
3873
"""Retrive the metadata of the Blob.
3974
4075
.. note::
4176
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
4277
4378
Returns:
44-
JSON: metadata of the Blob. Contains fields: content_type, md5_hash, size and updated(time)."""
79+
BigFrames Series: JSON metadata of the Blob. Contains fields: content_type, md5_hash, size and updated(time)."""
4580
details_json = self._apply_unary_op(ops.obj_fetch_metadata_op).struct.field(
4681
"details"
4782
)
@@ -56,12 +91,60 @@ def content_type(self) -> bigframes.series.Series:
5691
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
5792
5893
Returns:
59-
BigFrames Series: json-string of the content type."""
60-
metadata = self.metadata()
94+
BigFrames Series: string of the content type."""
95+
return (
96+
self.metadata()
97+
._apply_unary_op(ops.JSONValue(json_path="$.content_type"))
98+
.rename("content_type")
99+
)
100+
101+
def md5_hash(self) -> bigframes.series.Series:
102+
"""Retrive the md5 hash of the Blob.
103+
104+
.. note::
105+
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
106+
107+
Returns:
108+
BigFrames Series: string of the md5 hash."""
109+
return (
110+
self.metadata()
111+
._apply_unary_op(ops.JSONValue(json_path="$.md5_hash"))
112+
.rename("md5_hash")
113+
)
114+
115+
def size(self) -> bigframes.series.Series:
116+
"""Retrive the file size of the Blob.
117+
118+
.. note::
119+
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
120+
121+
Returns:
122+
BigFrames Series: file size in bytes."""
123+
return (
124+
self.metadata()
125+
._apply_unary_op(ops.JSONValue(json_path="$.size"))
126+
.rename("size")
127+
.astype("Int64")
128+
)
129+
130+
def updated(self) -> bigframes.series.Series:
131+
"""Retrive the updated time of the Blob.
132+
133+
.. note::
134+
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
135+
136+
Returns:
137+
BigFrames Series: updated time as UTC datetime."""
138+
import bigframes.pandas as bpd
139+
140+
updated = (
141+
self.metadata()
142+
._apply_unary_op(ops.JSONValue(json_path="$.updated"))
143+
.rename("updated")
144+
.astype("Int64")
145+
)
61146

62-
return metadata._apply_unary_op(
63-
ops.JSONValue(json_path="$.content_type")
64-
).rename("content_type")
147+
return bpd.to_datetime(updated, unit="us", utc=True)
65148

66149
def display(self, n: int = 3, *, content_type: str = ""):
67150
"""Display the blob content in the IPython Notebook environment. Only works for image type now.

0 commit comments

Comments
 (0)