Skip to content

Commit 2bb068f

Browse files
authored
chore: add experiment blob read_gbq_object_table (#1324)
* chore: add experiment blob read_gbq_object_table * fix unit
1 parent f3061f8 commit 2bb068f

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

bigframes/pandas/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
read_gbq,
4343
read_gbq_function,
4444
read_gbq_model,
45+
read_gbq_object_table,
4546
read_gbq_query,
4647
read_gbq_table,
4748
read_json,
@@ -306,6 +307,7 @@ def reset_session():
306307
"read_gbq",
307308
"read_gbq_function",
308309
"read_gbq_model",
310+
"read_gbq_object_table",
309311
"read_gbq_query",
310312
"read_gbq_table",
311313
"read_json",

bigframes/pandas/io/api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ def read_gbq_model(model_name: str):
193193
read_gbq_model.__doc__ = inspect.getdoc(bigframes.session.Session.read_gbq_model)
194194

195195

196+
def read_gbq_object_table(
197+
object_table: str, *, name: Optional[str] = None
198+
) -> bigframes.dataframe.DataFrame:
199+
return global_session.with_default_session(
200+
bigframes.session.Session.read_gbq_object_table,
201+
object_table,
202+
name=name,
203+
)
204+
205+
206+
read_gbq_object_table.__doc__ = inspect.getdoc(
207+
bigframes.session.Session.read_gbq_object_table
208+
)
209+
210+
196211
def read_gbq_query(
197212
query: str,
198213
*,

bigframes/session/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,9 @@ def from_glob_path(
16251625
) -> dataframe.DataFrame:
16261626
r"""Create a BigFrames DataFrame that contains a BigFrames Blob column from a global wildcard path.
16271627
1628+
.. note::
1629+
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
1630+
16281631
Args:
16291632
path (str):
16301633
The wildcard global path, such as "gs://<bucket>/<folder>/\*".
@@ -1641,6 +1644,7 @@ def from_glob_path(
16411644
if not bigframes.options.experiments.blob:
16421645
raise NotImplementedError()
16431646

1647+
# TODO(garrettwu): switch to pseudocolumn when b/374988109 is done.
16441648
connection = connection or self._bq_connection
16451649
connection = bigframes.clients.resolve_full_bq_connection_name(
16461650
connection,
@@ -1653,6 +1657,33 @@ def from_glob_path(
16531657
s = self.read_gbq(table)["uri"].str.to_blob(connection)
16541658
return s.rename(name).to_frame()
16551659

1660+
def read_gbq_object_table(
1661+
self, object_table: str, *, name: Optional[str] = None
1662+
) -> dataframe.DataFrame:
1663+
"""Read an existing object table to create a BigFrames Blob DataFrame. Use the connection of the object table for the connection of the blob.
1664+
This function dosen't retrieve the object table data. If you want to read the data, use read_gbq() instead.
1665+
1666+
.. note::
1667+
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
1668+
1669+
Args:
1670+
object_table (str): name of the object table of form <PROJECT_ID>.<DATASET_ID>.<TABLE_ID>.
1671+
name (str or None): the returned blob column name.
1672+
1673+
Returns:
1674+
bigframes.pandas.DataFrame:
1675+
Result BigFrames DataFrame.
1676+
"""
1677+
if not bigframes.options.experiments.blob:
1678+
raise NotImplementedError()
1679+
1680+
# TODO(garrettwu): switch to pseudocolumn when b/374988109 is done.
1681+
table = self.bqclient.get_table(object_table)
1682+
connection = table._properties["externalDataConfiguration"]["connectionId"]
1683+
1684+
s = self.read_gbq(object_table)["uri"].str.to_blob(connection)
1685+
return s.rename(name).to_frame()
1686+
16561687

16571688
def connect(context: Optional[bigquery_options.BigQueryOptions] = None) -> Session:
16581689
return Session(context)

0 commit comments

Comments
 (0)