Skip to content

Commit ca47748

Browse files
cnfaitkukushking
andauthored
add support for boto3 kwargs to timestream.create_table (#1819)
* add support for boto3 kwargs to timestream.create_table * remove awswrangler's validation of timestream_additional_kwargs - let boto3 handle it Co-authored-by: kukushking <[email protected]>
1 parent 32fcf63 commit ca47748

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

awswrangler/timestream.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ def create_table(
402402
memory_retention_hours: int,
403403
magnetic_retention_days: int,
404404
tags: Optional[Dict[str, str]] = None,
405+
timestream_additional_kwargs: Optional[Dict[str, Any]] = None,
405406
boto3_session: Optional[boto3.Session] = None,
406407
) -> str:
407408
"""Create a new Timestream database.
@@ -426,6 +427,9 @@ def create_table(
426427
Tags enable you to categorize databases and/or tables, for example,
427428
by purpose, owner, or environment.
428429
e.g. {"foo": "boo", "bar": "xoo"})
430+
timestream_additional_kwargs : Optional[Dict[str, Any]]
431+
Forwarded to botocore requests.
432+
e.g. timestream_additional_kwargs={'MagneticStoreWriteProperties': {'EnableMagneticStoreWrites': True}}
429433
boto3_session : boto3.Session(), optional
430434
Boto3 Session. The default boto3 Session will be used if boto3_session receive None.
431435
@@ -448,13 +452,15 @@ def create_table(
448452
449453
"""
450454
client: boto3.client = _utils.client(service_name="timestream-write", session=boto3_session)
455+
timestream_additional_kwargs = {} if timestream_additional_kwargs is None else timestream_additional_kwargs
451456
args: Dict[str, Any] = {
452457
"DatabaseName": database,
453458
"TableName": table,
454459
"RetentionProperties": {
455460
"MemoryStoreRetentionPeriodInHours": memory_retention_hours,
456461
"MagneticStoreRetentionPeriodInDays": magnetic_retention_days,
457462
},
463+
**timestream_additional_kwargs,
458464
}
459465
if tags is not None:
460466
args["Tags"] = [{"Key": k, "Value": v} for k, v in tags.items()]

tests/test_timestream.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from datetime import datetime
33

4+
import boto3
45
import pandas as pd
56
import pytest
67

@@ -284,3 +285,30 @@ def test_list_tables(timestream_database_and_table):
284285

285286
tables_in_db = wr.timestream.list_tables(database=timestream_database_and_table)
286287
assert f"{timestream_database_and_table}_2" not in tables_in_db
288+
289+
290+
@pytest.mark.parametrize(
291+
"timestream_additional_kwargs",
292+
[None, {"MagneticStoreWriteProperties": {"EnableMagneticStoreWrites": True}}],
293+
)
294+
def test_create_table_additional_kwargs(timestream_database_and_table, timestream_additional_kwargs):
295+
client_timestream = boto3.client("timestream-write")
296+
wr.timestream.create_table(
297+
database=timestream_database_and_table,
298+
table=f"{timestream_database_and_table}_3",
299+
memory_retention_hours=1,
300+
magnetic_retention_days=1,
301+
timestream_additional_kwargs=timestream_additional_kwargs,
302+
)
303+
304+
desc = client_timestream.describe_table(
305+
DatabaseName=timestream_database_and_table, TableName=f"{timestream_database_and_table}_3"
306+
)["Table"]
307+
if timestream_additional_kwargs is None:
308+
assert desc["MagneticStoreWriteProperties"].get("EnableMagneticStoreWrites") is False
309+
elif timestream_additional_kwargs["MagneticStoreWriteProperties"]["EnableMagneticStoreWrites"] is True:
310+
assert desc["MagneticStoreWriteProperties"].get("EnableMagneticStoreWrites") is True
311+
312+
wr.timestream.delete_table(database=timestream_database_and_table, table=f"{timestream_database_and_table}_3")
313+
tables_in_db = wr.timestream.list_tables(database=timestream_database_and_table)
314+
assert f"{timestream_database_and_table}_3" not in tables_in_db

0 commit comments

Comments
 (0)