Skip to content

Commit f09a180

Browse files
Update generated code (#1785)
update generated code
1 parent 52f3b82 commit f09a180

12 files changed

+629
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NOT RELEASED
44

5+
### Added
6+
7+
- AWS api-change: This release adds support for Query Insights, a feature that provides details of query execution, enabling users to identify areas for improvement to optimize their queries, resulting in improved query performance and lower query costs.
8+
59
## 2.0.4
610

711
### Changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"extra": {
3131
"branch-alias": {
32-
"dev-master": "2.0-dev"
32+
"dev-master": "2.1-dev"
3333
}
3434
}
3535
}

src/Enum/QueryInsightsMode.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace AsyncAws\TimestreamQuery\Enum;
4+
5+
final class QueryInsightsMode
6+
{
7+
public const DISABLED = 'DISABLED';
8+
public const ENABLED_WITH_RATE_CONTROL = 'ENABLED_WITH_RATE_CONTROL';
9+
10+
public static function exists(string $value): bool
11+
{
12+
return isset([
13+
self::DISABLED => true,
14+
self::ENABLED_WITH_RATE_CONTROL => true,
15+
][$value]);
16+
}
17+
}

src/Input/QueryRequest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use AsyncAws\Core\Input;
77
use AsyncAws\Core\Request;
88
use AsyncAws\Core\Stream\StreamFactory;
9+
use AsyncAws\TimestreamQuery\ValueObject\QueryInsights;
910

1011
final class QueryRequest extends Input
1112
{
@@ -78,12 +79,23 @@ final class QueryRequest extends Input
7879
*/
7980
private $maxRows;
8081

82+
/**
83+
* Encapsulates settings for enabling `QueryInsights`.
84+
*
85+
* Enabling `QueryInsights` returns insights and metrics in addition to query results for the query that you executed.
86+
* You can use `QueryInsights` to tune your query performance.
87+
*
88+
* @var QueryInsights|null
89+
*/
90+
private $queryInsights;
91+
8192
/**
8293
* @param array{
8394
* QueryString?: string,
8495
* ClientToken?: null|string,
8596
* NextToken?: null|string,
8697
* MaxRows?: null|int,
98+
* QueryInsights?: null|QueryInsights|array,
8799
* '@region'?: string|null,
88100
* } $input
89101
*/
@@ -93,6 +105,7 @@ public function __construct(array $input = [])
93105
$this->clientToken = $input['ClientToken'] ?? null;
94106
$this->nextToken = $input['NextToken'] ?? null;
95107
$this->maxRows = $input['MaxRows'] ?? null;
108+
$this->queryInsights = isset($input['QueryInsights']) ? QueryInsights::create($input['QueryInsights']) : null;
96109
parent::__construct($input);
97110
}
98111

@@ -102,6 +115,7 @@ public function __construct(array $input = [])
102115
* ClientToken?: null|string,
103116
* NextToken?: null|string,
104117
* MaxRows?: null|int,
118+
* QueryInsights?: null|QueryInsights|array,
105119
* '@region'?: string|null,
106120
* }|QueryRequest $input
107121
*/
@@ -125,6 +139,11 @@ public function getNextToken(): ?string
125139
return $this->nextToken;
126140
}
127141

142+
public function getQueryInsights(): ?QueryInsights
143+
{
144+
return $this->queryInsights;
145+
}
146+
128147
public function getQueryString(): ?string
129148
{
130149
return $this->queryString;
@@ -177,6 +196,13 @@ public function setNextToken(?string $value): self
177196
return $this;
178197
}
179198

199+
public function setQueryInsights(?QueryInsights $value): self
200+
{
201+
$this->queryInsights = $value;
202+
203+
return $this;
204+
}
205+
180206
public function setQueryString(?string $value): self
181207
{
182208
$this->queryString = $value;
@@ -201,6 +227,9 @@ private function requestBody(): array
201227
if (null !== $v = $this->maxRows) {
202228
$payload['MaxRows'] = $v;
203229
}
230+
if (null !== $v = $this->queryInsights) {
231+
$payload['QueryInsights'] = $v->requestBody();
232+
}
204233

205234
return $payload;
206235
}

