Skip to content

Commit

Permalink
Merge branch 'main' into b338873783-matrix-factorization
Browse files Browse the repository at this point in the history
  • Loading branch information
rey-esp committed Jan 28, 2025
2 parents dedef39 + 2bb068f commit e5165a9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bigframes/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
read_gbq,
read_gbq_function,
read_gbq_model,
read_gbq_object_table,
read_gbq_query,
read_gbq_table,
read_json,
Expand Down Expand Up @@ -306,6 +307,7 @@ def reset_session():
"read_gbq",
"read_gbq_function",
"read_gbq_model",
"read_gbq_object_table",
"read_gbq_query",
"read_gbq_table",
"read_json",
Expand Down
15 changes: 15 additions & 0 deletions bigframes/pandas/io/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ def read_gbq_model(model_name: str):
read_gbq_model.__doc__ = inspect.getdoc(bigframes.session.Session.read_gbq_model)


def read_gbq_object_table(
object_table: str, *, name: Optional[str] = None
) -> bigframes.dataframe.DataFrame:
return global_session.with_default_session(
bigframes.session.Session.read_gbq_object_table,
object_table,
name=name,
)


read_gbq_object_table.__doc__ = inspect.getdoc(
bigframes.session.Session.read_gbq_object_table
)


def read_gbq_query(
query: str,
*,
Expand Down
31 changes: 31 additions & 0 deletions bigframes/session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,9 @@ def from_glob_path(
) -> dataframe.DataFrame:
r"""Create a BigFrames DataFrame that contains a BigFrames Blob column from a global wildcard path.
.. note::
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
Args:
path (str):
The wildcard global path, such as "gs://<bucket>/<folder>/\*".
Expand All @@ -1641,6 +1644,7 @@ def from_glob_path(
if not bigframes.options.experiments.blob:
raise NotImplementedError()

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

def read_gbq_object_table(
self, object_table: str, *, name: Optional[str] = None
) -> dataframe.DataFrame:
"""Read an existing object table to create a BigFrames Blob DataFrame. Use the connection of the object table for the connection of the blob.
This function dosen't retrieve the object table data. If you want to read the data, use read_gbq() instead.
.. note::
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
Args:
object_table (str): name of the object table of form <PROJECT_ID>.<DATASET_ID>.<TABLE_ID>.
name (str or None): the returned blob column name.
Returns:
bigframes.pandas.DataFrame:
Result BigFrames DataFrame.
"""
if not bigframes.options.experiments.blob:
raise NotImplementedError()

# TODO(garrettwu): switch to pseudocolumn when b/374988109 is done.
table = self.bqclient.get_table(object_table)
connection = table._properties["externalDataConfiguration"]["connectionId"]

s = self.read_gbq(object_table)["uri"].str.to_blob(connection)
return s.rename(name).to_frame()


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

0 comments on commit e5165a9

Please sign in to comment.