|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace AsyncAws\Athena\Result; |
| 4 | + |
| 5 | +use AsyncAws\Athena\ValueObject\ColumnInfo; |
| 6 | +use AsyncAws\Athena\ValueObject\Datum; |
| 7 | +use AsyncAws\Athena\ValueObject\ResultSet; |
| 8 | +use AsyncAws\Athena\ValueObject\ResultSetMetadata; |
| 9 | +use AsyncAws\Athena\ValueObject\Row; |
| 10 | +use AsyncAws\Core\Response; |
| 11 | +use AsyncAws\Core\Result; |
| 12 | + |
| 13 | +class GetQueryResultsOutput extends Result |
| 14 | +{ |
| 15 | + /** |
| 16 | + * The number of rows inserted with a `CREATE TABLE AS SELECT` statement. |
| 17 | + */ |
| 18 | + private $updateCount; |
| 19 | + |
| 20 | + /** |
| 21 | + * The results of the query execution. |
| 22 | + */ |
| 23 | + private $resultSet; |
| 24 | + |
| 25 | + /** |
| 26 | + * A token generated by the Athena service that specifies where to continue pagination if a previous request was |
| 27 | + * truncated. To obtain the next set of pages, pass in the `NextToken` from the response object of the previous page |
| 28 | + * call. |
| 29 | + */ |
| 30 | + private $nextToken; |
| 31 | + |
| 32 | + public function getNextToken(): ?string |
| 33 | + { |
| 34 | + $this->initialize(); |
| 35 | + |
| 36 | + return $this->nextToken; |
| 37 | + } |
| 38 | + |
| 39 | + public function getResultSet(): ?ResultSet |
| 40 | + { |
| 41 | + $this->initialize(); |
| 42 | + |
| 43 | + return $this->resultSet; |
| 44 | + } |
| 45 | + |
| 46 | + public function getUpdateCount(): ?string |
| 47 | + { |
| 48 | + $this->initialize(); |
| 49 | + |
| 50 | + return $this->updateCount; |
| 51 | + } |
| 52 | + |
| 53 | + protected function populateResult(Response $response): void |
| 54 | + { |
| 55 | + $data = $response->toArray(); |
| 56 | + |
| 57 | + $this->updateCount = isset($data['UpdateCount']) ? (string) $data['UpdateCount'] : null; |
| 58 | + $this->resultSet = empty($data['ResultSet']) ? null : $this->populateResultResultSet($data['ResultSet']); |
| 59 | + $this->nextToken = isset($data['NextToken']) ? (string) $data['NextToken'] : null; |
| 60 | + } |
| 61 | + |
| 62 | + private function populateResultColumnInfo(array $json): ColumnInfo |
| 63 | + { |
| 64 | + return new ColumnInfo([ |
| 65 | + 'CatalogName' => isset($json['CatalogName']) ? (string) $json['CatalogName'] : null, |
| 66 | + 'SchemaName' => isset($json['SchemaName']) ? (string) $json['SchemaName'] : null, |
| 67 | + 'TableName' => isset($json['TableName']) ? (string) $json['TableName'] : null, |
| 68 | + 'Name' => (string) $json['Name'], |
| 69 | + 'Label' => isset($json['Label']) ? (string) $json['Label'] : null, |
| 70 | + 'Type' => (string) $json['Type'], |
| 71 | + 'Precision' => isset($json['Precision']) ? (int) $json['Precision'] : null, |
| 72 | + 'Scale' => isset($json['Scale']) ? (int) $json['Scale'] : null, |
| 73 | + 'Nullable' => isset($json['Nullable']) ? (string) $json['Nullable'] : null, |
| 74 | + 'CaseSensitive' => isset($json['CaseSensitive']) ? filter_var($json['CaseSensitive'], \FILTER_VALIDATE_BOOLEAN) : null, |
| 75 | + ]); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @return ColumnInfo[] |
| 80 | + */ |
| 81 | + private function populateResultColumnInfoList(array $json): array |
| 82 | + { |
| 83 | + $items = []; |
| 84 | + foreach ($json as $item) { |
| 85 | + $items[] = $this->populateResultColumnInfo($item); |
| 86 | + } |
| 87 | + |
| 88 | + return $items; |
| 89 | + } |
| 90 | + |
| 91 | + private function populateResultDatum(array $json): Datum |
| 92 | + { |
| 93 | + return new Datum([ |
| 94 | + 'VarCharValue' => isset($json['VarCharValue']) ? (string) $json['VarCharValue'] : null, |
| 95 | + ]); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * @return Datum[] |
| 100 | + */ |
| 101 | + private function populateResultDatumList(array $json): array |
| 102 | + { |
| 103 | + $items = []; |
| 104 | + foreach ($json as $item) { |
| 105 | + $items[] = $this->populateResultDatum($item); |
| 106 | + } |
| 107 | + |
| 108 | + return $items; |
| 109 | + } |
| 110 | + |
| 111 | + private function populateResultResultSet(array $json): ResultSet |
| 112 | + { |
| 113 | + return new ResultSet([ |
| 114 | + 'Rows' => !isset($json['Rows']) ? null : $this->populateResultRowList($json['Rows']), |
| 115 | + 'ResultSetMetadata' => empty($json['ResultSetMetadata']) ? null : $this->populateResultResultSetMetadata($json['ResultSetMetadata']), |
| 116 | + ]); |
| 117 | + } |
| 118 | + |
| 119 | + private function populateResultResultSetMetadata(array $json): ResultSetMetadata |
| 120 | + { |
| 121 | + return new ResultSetMetadata([ |
| 122 | + 'ColumnInfo' => !isset($json['ColumnInfo']) ? null : $this->populateResultColumnInfoList($json['ColumnInfo']), |
| 123 | + ]); |
| 124 | + } |
| 125 | + |
| 126 | + private function populateResultRow(array $json): Row |
| 127 | + { |
| 128 | + return new Row([ |
| 129 | + 'Data' => !isset($json['Data']) ? null : $this->populateResultDatumList($json['Data']), |
| 130 | + ]); |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * @return Row[] |
| 135 | + */ |
| 136 | + private function populateResultRowList(array $json): array |
| 137 | + { |
| 138 | + $items = []; |
| 139 | + foreach ($json as $item) { |
| 140 | + $items[] = $this->populateResultRow($item); |
| 141 | + } |
| 142 | + |
| 143 | + return $items; |
| 144 | + } |
| 145 | +} |
0 commit comments