Skip to content

Commit f591088

Browse files
authored
feat: Add templating for dynamodb table name (#2394)
Signed-off-by: Danny Boland <danny@bloomandwild.com>
1 parent 9aa96b9 commit f591088

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

sdk/python/feast/infra/online_stores/dynamodb.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class DynamoDBOnlineStoreConfig(FeastConfigBaseModel):
5252
region: StrictStr
5353
""" AWS Region Name """
5454

55+
table_name_template: StrictStr = "{project}.{table_name}"
56+
""" DynamoDB table name template """
57+
5558

5659
class DynamoDBOnlineStore(OnlineStore):
5760
"""
@@ -91,7 +94,7 @@ def update(
9194
for table_instance in tables_to_keep:
9295
try:
9396
dynamodb_resource.create_table(
94-
TableName=_get_table_name(config, table_instance),
97+
TableName=_get_table_name(online_config, config, table_instance),
9598
KeySchema=[{"AttributeName": "entity_id", "KeyType": "HASH"}],
9699
AttributeDefinitions=[
97100
{"AttributeName": "entity_id", "AttributeType": "S"}
@@ -107,12 +110,13 @@ def update(
107110

108111
for table_instance in tables_to_keep:
109112
dynamodb_client.get_waiter("table_exists").wait(
110-
TableName=_get_table_name(config, table_instance)
113+
TableName=_get_table_name(online_config, config, table_instance)
111114
)
112115

113116
for table_to_delete in tables_to_delete:
114117
_delete_table_idempotent(
115-
dynamodb_resource, _get_table_name(config, table_to_delete)
118+
dynamodb_resource,
119+
_get_table_name(online_config, config, table_to_delete),
116120
)
117121

118122
def teardown(
@@ -133,7 +137,9 @@ def teardown(
133137
dynamodb_resource = self._get_dynamodb_resource(online_config.region)
134138

135139
for table in tables:
136-
_delete_table_idempotent(dynamodb_resource, _get_table_name(config, table))
140+
_delete_table_idempotent(
141+
dynamodb_resource, _get_table_name(online_config, config, table)
142+
)
137143

138144
@log_exceptions_and_usage(online_store="dynamodb")
139145
def online_write_batch(
@@ -164,7 +170,9 @@ def online_write_batch(
164170
assert isinstance(online_config, DynamoDBOnlineStoreConfig)
165171
dynamodb_resource = self._get_dynamodb_resource(online_config.region)
166172

167-
table_instance = dynamodb_resource.Table(_get_table_name(config, table))
173+
table_instance = dynamodb_resource.Table(
174+
_get_table_name(online_config, config, table)
175+
)
168176
with table_instance.batch_writer() as batch:
169177
for entity_key, features, timestamp, created_ts in data:
170178
entity_id = compute_entity_id(entity_key)
@@ -206,7 +214,9 @@ def online_read(
206214

207215
result: List[Tuple[Optional[datetime], Optional[Dict[str, ValueProto]]]] = []
208216
for entity_key in entity_keys:
209-
table_instance = dynamodb_resource.Table(_get_table_name(config, table))
217+
table_instance = dynamodb_resource.Table(
218+
_get_table_name(online_config, config, table)
219+
)
210220
entity_id = compute_entity_id(entity_key)
211221
with tracing_span(name="remote_call"):
212222
response = table_instance.get_item(Key={"entity_id": entity_id})
@@ -242,8 +252,12 @@ def _initialize_dynamodb_resource(region: str):
242252
return boto3.resource("dynamodb", region_name=region)
243253

244254

245-
def _get_table_name(config: RepoConfig, table: FeatureView) -> str:
246-
return f"{config.project}.{table.name}"
255+
def _get_table_name(
256+
online_config: DynamoDBOnlineStoreConfig, config: RepoConfig, table: FeatureView
257+
) -> str:
258+
return online_config.table_name_template.format(
259+
project=config.project, table_name=table.name
260+
)
247261

248262

249263
def _delete_table_idempotent(

0 commit comments

Comments
 (0)