File size: 6,879 Bytes
4021124 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file 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.
"""The input configs for FeatureStore.
A feature store serves as the single source of truth to store, retrieve,
remove, track, share, discover, and control access to features.
You can configure two types of feature stores, an online features store
and an offline feature store.
The online features store is a low latency, high availability cache for a
feature group that enables real-time lookup of records. Only the latest record is stored.
The offline feature store use when low (sub-second) latency reads are not needed.
This is the case when you want to store and serve features for exploration, model training,
and batch inference. The offline store uses your Amazon Simple Storage Service (Amazon S3)
bucket for storage. A prefixing scheme based on event time is used to store your data in Amazon S3.
"""
from __future__ import absolute_import
import abc
from typing import Dict, Any
import attr
class Config(abc.ABC):
"""Base config object for FeatureStore.
Configs must implement the to_dict method.
"""
@abc.abstractmethod
def to_dict(self) -> Dict[str, Any]:
"""Get the dictionary from attributes.
Returns:
dict contains the attributes.
"""
@classmethod
def construct_dict(cls, **kwargs) -> Dict[str, Any]:
"""Construct the dictionary based on the args.
args:
kwargs: args to be used to construct the dict.
Returns:
dict represents the given kwargs.
"""
result = dict()
for key, value in kwargs.items():
if value is not None:
if isinstance(value, Config):
result[key] = value.to_dict()
else:
result[key] = value
return result
@attr.s
class OnlineStoreSecurityConfig(Config):
"""OnlineStoreSecurityConfig for FeatureStore.
Attributes:
kms_key_id (str): KMS key id.
"""
kms_key_id: str = attr.ib(factory=str)
def to_dict(self) -> Dict[str, Any]:
"""Construct a dictionary based on the attributes."""
return Config.construct_dict(KmsKeyId=self.kms_key_id)
@attr.s
class OnlineStoreConfig(Config):
"""OnlineStoreConfig for FeatureStore.
Attributes:
enable_online_store (bool): whether to enable the online store.
online_store_security_config (OnlineStoreSecurityConfig): configuration of security setting.
"""
enable_online_store: bool = attr.ib(default=True)
online_store_security_config: OnlineStoreSecurityConfig = attr.ib(default=None)
def to_dict(self) -> Dict[str, Any]:
"""Construct a dictionary based on the attributes.
Returns:
dict represents the attributes.
"""
return Config.construct_dict(
EnableOnlineStore=self.enable_online_store,
SecurityConfig=self.online_store_security_config,
)
@attr.s
class S3StorageConfig(Config):
"""S3StorageConfig for FeatureStore.
Attributes:
s3_uri (str): S3 URI.
kms_key_id (str): KMS key id.
"""
s3_uri: str = attr.ib()
kms_key_id: str = attr.ib(default=None)
def to_dict(self) -> Dict[str, Any]:
"""Construct a dictionary based on the attributes provided.
Returns:
dict represents the attributes.
"""
return Config.construct_dict(
S3Uri=self.s3_uri,
KmsKeyId=self.kms_key_id,
)
@attr.s
class DataCatalogConfig(Config):
"""DataCatalogConfig for FeatureStore.
Attributes:
table_name (str): name of the table.
catalog (str): name of the catalog.
database (str): name of the database.
"""
table_name: str = attr.ib(factory=str)
catalog: str = attr.ib(factory=str)
database: str = attr.ib(factory=str)
def to_dict(self) -> Dict[str, Any]:
"""Construct a dictionary based on the attributes provided.
Returns:
dict represents the attributes.
"""
return Config.construct_dict(
TableName=self.table_name,
Catalog=self.catalog,
Database=self.database,
)
@attr.s
class OfflineStoreConfig(Config):
"""OfflineStoreConfig for FeatureStore.
Attributes:
s3_storage_config (S3StorageConfig): configuration of S3 storage.
disable_glue_table_creation (bool): whether to disable the Glue table creation.
data_catalog_config (DataCatalogConfig): configuration of the data catalog.
"""
s3_storage_config: S3StorageConfig = attr.ib()
disable_glue_table_creation: bool = attr.ib(default=False)
data_catalog_config: DataCatalogConfig = attr.ib(default=None)
def to_dict(self) -> Dict[str, Any]:
"""Construct a dictionary based on the attributes.
Returns:
dict represents the attributes.
"""
return Config.construct_dict(
DisableGlueTableCreation=self.disable_glue_table_creation,
S3StorageConfig=self.s3_storage_config,
DataCatalogConfig=self.data_catalog_config,
)
@attr.s
class FeatureValue(Config):
"""FeatureValue for FeatureStore.
Attributes:
feature_name (str): name of the Feature.
value_as_string (str): value of the Feature in string form.
"""
feature_name: str = attr.ib(default=None)
value_as_string: str = attr.ib(default=None)
def to_dict(self) -> Dict[str, Any]:
"""Construct a dictionary based on the attributes provided.
Returns:
dict represents the attributes.
"""
return Config.construct_dict(
FeatureName=self.feature_name,
ValueAsString=self.value_as_string,
)
@attr.s
class FeatureParameter(Config):
"""FeatureParameter for FeatureStore.
Attributes:
key (str): key of the parameter.
value (str): value of the parameter.
"""
key: str = attr.ib(default=None)
value: str = attr.ib(default=None)
def to_dict(self) -> Dict[str, Any]:
"""Construct a dictionary based on the attributes provided.
Returns:
dict represents the attributes.
"""
return Config.construct_dict(
Key=self.key,
Value=self.value,
)
|