-
Notifications
You must be signed in to change notification settings - Fork 350
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
nayaknishant
merged 39 commits into
googleapis:main
from
nayaknishant:nn-fs-batch-import-read
Mar 8, 2022
Merged
Changes from 37 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 5e1aef1
feat: adding to conftest.py
nayaknishant f9ea78f
docs(samples): fixed testing
nayaknishant c9c131d
docs(samples): fixed testing
nayaknishant 827f228
docs(samples): fixed testing
nayaknishant 6929a8f
Merge branch 'googleapis:main' into main
nayaknishant 7621664
docs(samples) added changes
nayaknishant b3bec5e
docs(samples): style issues
nayaknishant 1d01651
Merge branch 'main' into main
nayaknishant d217a8d
adding create entity
nayaknishant 7620809
docs(samples): added create feature and entity type
nayaknishant bd8899e
docs(samples): edited test
nayaknishant ecbe0cd
docs(samples) edited style
nayaknishant c03182e
moving constants
nayaknishant 9690114
fixed dates
nayaknishant 42fffc9
Merge branch 'googleapis:main' into nn-create-delete
nayaknishant 209ec83
Update samples/model-builder/create_featurestore_sample_test.py
nayaknishant 0c7501e
Update samples/model-builder/test_constants.py
nayaknishant 41d8fdd
Update samples/model-builder/create_featurestore_sample_test.py
nayaknishant b19fbf0
docs(samples): add samples to create/delete featurestore (#980)
nayaknishant a1815fc
Update samples/model-builder/test_constants.py
nayaknishant 5c38dc2
moving constants
nayaknishant 4343293
added variables, made fixes, fixed spelling
nayaknishant 56f566d
Merge branch 'main' into nn-create-delete
nayaknishant 1250e52
batch_create_features_sample and test
nayaknishant a61f190
added batch serve to bq and test
nayaknishant 3703c8d
working on batch samples
nayaknishant 6c2c36e
fixed batch_serve_to_bq test
nayaknishant 942222c
added read sample
nayaknishant 54fa49c
moving constants
nayaknishant 974b188
added featurestore samples
nayaknishant fa97910
Merge branch 'main' into nn-fs-batch-import-read
nayaknishant a5fe15d
lint issues
nayaknishant 6870df8
adding revisions
nayaknishant 0b1a583
adding revisions, fixing tests
nayaknishant 5bcc7c5
Merge branch 'main' into nn-fs-batch-import-read
nayaknishant 498e19a
Merge branch 'main' into nn-fs-batch-import-read
nayaknishant 3ef7fe1
editing spacing for readability
nayaknishant 1ae6c41
Merge branch 'main' into nn-fs-batch-import-read
nayaknishant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
||
# [START aiplatform_sdk_batch_create_features_sample] | ||
from google.cloud import aiplatform | ||
|
||
|
||
def batch_create_features_sample( | ||
project: str, | ||
location: str, | ||
entity_type_id: str, | ||
featurestore_id: str, | ||
sync: bool = True, | ||
): | ||
|
||
aiplatform.init(project=project, location=location) | ||
|
||
my_entity_type = aiplatform.featurestore.EntityType( | ||
entity_type_name=entity_type_id, featurestore_id=featurestore_id | ||
) | ||
|
||
FEATURE_CONFIGS = { | ||
"age": {"value_type": "INT64", "description": "User age"}, | ||
"gender": {"value_type": "STRING", "description": "User gender"}, | ||
"liked_genres": { | ||
"value_type": "STRING_ARRAY", | ||
"description": "An array of genres this user liked", | ||
}, | ||
} | ||
|
||
my_entity_type.batch_create_features(feature_configs=FEATURE_CONFIGS, sync=sync) | ||
|
||
|
||
# [END aiplatform_sdk_batch_create_features_sample] |
42 changes: 42 additions & 0 deletions
42
samples/model-builder/batch_create_features_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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_id=constants.ENTITY_TYPE_ID, | ||
featurestore_id=constants.FEATURESTORE_ID, | ||
nayaknishant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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_ID, | ||
featurestore_id=constants.FEATURESTORE_ID, | ||
) | ||
|
||
mock_batch_create_features.assert_called_once_with( | ||
feature_configs=constants.FEATURE_CONFIGS, sync=constants.SYNC | ||
) |
46 changes: 46 additions & 0 deletions
46
samples/model-builder/batch_serve_features_to_bq_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
||
# [START aiplatform_sdk_batch_serve_features_to_bq_sample] | ||
from google.cloud import aiplatform | ||
|
||
|
||
def batch_serve_features_to_bq_sample( | ||
project: str, | ||
location: str, | ||
featurestore_name: str, | ||
bq_destination_output_uri: str, | ||
read_instances_uri: str, | ||
sync: bool = True, | ||
): | ||
|
||
aiplatform.init(project=project, location=location) | ||
|
||
fs = aiplatform.featurestore.Featurestore(featurestore_name=featurestore_name) | ||
|
||
SERVING_FEATURE_IDS = { | ||
"users": ["age", "gender", "liked_genres"], | ||
"movies": ["title", "average_rating", "genres"], | ||
} | ||
|
||
fs.batch_serve_to_bq( | ||
bq_destination_output_uri=bq_destination_output_uri, | ||
serving_feature_ids=SERVING_FEATURE_IDS, | ||
read_instances_uri=read_instances_uri, | ||
sync=sync, | ||
) | ||
|
||
|
||
# [END aiplatform_sdk_batch_serve_features_to_bq_sample] |
45 changes: 45 additions & 0 deletions
45
samples/model-builder/batch_serve_features_to_bq_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 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, | ||
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_id: 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_id, featurestore_id=featurestore_id | ||
) | ||
|
||
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
48
samples/model-builder/import_feature_values_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_id=constants.ENTITY_TYPE_ID, | ||
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_ID, | ||
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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_id: 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_id, featurestore_id=featurestore_id | ||
) | ||
|
||
my_dataframe = my_entity_type.read(entity_ids=entity_ids, feature_ids=feature_ids) | ||
|
||
return my_dataframe | ||
|
||
|
||
# [END aiplatform_sdk_read_features_sample] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed