Skip to content

Commit ad9e259

Browse files
imingtsoumizanfiu
authored andcommitted
Add list_feature_groups API (aws#647)
1 parent 4389847 commit ad9e259

File tree

6 files changed

+774
-590
lines changed

6 files changed

+774
-590
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Feature Store.
14+
15+
Amazon SageMaker Feature Store is a fully managed, purpose-built repository to store, share, and
16+
manage features for machine learning (ML) models.
17+
"""
18+
from __future__ import absolute_import
19+
20+
import datetime
21+
from typing import Dict, Any
22+
23+
import attr
24+
25+
from sagemaker import Session
26+
27+
28+
@attr.s
29+
class FeatureStore:
30+
"""FeatureStore definition.
31+
32+
This class instantiates a FeatureStore object that comprises a SageMaker session instance.
33+
34+
Attributes:
35+
sagemaker_session (Session): session instance to perform boto calls.
36+
"""
37+
38+
sagemaker_session: Session = attr.ib(default=Session)
39+
40+
def list_feature_groups(
41+
self,
42+
name_contains: str = None,
43+
feature_group_status_equals: str = None,
44+
offline_store_status_equals: str = None,
45+
creation_time_after: datetime.datetime = None,
46+
creation_time_before: datetime.datetime = None,
47+
sort_order: str = None,
48+
sort_by: str = None,
49+
max_results: int = None,
50+
next_token: str = None,
51+
) -> Dict[str, Any]:
52+
"""List all FeatureGroups satisfying given filters.
53+
54+
Args:
55+
name_contains (str): A string that partially matches one or more FeatureGroups' names.
56+
Filters FeatureGroups by name.
57+
feature_group_status_equals (str): A FeatureGroup status.
58+
Filters FeatureGroups by FeatureGroup status.
59+
offline_store_status_equals (str): An OfflineStore status.
60+
Filters FeatureGroups by OfflineStore status.
61+
creation_time_after (datetime.datetime): Use this parameter to search for FeatureGroups
62+
created after a specific date and time.
63+
creation_time_before (datetime.datetime): Use this parameter to search for FeatureGroups
64+
created before a specific date and time.
65+
sort_order (str): The order in which FeatureGroups are listed.
66+
sort_by (str): The value on which the FeatureGroup list is sorted.
67+
max_results (int): The maximum number of results returned by ListFeatureGroups.
68+
next_token (str): A token to resume pagination of ListFeatureGroups results.
69+
Returns:
70+
Response dict from service.
71+
"""
72+
return self.sagemaker_session.list_feature_groups(
73+
name_contains=name_contains,
74+
feature_group_status_equals=feature_group_status_equals,
75+
offline_store_status_equals=offline_store_status_equals,
76+
creation_time_after=creation_time_after,
77+
creation_time_before=creation_time_before,
78+
sort_order=sort_order,
79+
sort_by=sort_by,
80+
max_results=max_results,
81+
next_token=next_token,
82+
)

src/sagemaker/session.py

+55
Original file line numberDiff line numberDiff line change
@@ -4332,6 +4332,61 @@ def update_feature_group(
43324332
FeatureGroupName=feature_group_name, FeatureAdditions=feature_additions
43334333
)
43344334

4335+
def list_feature_groups(
4336+
self,
4337+
name_contains,
4338+
feature_group_status_equals,
4339+
offline_store_status_equals,
4340+
creation_time_after,
4341+
creation_time_before,
4342+
sort_order,
4343+
sort_by,
4344+
max_results,
4345+
next_token,
4346+
) -> Dict[str, Any]:
4347+
"""List all FeatureGroups satisfying given filters.
4348+
4349+
Args:
4350+
name_contains (str): A string that partially matches one or more FeatureGroups' names.
4351+
Filters FeatureGroups by name.
4352+
feature_group_status_equals (str): A FeatureGroup status.
4353+
Filters FeatureGroups by FeatureGroup status.
4354+
offline_store_status_equals (str): An OfflineStore status.
4355+
Filters FeatureGroups by OfflineStore status.
4356+
creation_time_after (datetime.datetime): Use this parameter to search for FeatureGroups
4357+
created after a specific date and time.
4358+
creation_time_before (datetime.datetime): Use this parameter to search for FeatureGroups
4359+
created before a specific date and time.
4360+
sort_order (str): The order in which FeatureGroups are listed.
4361+
sort_by (str): The value on which the FeatureGroup list is sorted.
4362+
max_results (int): The maximum number of results returned by ListFeatureGroups.
4363+
next_token (str): A token to resume pagination of ListFeatureGroups results.
4364+
Returns:
4365+
Response dict from service.
4366+
"""
4367+
list_feature_groups_args = {}
4368+
4369+
if name_contains:
4370+
list_feature_groups_args["NameContains"] = name_contains
4371+
if feature_group_status_equals:
4372+
list_feature_groups_args["FeatureGroupStatusEquals"] = feature_group_status_equals
4373+
if offline_store_status_equals:
4374+
list_feature_groups_args["OfflineStoreStatusEquals"] = offline_store_status_equals
4375+
if creation_time_after:
4376+
list_feature_groups_args["CreationTimeAfter"] = creation_time_after
4377+
if creation_time_before:
4378+
list_feature_groups_args["CreationTimeBefore"] = creation_time_before
4379+
if sort_order:
4380+
list_feature_groups_args["SortOrder"] = sort_order
4381+
if sort_by:
4382+
list_feature_groups_args["SortBy"] = sort_by
4383+
if max_results:
4384+
list_feature_groups_args["MaxResults"] = max_results
4385+
if next_token:
4386+
list_feature_groups_args["NextToken"] = next_token
4387+
4388+
return self.sagemaker_client.list_feature_groups(**list_feature_groups_args)
4389+
43354390
def update_feature_metadata(
43364391
self,
43374392
feature_group_name: str,

tests/integ/test_feature_store.py

+20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from sagemaker.feature_store.feature_definition import FractionalFeatureDefinition
2626
from sagemaker.feature_store.feature_group import FeatureGroup
27+
from sagemaker.feature_store.feature_store import FeatureStore
2728
from sagemaker.feature_store.inputs import FeatureValue, FeatureParameter, TableFormatEnum
2829
from sagemaker.session import get_execution_role, Session
2930
from tests.integ.timeout import timeout
@@ -316,6 +317,25 @@ def test_update_feature_group(
316317
assert any([True for elem in feature_definitions if new_feature_name in elem.values()])
317318

318319

320+
def test_list_feature_groups(feature_store_session, role, feature_group_name, pandas_data_frame):
321+
feature_store = FeatureStore(sagemaker_session=feature_store_session)
322+
feature_group = FeatureGroup(name=feature_group_name, sagemaker_session=feature_store_session)
323+
feature_group.load_feature_definitions(data_frame=pandas_data_frame)
324+
325+
with cleanup_feature_group(feature_group):
326+
feature_group.create(
327+
s3_uri=False,
328+
record_identifier_name="feature1",
329+
event_time_feature_name="feature3",
330+
role_arn=role,
331+
enable_online_store=True,
332+
)
333+
_wait_for_feature_group_create(feature_group)
334+
output = feature_store.list_feature_groups(name_contains=feature_group_name)
335+
336+
assert output["FeatureGroupSummaries"][0]["FeatureGroupName"] == feature_group_name
337+
338+
319339
def test_feature_metadata(
320340
feature_store_session,
321341
role,

0 commit comments

Comments
 (0)