1

I am facing some issues while querying Timestream DB from my NodeJS environment. I am receiving an empty array in response for all the queries that have large response The exact same queries are working when I use the console. So I am sure the query syntax and format is right. The documentation says when the response is greater than 1 MB then pagination is used. So I should receive paginated response with nextPageToken but instead I am getting [].

Other thing I noticed that the MaxRows param is not working. So there is one query that returns 84 rows. When I pass MaxRows = 83 or anything less than that then I am receiving empty array in response and when I pass MaxRows = 84 or anything more then I am receiving the actual response.

On the basis of these observations I think pagination is not working. Any idea on how to resolve this?

Jai Jain
  • 11
  • 1
  • 2
    Could you please add some examples of the code that you are using so we can see if the api is being used correctly? – Calummm Jul 21 '21 at 23:39

1 Answers1

1

It seems that any query which results in pagination returns an empty set of results (Rows) on the initial response. To get the first page of results, make a follow-up query passing through the NextToken string from the first query response. Then likewise for your second page of results, make a follow-up query passing through the NextToken string from the second query response.

This would look something like the following:

const client = new TimestreamQueryClient(...);
const queryString = 'select * from "db"."table"';
const result = await client.send(
    new TimestreamQueryCommand({
        QueryString: queryString,
    })
);
// result.Rows is an empty array

const firstPage = await client.send(
    new TimestreamQueryCommand({
        QueryString: queryString,
        NextToken: result.NextToken,
    })
);
// firstPage.Rows contains the first page of results

const secondPage = await client.send(
    new TimestreamQueryCommand({
        QueryString: queryString,
        NextToken: firstPage.NextToken,
    })
);
// secondPage.Rows contains the second page of results
Dharman
  • 30,962
  • 25
  • 85
  • 135