src/Result/QueryResponse.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
use AsyncAws\TimestreamQuery\TimestreamQueryClient;
1010
use AsyncAws\TimestreamQuery\ValueObject\ColumnInfo;
1111
use AsyncAws\TimestreamQuery\ValueObject\Datum;
12+
use AsyncAws\TimestreamQuery\ValueObject\QueryInsightsResponse;
13+
use AsyncAws\TimestreamQuery\ValueObject\QuerySpatialCoverage;
14+
use AsyncAws\TimestreamQuery\ValueObject\QuerySpatialCoverageMax;
1215
use AsyncAws\TimestreamQuery\ValueObject\QueryStatus;
16+
use AsyncAws\TimestreamQuery\ValueObject\QueryTemporalRange;
17+
use AsyncAws\TimestreamQuery\ValueObject\QueryTemporalRangeMax;
1318
use AsyncAws\TimestreamQuery\ValueObject\Row;
1419
use AsyncAws\TimestreamQuery\ValueObject\TimeSeriesDataPoint;
1520
use AsyncAws\TimestreamQuery\ValueObject\Type;
@@ -54,6 +59,13 @@ class QueryResponse extends Result implements \IteratorAggregate
5459
*/
5560
private $queryStatus;
5661

62+
/**
63+
* Encapsulates `QueryInsights` containing insights and metrics related to the query that you executed.
64+
*
65+
* @var QueryInsightsResponse|null
66+
*/
67+
private $queryInsightsResponse;
68+
5769
/**
5870
* @return ColumnInfo[]
5971
*/
@@ -88,6 +100,13 @@ public function getQueryId(): string
88100
return $this->queryId;
89101
}
90102

103+
public function getQueryInsightsResponse(): ?QueryInsightsResponse
104+
{
105+
$this->initialize();
106+
107+
return $this->queryInsightsResponse;
108+
}
109+
91110
public function getQueryStatus(): ?QueryStatus
92111
{
93112
$this->initialize();
@@ -148,6 +167,7 @@ protected function populateResult(Response $response): void
148167
$this->rows = $this->populateResultRowList($data['Rows'] ?? []);
149168
$this->columnInfo = $this->populateResultColumnInfoList($data['ColumnInfo'] ?? []);
150169
$this->queryStatus = empty($data['QueryStatus']) ? null : $this->populateResultQueryStatus($data['QueryStatus']);
170+
$this->queryInsightsResponse = empty($data['QueryInsightsResponse']) ? null : $this->populateResultQueryInsightsResponse($data['QueryInsightsResponse']);
151171
}
152172

153173
private function populateResultColumnInfo(array $json): ColumnInfo
@@ -195,6 +215,52 @@ private function populateResultDatumList(array $json): array
195215
return $items;
196216
}
197217

218+
/**
219+
* @return string[]
220+
*/
221+
private function populateResultPartitionKeyList(array $json): array
222+
{
223+
$items = [];
224+
foreach ($json as $item) {
225+
$a = isset($item) ? (string) $item : null;
226+
if (null !== $a) {
227+
$items[] = $a;
228+
}
229+
}
230+
231+
return $items;
232+
}
233+
234+
private function populateResultQueryInsightsResponse(array $json): QueryInsightsResponse
235+
{
236+
return new QueryInsightsResponse([
237+
'QuerySpatialCoverage' => empty($json['QuerySpatialCoverage']) ? null : $this->populateResultQuerySpatialCoverage($json['QuerySpatialCoverage']),
238+
'QueryTemporalRange' => empty($json['QueryTemporalRange']) ? null : $this->populateResultQueryTemporalRange($json['QueryTemporalRange']),
239+
'QueryTableCount' => isset($json['QueryTableCount']) ? (int) $json['QueryTableCount'] : null,
240+
'OutputRows' => isset($json['OutputRows']) ? (int) $json['OutputRows'] : null,
241+
'OutputBytes' => isset($json['OutputBytes']) ? (int) $json['OutputBytes'] : null,
242+
'UnloadPartitionCount' => isset($json['UnloadPartitionCount']) ? (int) $json['UnloadPartitionCount'] : null,
243+
'UnloadWrittenRows' => isset($json['UnloadWrittenRows']) ? (int) $json['UnloadWrittenRows'] : null,
244+
'UnloadWrittenBytes' => isset($json['UnloadWrittenBytes']) ? (int) $json['UnloadWrittenBytes'] : null,
245+
]);
246+
}
247+
248+
private function populateResultQuerySpatialCoverage(array $json): QuerySpatialCoverage
249+
{
250+
return new QuerySpatialCoverage([
251+
'Max' => empty($json['Max']) ? null : $this->populateResultQuerySpatialCoverageMax($json['Max']),
252+
]);
253+
}
254+
255+
private function populateResultQuerySpatialCoverageMax(array $json): QuerySpatialCoverageMax
256+
{
257+
return new QuerySpatialCoverageMax([
258+
'Value' => isset($json['Value']) ? (float) $json['Value'] : null,
259+
'TableArn' => isset($json['TableArn']) ? (string) $json['TableArn'] : null,
260+
'PartitionKey' => !isset($json['PartitionKey']) ? null : $this->populateResultPartitionKeyList($json['PartitionKey']),
261+
]);
262+
}
263+
198264
private function populateResultQueryStatus(array $json): QueryStatus
199265
{
200266
return new QueryStatus([
@@ -204,6 +270,21 @@ private function populateResultQueryStatus(array $json): QueryStatus
204270
]);
205271
}
206272

273+
private function populateResultQueryTemporalRange(array $json): QueryTemporalRange
274+
{
275+
return new QueryTemporalRange([
276+
'Max' => empty($json['Max']) ? null : $this->populateResultQueryTemporalRangeMax($json['Max']),
277+
]);
278+
}
279+
280+
private function populateResultQueryTemporalRangeMax(array $json): QueryTemporalRangeMax
281+
{
282+
return new QueryTemporalRangeMax([
283+
'Value' => isset($json['Value']) ? (int) $json['Value'] : null,
284+
'TableArn' => isset($json['TableArn']) ? (string) $json['TableArn'] : null,
285+
]);
286+
}
287+
207288
private function populateResultRow(array $json): Row
208289
{
209290
return new Row([

src/TimestreamQueryClient.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use AsyncAws\TimestreamQuery\Result\DescribeEndpointsResponse;
2323
use AsyncAws\TimestreamQuery\Result\PrepareQueryResponse;
2424
use AsyncAws\TimestreamQuery\Result\QueryResponse;
25+
use AsyncAws\TimestreamQuery\ValueObject\QueryInsights;
2526

2627
class TimestreamQueryClient extends AbstractApi
2728
{
@@ -135,9 +136,16 @@ public function prepareQuery($input): PrepareQueryResponse
135136
}
136137

137138
/**
138-
* `Query` is a synchronous operation that enables you to run a query against your Amazon Timestream data. `Query` will
139-
* time out after 60 seconds. You must update the default timeout in the SDK to support a timeout of 60 seconds. See the
140-
* code sample [^1] for details.
139+
* `Query` is a synchronous operation that enables you to run a query against your Amazon Timestream data.
140+
*
141+
* If you enabled `QueryInsights`, this API also returns insights and metrics related to the query that you executed.
142+
* `QueryInsights` helps with performance tuning of your query.
143+
*
144+
* > The maximum number of `Query` API requests you're allowed to make with `QueryInsights` enabled is 1 query per
145+
* > second (QPS). If you exceed this query rate, it might result in throttling.
146+
*
147+
* `Query` will time out after 60 seconds. You must update the default timeout in the SDK to support a timeout of 60
148+
* seconds. See the code sample [^1] for details.
141149
*
142150
* Your query request will fail in the following cases:
143151
*
@@ -162,6 +170,7 @@ public function prepareQuery($input): PrepareQueryResponse
162170
* ClientToken?: null|string,
163171
* NextToken?: null|string,
164172
* MaxRows?: null|int,
173+
* QueryInsights?: null|QueryInsights|array,
165174
* '@region'?: string|null,
166175
* }|QueryRequest $input
167176
*

src/ValueObject/QueryInsights.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace AsyncAws\TimestreamQuery\ValueObject;
4+
5+
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\TimestreamQuery\Enum\QueryInsightsMode;
7+
8+
/**
9+
* `QueryInsights` is a performance tuning feature that helps you optimize your queries, reducing costs and improving
10+
* performance. With `QueryInsights`, you can assess the pruning efficiency of your queries and identify areas for
11+
* improvement to enhance query performance. With `QueryInsights`, you can also analyze the effectiveness of your
12+
* queries in terms of temporal and spatial pruning, and identify opportunities to improve performance. Specifically,
13+
* you can evaluate how well your queries use time-based and partition key-based indexing strategies to optimize data
14+
* retrieval. To optimize query performance, it's essential that you fine-tune both the temporal and spatial parameters
15+
* that govern query execution.
16+
*
17+
* The key metrics provided by `QueryInsights` are `QuerySpatialCoverage` and `QueryTemporalRange`.
18+
* `QuerySpatialCoverage` indicates how much of the spatial axis the query scans, with lower values being more
19+
* efficient. `QueryTemporalRange` shows the time range scanned, with narrower ranges being more performant.
20+
*
21+
* **Benefits of QueryInsights**
22+
*
23+
* The following are the key benefits of using `QueryInsights`:
24+
*
25+
* - **Identifying inefficient queries** – `QueryInsights` provides information on the time-based and attribute-based
26+
* pruning of the tables accessed by the query. This information helps you identify the tables that are sub-optimally
27+
* accessed.
28+
* - **Optimizing your data model and partitioning** – You can use the `QueryInsights` information to access and
29+
* fine-tune your data model and partitioning strategy.
30+
* - **Tuning queries** – `QueryInsights` highlights opportunities to use indexes more effectively.
31+
*
32+
* > The maximum number of `Query` API requests you're allowed to make with `QueryInsights` enabled is 1 query per
33+
* > second (QPS). If you exceed this query rate, it might result in throttling.
34+
*/
35+
final class QueryInsights
36+
{
37+
/**
38+
* Provides the following modes to enable `QueryInsights`:
39+
*
40+
* - `ENABLED_WITH_RATE_CONTROL` – Enables `QueryInsights` for the queries being processed. This mode also includes a
41+
* rate control mechanism, which limits the `QueryInsights` feature to 1 query per second (QPS).
42+
* - `DISABLED` – Disables `QueryInsights`.
43+
*
44+
* @var QueryInsightsMode::*
45+
*/
46+
private $mode;
47+
48+
/**
49+
* @param array{
50+
* Mode: QueryInsightsMode::*,
51+
* } $input
52+
*/
53+
public function __construct(array $input)
54+
{
55+
$this->mode = $input['Mode'] ?? $this->throwException(new InvalidArgument('Missing required field "Mode".'));
56+
}
57+
58+
/**
59+
* @param array{
60+
* Mode: QueryInsightsMode::*,
61+
* }|QueryInsights $input
62+
*/
63+
public static function create($input): self
64+
{
65+
return $input instanceof self ? $input : new self($input);
66+
}
67+
68+
/**
69+
* @return QueryInsightsMode::*
70+
*/
71+
public function getMode(): string
72+
{
73+
return $this->mode;
74+
}
75+
76+
/**
77+
* @internal
78+
*/
79+
public function requestBody(): array
80+
{
81+
$payload = [];
82+
$v = $this->mode;
83+
if (!QueryInsightsMode::exists($v)) {
84+
throw new InvalidArgument(\sprintf('Invalid parameter "Mode" for "%s". The value "%s" is not a valid "QueryInsightsMode".', __CLASS__, $v));
85+
}
86+
$payload['Mode'] = $v;
87+
88+
return $payload;
89+
}
90+
91+
/**
92+
* @return never
93+
*/
94+
private function throwException(\Throwable $exception)
95+
{
96+
throw $exception;
97+
}
98+
}

0 commit comments

Comments
 (0)