Query
Query
is a synchronous operation that enables you to run a query against
your Amazon Timestream data.
If you enabled QueryInsights
, this API also returns insights and metrics related to the query that you executed. QueryInsights
helps with performance tuning of your query. For more information about QueryInsights
, see Using query insights to optimize queries in Amazon Timestream.
Note
The maximum number of Query
API requests you're allowed to make with QueryInsights
enabled is 1 query per second (QPS). If you exceed this query rate, it might result in throttling.
Query
will time out 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 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
-
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
",
"QueryInsights": {
"Mode": "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 aClientToken
makes the call toQuery
idempotent. This means that running the same query repeatedly will produce the same result. In other words, making multiple identicalQuery
requests has the same effect as making a single request. When usingClientToken
in a query, note the following:-
If the Query API is instantiated without a
ClientToken
, the Query SDK generates aClientToken
on your behalf. -
If the
Query
invocation only contains theClientToken
but does not include aNextToken
, that invocation ofQuery
is assumed to be a new query run. -
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. The initial run ofQuery
with aMaxRows
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 aNextToken
, which can then be used in subsequent calls to fetch the result set. To resume pagination, provide theNextToken
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 number 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 usingNextToken
, that particular invocation is assumed to be a subsequent invocation of a prior call toQuery
, and a result set is returned. However, if theQuery
invocation only contains theClientToken
, that invocation ofQuery
is assumed to be a new query run.Note the following when using NextToken in a query:
-
A pagination token can be used for up to five
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 recentnextToken
. -
Suppose a
Query
invocation returns twoNextToken
values,TokenA
andTokenB
. IfTokenB
is used in a subsequentQuery
invocation, thenTokenA
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 untilnull
is returned, at which point a newNextToken
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
-
- QueryInsights
-
Encapsulates settings for enabling
QueryInsights
.Enabling
QueryInsights
returns insights and metrics in addition to query results for the query that you executed. You can useQueryInsights
to tune your query performance.Type: QueryInsights object
Required: No
- QueryString
-
The query to be run 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",
"QueryInsightsResponse": {
"OutputBytes": number,
"OutputRows": number,
"QuerySpatialCoverage": {
"Max": {
"PartitionKey": [ "string" ],
"TableArn": "string",
"Value": number
}
},
"QueryTableCount": number,
"QueryTemporalRange": {
"Max": {
"TableArn": "string",
"Value": number
}
},
"UnloadPartitionCount": number,
"UnloadWrittenBytes": number,
"UnloadWrittenRows": number
},
"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]+
- QueryInsightsResponse
-
Encapsulates
QueryInsights
containing insights and metrics related to the query that you executed.Type: QueryInsightsResponse object
- 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
-
The service was unable to fully process this request because of an internal server error.
HTTP Status Code: 400
- InvalidEndpointException
-
The requested endpoint was not valid.
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: