Skip to content

Commit 46083bd

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
chore: offline store - pass credentials to bigframes session
PiperOrigin-RevId: 650355180
1 parent 7395665 commit 46083bd

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

tests/unit/vertexai/test_offline_store.py

+52
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,55 @@ def test_one_feature_with_explicit_project_and_location(
427427
)
428428

429429
assert rsp == "SOME SQL QUERY OUTPUT"
430+
431+
432+
def test_one_feature_with_explicit_credentials(
433+
mock_convert_to_bigquery_dataframe,
434+
mock_session,
435+
mock_fg,
436+
mock_feature,
437+
):
438+
entity_df = pd.DataFrame(
439+
[
440+
CUSTOMER_1_OLD_ENTITY_DF_ENTRY,
441+
CUSTOMER_2_OLD_ENTITY_DF_ENTRY,
442+
],
443+
columns=ENTITY_DF_COLUMNS,
444+
)
445+
446+
mock_convert_to_bigquery_dataframe.return_value = mock_bdf(
447+
non_ts_cols=["customer_id", "feature_1"],
448+
ts_cols=["timestamp"],
449+
sql=FAKE_ENTITY_DF_QUERY,
450+
)
451+
452+
mock_fg.return_value = create_mock_fg(
453+
name="fake", entity_id_cols=["customer_id"], bq_uri="bq://my.table"
454+
)
455+
mock_feature.return_value = create_mock_feature(
456+
name="my_feature", version_column_name="my_feature"
457+
)
458+
mock_fg.return_value.get_feature = mock_feature
459+
460+
mock_session.return_value.read_gbq_query.return_value = "SOME SQL QUERY OUTPUT"
461+
462+
credentials = mock.MagicMock()
463+
rsp = offline_store.fetch_historical_feature_values(
464+
entity_df=entity_df,
465+
features=["fake.my_feature"],
466+
credentials=credentials,
467+
)
468+
469+
# Ensure when initializing the session, the credentials are
470+
# passed through.
471+
mock_session.assert_called_once_with(
472+
bigframes.BigQueryOptions(
473+
credentials=credentials, project="my-project", location="my-location"
474+
),
475+
)
476+
mock_session.return_value.read_gbq_query.assert_called_once_with(
477+
expected_sql_for_one_feature("my_feature", "my_feature"),
478+
index_col=bigframes.enums.DefaultIndexKind.NULL,
479+
)
480+
481+
assert rsp == "SOME SQL QUERY OUTPUT"

vertexai/resources/preview/feature_store/offline_store.py

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import re
2020

2121
from typing import Optional, List, Tuple, Union, TYPE_CHECKING
22+
from google.auth import credentials as auth_credentials
2223
from vertexai.resources.preview.feature_store import (
2324
FeatureGroup,
2425
Feature,
@@ -151,6 +152,7 @@ def fetch_historical_feature_values(
151152
dry_run: bool = False,
152153
project: Optional[str] = None,
153154
location: Optional[str] = None,
155+
credentials: Optional[auth_credentials.Credentials] = None,
154156
) -> "Union[bigframes.pandas.DataFrame, None]":
155157
"""Fetch historical data at the timestamp specified for each entity.
156158
@@ -187,6 +189,9 @@ def fetch_historical_feature_values(
187189
The location to use for feature lookup and running the Point-In-Time
188190
Lookup (PITL) query in BigQuery. If unset, the project set in
189191
aiplatform.init will be used.
192+
credentials:
193+
Custom credentials to use for running the Point-In-Time Lookup (PITL)
194+
query in BigQuery. Overrides credentials set in aiplatform.init.
190195
191196
Returns:
192197
A `bigframes.pandas.DataFrame` with the historical feature values. `None`
@@ -196,10 +201,12 @@ def fetch_historical_feature_values(
196201
bigframes = _try_import_bigframes()
197202
project = project or initializer.global_config.project
198203
location = location or initializer.global_config.location
204+
credentials = credentials or initializer.global_config.credentials
199205
application_name = (
200206
f"vertexai-offline-store/{__version__}+fetch-historical-feature-values"
201207
)
202208
session_options = bigframes.BigQueryOptions(
209+
credentials=credentials,
203210
project=project,
204211
location=location,
205212
application_name=application_name,

0 commit comments

Comments
 (0)