Query - Amazon Timestream

Query

Query is a synchronous operation that enables you to execute a query against your Amazon Timestream data. Query will timeout after 60 seconds. You must update the default timeout in the SDK to support a timeout of 60 seconds. See the code sample for details.

Your query request will fail in the following cases:

  • If you submit a Query request with the same client token outside of the 5-minute idempotency window.

  • If you submit a Query request with the same client token, but change other parameters, within the 5-minute idempotency window.

  • If the size of the row (including the query metadata) exceeds 1MB, 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

  • If the IAM principal of the query initiator and the result reader are not the same and/or the query initiator and the result reader do not have the same query string in the query requests, the query will fail with an Invalid pagination token error.

Request Syntax

{ "ClientToken": "string", "MaxRows": number, "NextToken": "string", "QueryString": "string" }

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.

ClientToken

Unique, case-sensitive string of up to 64 ASCII characters specified when a Query request is made. Providing a ClientToken makes the call to Query idempotent, meaning that executing the same query repeatedly will produce the same result. In other words, making multiple identical Query requests has the same effect as making a single request. When using ClientToken in a query, note the following:

  • If the Query API is instantiated without a ClientToken, the Query SDK generates a ClientToken on your behalf.

  • If the Query invocation only contains the ClientToken but does not include a NextToken, that invocation of Query is assumed to be a new query execution.

  • If the invocation contains NextToken, that particular invocation is assumed to be a subsequent invocation of a prior call to the Query API, and a result set is returned.

  • After 4 hours, any request with the same ClientToken is treated as a new request.

Type: String

Length Constraints: Minimum length of 32. Maximum length of 128.

Required: No

MaxRows

The total number of rows to be returned in the Query output. Initial execution of Query with a MaxRows value specified will return the result set of the query in two cases:

  • the size of the result is less than 1MB

  • the number of rows in the result set is less than the value of maxRows

Otherwise, the initial invocation of Query only returns a NextToken, which can then be used in subsequent calls to fetch the result set. To resume pagination, provide the NextToken value in the subsequent command.

If the row size is large (e.g. a row has many columns), Timestream may return fewer rows to keep the response size from exceeding the 1 MB limit. If MaxRows is not provided, Timestream will send the necessary amount of rows to meet the 1 MB limit.

Type: Integer

Valid Range: Minimum value of 1. Maximum value of 1000.

Required: No

NextToken

A pagination token used to return a set of results. When the Query API is invoked using NextToken, that particular invocation is assumed to be a subsequent invocation of a prior call to Query, and a result set is returned. However, if the Query invocation only contains the ClientToken, that invocation of Query is assumed to be a new query execution.

Note the following when using NextToken in a query:

  • A pagination token can be used for up to 5 Query invocations, OR for a duration of up to 1 hour – whichever comes first.

  • Using the same NextToken will return the same set of records. To keep paginating through the result set, you must to use the most recent nextToken.

  • Suppose a Query invocation returns two NextToken values, TokenA and TokenB. If TokenB is used in a subsequent Query invocation, then TokenA is invalidated and cannot be reused.

  • To request a previous result set from a query after pagination has begun, you must re-invoke the Query API.

  • The latest NextToken should be used to paginate until null is returned, at which point a new NextToken should be used.

  • If the IAM principal of the query initiator and the result reader are not the same and/or the query initiator and the result reader do not have the same query string in the query requests, the query will fail with an Invalid pagination token error.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 2048.

Required: No

QueryString

The query to be executed by Timestream.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 262144.

Required: Yes

Response Syntax

{ "ColumnInfo": [ { "Name": "string", "Type": { "ArrayColumnInfo": "ColumnInfo", "RowColumnInfo": [ "ColumnInfo" ], "ScalarType": "string", "TimeSeriesMeasureValueColumnInfo": "ColumnInfo" } } ], "NextToken": "string", "QueryId": "string", "QueryStatus": { "CumulativeBytesMetered": number, "CumulativeBytesScanned": number, "ProgressPercentage": number }, "Rows": [ { "Data": [ { "ArrayValue": [ "Datum" ], "NullValue": boolean, "RowValue": "Row", "ScalarValue": "string", "TimeSeriesValue": [ { "Time": "string", "Value": "Datum" } ] } ] } ] }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

ColumnInfo

The column data types of the returned result set.

Type: Array of ColumnInfo objects

NextToken

A pagination token that can be used again on a Query call to get the next set of results.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 2048.

QueryId

A unique ID for the given query.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 64.

Pattern: [a-zA-Z0-9]+

QueryStatus

Information about the status of the query, including progress and bytes scanned.

Type: QueryStatus object

Rows

The result set rows returned by the query.

Type: Array of Row objects

Errors

For information about the errors that are common to all actions, see Common Errors.

AccessDeniedException

You are not authorized to perform this action.

HTTP Status Code: 400

ConflictException

Unable to poll results for a cancelled query.

HTTP Status Code: 400

InternalServerException

Timestream was unable to fully process this request because of an internal server error.

HTTP Status Code: 400

InvalidEndpointException

The requested endpoint was invalid.

HTTP Status Code: 400

QueryExecutionException

Timestream was unable to run the query successfully.

HTTP Status Code: 400

ThrottlingException

The request was denied due to request throttling.

HTTP Status Code: 400

ValidationException

Invalid or malformed request.

HTTP Status Code: 400

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: