Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(samples): read, import, batch_serve, batch_create features #1046

Merged
merged 39 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b687093
feat: SDK feature store samples (create/delete fs)
nayaknishant Jan 27, 2022
5e1aef1
feat: adding to conftest.py
nayaknishant Jan 27, 2022
f9ea78f
docs(samples): fixed testing
nayaknishant Jan 27, 2022
c9c131d
docs(samples): fixed testing
nayaknishant Jan 27, 2022
827f228
docs(samples): fixed testing
nayaknishant Jan 27, 2022
6929a8f
Merge branch 'googleapis:main' into main
nayaknishant Jan 28, 2022
7621664
docs(samples) added changes
nayaknishant Feb 2, 2022
b3bec5e
docs(samples): style issues
nayaknishant Feb 2, 2022
1d01651
Merge branch 'main' into main
nayaknishant Feb 22, 2022
d217a8d
adding create entity
nayaknishant Jan 28, 2022
7620809
docs(samples): added create feature and entity type
nayaknishant Jan 28, 2022
bd8899e
docs(samples): edited test
nayaknishant Jan 31, 2022
ecbe0cd
docs(samples) edited style
nayaknishant Jan 31, 2022
c03182e
moving constants
nayaknishant Feb 23, 2022
9690114
fixed dates
nayaknishant Feb 23, 2022
42fffc9
Merge branch 'googleapis:main' into nn-create-delete
nayaknishant Feb 24, 2022
209ec83
Update samples/model-builder/create_featurestore_sample_test.py
nayaknishant Feb 24, 2022
0c7501e
Update samples/model-builder/test_constants.py
nayaknishant Feb 24, 2022
41d8fdd
Update samples/model-builder/create_featurestore_sample_test.py
nayaknishant Feb 24, 2022
b19fbf0
docs(samples): add samples to create/delete featurestore (#980)
nayaknishant Feb 24, 2022
a1815fc
Update samples/model-builder/test_constants.py
nayaknishant Feb 24, 2022
5c38dc2
moving constants
nayaknishant Feb 23, 2022
4343293
added variables, made fixes, fixed spelling
nayaknishant Feb 24, 2022
56f566d
Merge branch 'main' into nn-create-delete
nayaknishant Feb 24, 2022
1250e52
batch_create_features_sample and test
nayaknishant Feb 25, 2022
a61f190
added batch serve to bq and test
nayaknishant Feb 25, 2022
3703c8d
working on batch samples
nayaknishant Feb 28, 2022
6c2c36e
fixed batch_serve_to_bq test
nayaknishant Feb 28, 2022
942222c
added read sample
nayaknishant Feb 28, 2022
54fa49c
moving constants
nayaknishant Feb 23, 2022
974b188
added featurestore samples
nayaknishant Mar 2, 2022
fa97910
Merge branch 'main' into nn-fs-batch-import-read
nayaknishant Mar 2, 2022
a5fe15d
lint issues
nayaknishant Mar 2, 2022
6870df8
adding revisions
nayaknishant Mar 4, 2022
0b1a583
adding revisions, fixing tests
nayaknishant Mar 4, 2022
5bcc7c5
Merge branch 'main' into nn-fs-batch-import-read
nayaknishant Mar 4, 2022
498e19a
Merge branch 'main' into nn-fs-batch-import-read
nayaknishant Mar 8, 2022
3ef7fe1
editing spacing for readability
nayaknishant Mar 8, 2022
1ae6c41
Merge branch 'main' into nn-fs-batch-import-read
nayaknishant Mar 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions samples/model-builder/batch_create_features_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# [START aiplatform_sdk_batch_create_features_sample]
from typing import Dict, Union

from google.cloud import aiplatform


def batch_create_features_sample(
project: str,
location: str,
entity_type_name: str,
featurestore_id: str,
feature_configs: Dict[str, Dict[str, Union[bool, int, Dict[str, str], str]]],
sync: bool = True,
):

aiplatform.init(project=project, location=location)

my_entity_type = aiplatform.featurestore.EntityType(
entity_type_name=entity_type_name, featurestore_id=featurestore_id
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved
)

my_entity_type.batch_create_features(feature_configs=feature_configs, sync=sync)
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved


# [END aiplatform_sdk_batch_create_features_sample]
43 changes: 43 additions & 0 deletions samples/model-builder/batch_create_features_sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import batch_create_features_sample
import test_constants as constants


def test_batch_create_features_sample(
mock_sdk_init, mock_get_entity_type, mock_batch_create_features
):

batch_create_features_sample.batch_create_features_sample(
project=constants.PROJECT,
location=constants.LOCATION,
entity_type_name=constants.ENTITY_TYPE_NAME,
featurestore_id=constants.FEATURESTORE_ID,
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved
feature_configs=constants.FEATURE_CONFIGS,
sync=constants.SYNC,
)

mock_sdk_init.assert_called_once_with(
project=constants.PROJECT, location=constants.LOCATION
)

mock_get_entity_type.assert_called_once_with(
entity_type_name=constants.ENTITY_TYPE_NAME,
featurestore_id=constants.FEATURESTORE_ID,
)

mock_batch_create_features.assert_called_once_with(
feature_configs=constants.FEATURE_CONFIGS, sync=constants.SYNC
)
44 changes: 44 additions & 0 deletions samples/model-builder/batch_serve_features_to_bq_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# [START aiplatform_sdk_batch_serve_features_to_bq_sample]
from typing import Dict, List

from google.cloud import aiplatform


def batch_serve_features_to_bq_sample(
project: str,
location: str,
featurestore_name: str,
bq_destination_output_uri: str,
serving_feature_ids: Dict[str, List[str]],
read_instances_uri: str,
sync: bool = True,
):

aiplatform.init(project=project, location=location)

fs = aiplatform.featurestore.Featurestore(featurestore_name=featurestore_name)

fs.batch_serve_to_bq(
bq_destination_output_uri=bq_destination_output_uri,
serving_feature_ids=serving_feature_ids,
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved
read_instances_uri=read_instances_uri,
sync=sync,
)


# [END aiplatform_sdk_batch_serve_features_to_bq_sample]
46 changes: 46 additions & 0 deletions samples/model-builder/batch_serve_features_to_bq_sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import batch_serve_features_to_bq_sample
import test_constants as constants


def test_batch_serve_features_to_bq_sample(
mock_sdk_init, mock_get_featurestore, mock_batch_serve_to_bq
):

batch_serve_features_to_bq_sample.batch_serve_features_to_bq_sample(
project=constants.PROJECT,
location=constants.LOCATION,
featurestore_name=constants.FEATURESTORE_NAME,
bq_destination_output_uri=constants.BQ_DESTINATION_OUTPUT_URI,
serving_feature_ids=constants.SERVING_FEATURE_IDS,
read_instances_uri=constants.INPUT_CSV_FILE,
sync=constants.SYNC,
)

mock_sdk_init.assert_called_once_with(
project=constants.PROJECT, location=constants.LOCATION
)

mock_get_featurestore.assert_called_once_with(
featurestore_name=constants.FEATURESTORE_NAME
)

mock_batch_serve_to_bq.assert_called_once_with(
bq_destination_output_uri=constants.BQ_DESTINATION_OUTPUT_URI,
serving_feature_ids=constants.SERVING_FEATURE_IDS,
read_instances_uri=constants.INPUT_CSV_FILE,
sync=constants.SYNC,
)
37 changes: 36 additions & 1 deletion samples/model-builder/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def mock_endpoint_explain(mock_endpoint):

"""
----------------------------------------------------------------------------
FeatureStore Fixtures
Feature Store Fixtures
----------------------------------------------------------------------------
"""

Expand Down Expand Up @@ -398,6 +398,13 @@ def mock_get_featurestore(mock_featurestore):
yield mock_get_featurestore


@pytest.fixture
def mock_get_entity_type(mock_entity_type):
with patch.object(aiplatform.featurestore, "EntityType") as mock_get_entity_type:
mock_get_entity_type.return_value = mock_entity_type
yield mock_get_entity_type


@pytest.fixture
def mock_create_featurestore(mock_featurestore):
with patch.object(
Expand Down Expand Up @@ -429,3 +436,31 @@ def mock_create_feature(mock_feature):
def mock_delete_featurestore(mock_featurestore):
with patch.object(mock_featurestore, "delete") as mock_delete_featurestore:
yield mock_delete_featurestore


@pytest.fixture
def mock_batch_serve_to_bq(mock_featurestore):
with patch.object(mock_featurestore, "batch_serve_to_bq") as mock_batch_serve_to_bq:
yield mock_batch_serve_to_bq


@pytest.fixture
def mock_batch_create_features(mock_entity_type):
with patch.object(
mock_entity_type, "batch_create_features"
) as mock_batch_create_features:
yield mock_batch_create_features


@pytest.fixture
def mock_read_feature_values(mock_entity_type):
with patch.object(mock_entity_type, "read") as mock_read_feature_values:
yield mock_read_feature_values


@pytest.fixture
def mock_import_feature_values(mock_entity_type):
with patch.object(
mock_entity_type, "ingest_from_gcs"
) as mock_import_feature_values:
yield mock_import_feature_values
48 changes: 48 additions & 0 deletions samples/model-builder/import_feature_values_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# [START aiplatform_sdk_import_feature_values_sample]
import datetime
from typing import List, Union

from google.cloud import aiplatform


def import_feature_values_sample(
project: str,
location: str,
entity_type_name: str,
featurestore_id: str,
feature_ids: List[str],
feature_time: Union[str, datetime.datetime],
gcs_source_uris: Union[str, List[str]],
gcs_source_type: str,
):

aiplatform.init(project=project, location=location)

my_entity_type = aiplatform.featurestore.EntityType(
entity_type_name=entity_type_name, featurestore_id=featurestore_id
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved
)

my_entity_type.ingest_from_gcs(
feature_ids=feature_ids,
feature_time=feature_time,
gcs_source_uris=gcs_source_uris,
gcs_source_type=gcs_source_type,
)


# [END aiplatform_sdk_import_feature_values_sample]
48 changes: 48 additions & 0 deletions samples/model-builder/import_feature_values_sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import import_feature_values_sample
import test_constants as constants


def test_import_feature_values_sample(
mock_sdk_init, mock_get_entity_type, mock_import_feature_values
):

import_feature_values_sample.import_feature_values_sample(
project=constants.PROJECT,
location=constants.LOCATION,
entity_type_name=constants.ENTITY_TYPE_NAME,
featurestore_id=constants.FEATURESTORE_ID,
feature_ids=constants.FEATURE_IDS,
feature_time=constants.USERS_FEATURE_TIME,
gcs_source_uris=constants.USERS_GCS_SOURCE_URI,
gcs_source_type=constants.GCS_SOURCE_TYPE,
)

mock_sdk_init.assert_called_once_with(
project=constants.PROJECT, location=constants.LOCATION
)

mock_get_entity_type.assert_called_once_with(
entity_type_name=constants.ENTITY_TYPE_NAME,
featurestore_id=constants.FEATURESTORE_ID,
)

mock_import_feature_values.assert_called_once_with(
feature_ids=constants.FEATURE_IDS,
feature_time=constants.USERS_FEATURE_TIME,
gcs_source_uris=constants.USERS_GCS_SOURCE_URI,
gcs_source_type=constants.GCS_SOURCE_TYPE,
)
40 changes: 40 additions & 0 deletions samples/model-builder/read_feature_values_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# [START aiplatform_sdk_read_features_sample]
from typing import List, Union

from google.cloud import aiplatform


def read_feature_values_sample(
project: str,
location: str,
entity_type_name: str,
featurestore_id: str,
entity_ids: Union[str, List[str]],
feature_ids: Union[str, List[str]] = "*",
):

aiplatform.init(project=project, location=location)

my_entity_type = aiplatform.featurestore.EntityType(
entity_type_name=entity_type_name, featurestore_id=featurestore_id
)

my_entity_type.read(entity_ids=entity_ids, feature_ids=feature_ids)
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved


# [END aiplatform_sdk_read_features_sample]
Loading