-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Add UpdateFeatureGroup related APIs in sample notebook #3515
Merged
Merged
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions
5
sagemaker-featurestore/data/feature_store_introduction_customer_updated.csv
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,5 @@ | ||
customer_id,city_code,state_code,country_code,email,name | ||
573291,1,49,2,[email protected],John Lee | ||
109382,2,40,2,[email protected],Olive Quil | ||
828400,3,31,2,[email protected],Liz Knee | ||
124013,4,5,2,[email protected],Eileen Book |
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 |
---|---|---|
|
@@ -473,6 +473,152 @@ | |
"all_records" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Add features to a feature group\n", | ||
"\n", | ||
"If we want to update a FeatureGroup that has done the data ingestion, we can use the `UpdateFeatureGroup` API and then re-ingest data by using the updated dataset." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from sagemaker.feature_store.feature_definition import StringFeatureDefinition\n", | ||
"\n", | ||
"customers_feature_group.update(\n", | ||
" feature_additions=[StringFeatureDefinition(\"email\"), StringFeatureDefinition(\"name\")]\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 FeatureGroup 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(\n", | ||
" f\"FeatureGroup {feature_group.name} updated failed. The LastUpdateStatus is\"\n", | ||
" + str(last_update_status)\n", | ||
" )\n", | ||
"\n", | ||
"\n", | ||
"check_last_update_status(customers_feature_group)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Inspect the new dataset." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"customer_data_updated = pd.read_csv(\"data/feature_store_introduction_customer_updated.csv\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"customer_data_updated.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Append `EventTime` feature to your data frame again." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"customer_data_updated[\"EventTime\"] = pd.Series(\n", | ||
" [current_time_sec] * len(customer_data), dtype=\"float64\"\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Ingest the new dataset." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"customers_feature_group.ingest(data_frame=customer_data_updated, max_workers=3, wait=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Use `batch_get_record` again to check that all updated data has been ingested into `customers_feature_group` by providing customer IDs." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"updated_customers_records = sagemaker_session.boto_session.client(\n", | ||
" \"sagemaker-featurestore-runtime\", region_name=region\n", | ||
").batch_get_record(\n", | ||
" Identifiers=[\n", | ||
" {\n", | ||
" \"FeatureGroupName\": customers_feature_group_name,\n", | ||
" \"RecordIdentifiersValueAsString\": [\"573291\", \"109382\", \"828400\", \"124013\"],\n", | ||
" }\n", | ||
" ]\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"updated_customers_records" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
|
@@ -530,6 +676,7 @@ | |
"* `delete()`\n", | ||
"* `create()`\n", | ||
"* `load_feature_definitions()`\n", | ||
"* `update()`\n", | ||
"* `update_feature_metadata()`\n", | ||
"* `describe_feature_metadata()`\n", | ||
"\n", | ||
|
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.
Branding nit - should it be "feature group", "FeatureGroup", or "Feature Group"? Use one consistently.
Reply via ReviewNB
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.
thx! fixed in new version.