Skip to content

Commit

Permalink
Add UpdateFeatureGroup related APIs in sample notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
verayu43 committed Jul 28, 2022
1 parent 2bd685e commit f523d15
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions sagemaker-featurestore/feature_store_introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down Expand Up @@ -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": {},
Expand Down Expand Up @@ -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"
]
Expand Down

0 comments on commit f523d15

Please sign in to comment.