How can I use the Timestream Query Client - AWS SDK for JavaScript v3 > Class QueryCommand to query all table rows?

0

Hello,

I have successfully configured Class QueryCommand on a ReactJS project and it works well when I use a query that returns less than 2,000 records.

The problem I have is when I use a broader query term like to return all the rows inside the table then the QueryCommand just loops with a ProgressPercentage of 0, it only returns the metadata of the query but no data (the same query works well through the AWS Timestream Query Editor). This is what returns on my console log:

Current query status: {"CumulativeBytesMetered":10000000,"CumulativeBytesScanned":0,"ProgressPercentage":0}

I read in the QueryCommand class documentation (link shared above) the following:

If the size of the row (including the query metadata) exceeds 1 MB, then the query will fail with the following error message: Query aborted as max page response size has been exceeded by the output result row

So perhaps this is the reason for my problem but I am not getting that error either.

My build is the same as the AWS timestream sample found here: https://github.com/awslabs/amazon-timestream-tools/tree/f3e2a6037a158eed41ed285deec4562d5b3c73fa/sample_apps/js with @aws-sdk/client-timestream-query

My only question is:

  • Is it possible to use the Class QueryCommand to query and paginate all the records in a table?

Update:

I've found out that there is something strange going on the iteration seems to be happening but not showing, the following picture is taken from the console log: Empty Iteration

If I start a page refresh then I suddenly start getting all the query rows while the page refresh last: On page refresh

Best regards. Gianpiero Benvenuto

asked a year ago1137 views
1 Answer
0

Yes it is possible. To paginate a TimeStream query command call, you can use the "MaxResults" and "NextToken" parameters in your API request.

https://docs.aws.amazon.com/timestream/latest/developerguide/API_query_Query.html

You could iterate until the response contains a NextToken and provising MaxResults as query parameters in the request.

Hope it helps!

profile picture
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions