Skip to content

Commit 5199363

Browse files
authored
Add timestream pagination config (#843)
1 parent 165c786 commit 5199363

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

awswrangler/timestream.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,17 @@ def write(
199199
return [item for sublist in res for item in sublist]
200200

201201

202-
def query(sql: str, boto3_session: Optional[boto3.Session] = None) -> pd.DataFrame:
202+
def query(
203+
sql: str, pagination_config: Dict[str, Any] = None, boto3_session: Optional[boto3.Session] = None
204+
) -> pd.DataFrame:
203205
"""Run a query and retrieve the result as a Pandas DataFrame.
204206
205207
Parameters
206208
----------
207209
sql: str
208210
SQL query.
211+
pagination_config: Dict[str, Any]
212+
Pagination configuration dictionary of a form {'MaxItems': 10, 'PageSize': 10, 'StartingToken': '...'}
209213
boto3_session : boto3.Session(), optional
210214
Boto3 Session. The default boto3 Session will be used if boto3_session receive None.
211215
@@ -230,7 +234,7 @@ def query(sql: str, boto3_session: Optional[boto3.Session] = None) -> pd.DataFra
230234
paginator = client.get_paginator("query")
231235
rows: List[List[Any]] = []
232236
schema: List[Dict[str, str]] = []
233-
for page in paginator.paginate(QueryString=sql):
237+
for page in paginator.paginate(QueryString=sql, PaginationConfig=pagination_config or {}):
234238
if not schema:
235239
schema = _process_schema(page=page)
236240
for row in page["Rows"]:

tests/test_timestream.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
from datetime import datetime
33

44
import pandas as pd
5+
import pytest
56

67
import awswrangler as wr
78

89
logging.getLogger("awswrangler").setLevel(logging.DEBUG)
910

1011

11-
def test_basic_scenario(timestream_database_and_table):
12+
@pytest.mark.parametrize("pagination", [None, {}, {"MaxItems": 3, "PageSize": 2}])
13+
def test_basic_scenario(timestream_database_and_table, pagination):
1214
name = timestream_database_and_table
1315
df = pd.DataFrame(
1416
{
@@ -41,7 +43,8 @@ def test_basic_scenario(timestream_database_and_table):
4143
FROM "{name}"."{name}"
4244
ORDER BY time
4345
DESC LIMIT 10
44-
"""
46+
""",
47+
pagination_config=pagination,
4548
)
4649
assert df.shape == (3, 8)
4750

0 commit comments

Comments
 (0)