-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UpdateFeatureGroup related APIs in sample notebook
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
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 |
---|---|---|
|
@@ -310,6 +310,63 @@ | |
"check_feature_group_status(orders_feature_group)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Add features to FeatureGroup\n", | ||
"\n", | ||
"After the FeatureGroup has been created, we can update the FeatureGroup by using the `UpdateFeatureGroup` API." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from sagemaker.feature_store.feature_definition import (\n", | ||
" FractionalFeatureDefinition,\n", | ||
" IntegralFeatureDefinition,\n", | ||
" StringFeatureDefinition,\n", | ||
" FeatureTypeEnum,\n", | ||
")\n", | ||
"\n", | ||
"customers_feature_group.update(\n", | ||
" feature_additions = [\n", | ||
" StringFeatureDefinition(\"email\"),\n", | ||
" StringFeatureDefinition(\"name\")\n", | ||
" ]\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Verify the FeatureGroup has been updated successfully or not." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def check_last_update_status(feature_group):\n", | ||
" last_update_status = feature_group.describe().get(\"LastUpdateStatus\")[\"Status\"]\n", | ||
" while last_update_status == \"InProgress\":\n", | ||
" print(\"Waiting for Feature Group to be updated\")\n", | ||
" time.sleep(5)\n", | ||
" last_update_status = feature_group.describe().get(\"LastUpdateStatus\")\n", | ||
" if last_update_status == \"Successful\":\n", | ||
" print(f\"FeatureGroup {feature_group.name} successfully updated.\")\n", | ||
" else:\n", | ||
" print(f\"FeatureGroup {feature_group.name} updated failed. The LastUpdateStatus is\" + last_update_status)\n", | ||
"\n", | ||
"check_last_update_status(customers_feature_group)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
|
@@ -473,6 +530,51 @@ | |
"all_records" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"If we want to load data for the added features into the updated customers_feature_group, use `PutRecord` operation." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sagemaker_session.boto_session.client(\n", | ||
" \"sagemaker-featurestore-runtime\", region_name=region\n", | ||
").put_record(\n", | ||
" FeatureGroupName=customers_feature_group_name, \n", | ||
" Record=[\n", | ||
" {\n", | ||
" \"FeatureName\": \"customer_id\",\n", | ||
" \"ValueAsString\": \"573291\"\n", | ||
" },\n", | ||
" {\n", | ||
" \"FeatureName\": \"EventTime\",\n", | ||
" \"ValueAsString\": str(current_time_sec)\n", | ||
" },\n", | ||
" {\n", | ||
" \"FeatureName\": \"email\",\n", | ||
" \"ValueAsString\": \"[email protected]\"\n", | ||
" },\n", | ||
" {\n", | ||
" \"FeatureName\": \"name\",\n", | ||
" \"ValueAsString\": \"John Lee\"\n", | ||
" } \n", | ||
" ]\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Use the `GetRecord` operation again to check the records that have been ingested to the updated customers_feature_group." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
|
@@ -530,12 +632,14 @@ | |
"* `delete()`\n", | ||
"* `create()`\n", | ||
"* `load_feature_definitions()`\n", | ||
"* `update()`\n", | ||
"* `update_feature_metadata()`\n", | ||
"* `describe_feature_metadata()`\n", | ||
"\n", | ||
"#### Boto3 API Calls\n", | ||
"* `list_feature_groups()`\n", | ||
"* `get_record()`\n", | ||
"* `put_record()`\n", | ||
"* `batch_get_record()`\n", | ||
"* `search()`\n" | ||
] | ||
|