Skip to content

Commit aacfe68

Browse files
async_aws (Athena Client): create aws Athena Client with somes operations (#1388)
* async_aws (Athena Client): create aws Athena Client with somes operations * async-aws(Athena Client): add new ligne in psalm.baseline.xml * Apply suggestions from code review --------- Co-authored-by: Jérémy Derussé <jeremy@derusse.com>
1 parent b8e87e0 commit aacfe68

File tree

162 files changed

+11084
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+11084
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ See full documentation on [https://async-aws.com](https://async-aws.com).
1212
| --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1313
| [async-aws/core](https://github.com/async-aws/core) | [![Latest Stable Version](https://poser.pugx.org/async-aws/core/v/stable)](https://packagist.org/packages/async-aws/core) [![Total Downloads](https://poser.pugx.org/async-aws/core/downloads)](https://packagist.org/packages/async-aws/core) | [![](https://github.com/async-aws/core/workflows/BC%20Check/badge.svg?branch=master)](https://github.com/async-aws/core/actions) | [![](https://async-aws-pr.github.io/commits-since-release-counter/core.svg)](https://github.com/async-aws/core/releases) |
1414
| [async-aws/app-sync](https://github.com/async-aws/app-sync) | [![Latest Stable Version](https://poser.pugx.org/async-aws/app-sync/v/stable)](https://packagist.org/packages/async-aws/app-sync) [![Total Downloads](https://poser.pugx.org/async-aws/app-sync/downloads)](https://packagist.org/packages/async-aws/app-sync) | [![](https://github.com/async-aws/app-sync/workflows/BC%20Check/badge.svg?branch=master)](https://github.com/async-aws/app-sync/actions) | [![](https://async-aws-pr.github.io/commits-since-release-counter/app-sync.svg)](https://github.com/async-aws/app-sync/releases) |
15+
| [async-aws/athena](https://github.com/async-aws/athena) | [![Latest Stable Version](https://poser.pugx.org/async-aws/athena/v/stable)](https://packagist.org/packages/async-aws/athena) [![Total Downloads](https://poser.pugx.org/async-aws/athena/downloads)](https://packagist.org/packages/async-aws/athena) | [![](https://github.com/async-aws/athena/workflows/BC%20Check/badge.svg?branch=master)](https://github.com/async-aws/athena/actions) | [![](https://async-aws-pr.github.io/commits-since-release-counter/athena.svg)](https://github.com/async-aws/athena/releases) |
1516
| [async-aws/cloud-formation](https://github.com/async-aws/cloud-formation) | [![Latest Stable Version](https://poser.pugx.org/async-aws/cloud-formation/v/stable)](https://packagist.org/packages/async-aws/cloud-formation) [![Total Downloads](https://poser.pugx.org/async-aws/cloud-formation/downloads)](https://packagist.org/packages/async-aws/cloud-formation) | [![](https://github.com/async-aws/cloud-formation/workflows/BC%20Check/badge.svg?branch=master)](https://github.com/async-aws/cloud-formation/actions) | [![](https://async-aws-pr.github.io/commits-since-release-counter/cloud-formation.svg)](https://github.com/async-aws/cloud-formation/releases) |
1617
| [async-aws/cloud-front](https://github.com/async-aws/cloud-front) | [![Latest Stable Version](https://poser.pugx.org/async-aws/cloud-front/v/stable)](https://packagist.org/packages/async-aws/cloud-front) [![Total Downloads](https://poser.pugx.org/async-aws/cloud-front/downloads)](https://packagist.org/packages/async-aws/cloud-front) | [![](https://github.com/async-aws/cloud-front/workflows/BC%20Check/badge.svg?branch=master)](https://github.com/async-aws/cloud-front/actions) | [![](https://async-aws-pr.github.io/commits-since-release-counter/cloud-front.svg)](https://github.com/async-aws/cloud-front/releases) |
1718
| [async-aws/cloud-watch](https://github.com/async-aws/cloud-watch) | [![Latest Stable Version](https://poser.pugx.org/async-aws/cloud-watch/v/stable)](https://packagist.org/packages/async-aws/cloud-watch) [![Total Downloads](https://poser.pugx.org/async-aws/cloud-watch/downloads)](https://packagist.org/packages/async-aws/cloud-watch) | [![](https://github.com/async-aws/cloud-watch/workflows/BC%20Check/badge.svg?branch=master)](https://github.com/async-aws/cloud-watch/actions) | [![](https://async-aws-pr.github.io/commits-since-release-counter/cloud-watch.svg)](https://github.com/async-aws/cloud-watch/releases) |

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"autoload": {
5050
"psr-4": {
5151
"AsyncAws\\AppSync\\": "src/Service/AppSync/src",
52+
"AsyncAws\\Athena\\": "src/Service/Athena/src",
5253
"AsyncAws\\CloudFormation\\": "src/Service/CloudFormation/src",
5354
"AsyncAws\\CloudFront\\": "src/Service/CloudFront/src",
5455
"AsyncAws\\CloudWatchLogs\\": "src/Service/CloudWatchLogs/src",
@@ -100,6 +101,7 @@
100101
"autoload-dev": {
101102
"psr-4": {
102103
"AsyncAws\\AppSync\\Tests\\": "src/Service/AppSync/tests",
104+
"AsyncAws\\Athena\\Tests\\": "src/Service/Athena/tests",
103105
"AsyncAws\\CloudFormation\\Tests\\": "src/Service/CloudFormation/tests",
104106
"AsyncAws\\CloudFront\\Tests\\": "src/Service/CloudFront/tests",
105107
"AsyncAws\\CloudWatchLogs\\Tests\\": "src/Service/CloudWatchLogs/tests",

couscous.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ menu:
3434
app-sync:
3535
text: AppSync
3636
url: /clients/app-sync.html
37+
athena:
38+
text: Athena
39+
url: /clients/athena.html
3740
cf:
3841
text: Cloud Formation
3942
url: /clients/cf.html

docs/clients/athena.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
layout: client
3+
category: clients
4+
name: Athena
5+
package: async-aws/athena
6+
---
7+
8+
## Usage
9+
10+
### List Databases
11+
12+
```php
13+
use AsyncAws\Athena\AthenaClient;
14+
use AsyncAws\Athena\Input\ListDatabasesInput;
15+
16+
$athena = new AthenaClient();
17+
18+
$result = $athena->listDatabases(new ListDatabasesInput([
19+
'CatalogName' => 'my_catalog'
20+
]));
21+
22+
foreach ($result->getDatabaseList() as $database) {
23+
echo 'Database name : ' . $database->getName();
24+
echo 'Database description : ' . $database->getDescription();
25+
echo 'Database parameter : '.PHP_EOL;
26+
print_r($database->getParameters());
27+
}
28+
29+
```
30+
more information [listDatabases](https://docs.aws.amazon.com/athena/latest/APIReference/API_ListDatabases.html)
31+
32+
### Query to Amazon Athena
33+
34+
```php
35+
use AsyncAws\Athena\AthenaClient;
36+
use AsyncAws\Athena\Input\StartQueryExecutionInput;
37+
use AsyncAws\Athena\Input\DescribeTableInput;
38+
use AsyncAws\Athena\ValueObject\QueryExecutionContext;
39+
use AsyncAws\Athena\ValueObject\ResultConfiguration;
40+
use AsyncAws\Athena\ValueObject\EncryptionConfiguration;
41+
use AsyncAws\Athena\ValueObject\AclConfiguration;
42+
use AsyncAws\Athena\ValueObject\ResultReuseByAgeConfiguration;
43+
use AsyncAws\Athena\Input\GetQueryExecutionInput;
44+
use AsyncAws\Athena\Input\GetQueryResultsInput;
45+
use AsyncAws\Athena\ValueObject\Row;
46+
use AsyncAws\Athena\ValueObject\Datum;
47+
use AsyncAws\Athena\Enum\QueryExecutionState;
48+
49+
$athena = new AthenaClient();
50+
51+
// Submits a sample query to Amazon Athena and returns the execution ID of the query.
52+
$startQueryResult = $athena->startQueryExecution(new StartQueryExecutionInput([
53+
'QueryString' => 'select * from product limit 30',
54+
'QueryExecutionContext' => new QueryExecutionContext([
55+
'Database' => 'production_db', // REQUIRED
56+
]),
57+
'ResultConfiguration' => new ResultConfiguration([
58+
'OutputLocation' => 's3://test_output_bucket', // REQUIRED
59+
'EncryptionConfiguration' => new EncryptionConfiguration([
60+
'EncryptionOption' => 'SSE_S3', // REQUIRED
61+
])
62+
]),
63+
]));
64+
65+
66+
// Wait for an Amazon Athena query to complete, fail or to be cancelled.
67+
$isQueryStillRunning = true;
68+
while ($isQueryStillRunning) {
69+
$queryExecutionResult = $athena->getQueryExecution( new GetQueryExecutionInput([
70+
'QueryExecutionId' => $startQueryResult->getQueryExecutionId(), // REQUIRED
71+
]));
72+
$queryState=$queryExecutionResult->getQueryExecution()->getStatus()->getState();
73+
if($queryState === QueryExecutionState::FAILED) {
74+
throw new \Exception(
75+
'Athena query failed to run with error message: '.$queryExecutionResult->getQueryExecution()->getStatus()->getStateChangeReason()
76+
)
77+
} elseif ($queryState === QueryExecutionState::CANCELLED) {
78+
throw new \Exception('Athena query was cancelled.')
79+
} elseif ($queryState === QueryExecutionState::SUCCEEDED) {
80+
$isQueryStillRunning = false;
81+
}
82+
echo 'The current status is: : ' . $queryState;
83+
}
84+
85+
86+
// retrieves the results of a query
87+
$results = $athena->getQueryResults(new GetQueryResultsInput([
88+
'QueryExecutionId' => $startQueryResult->getQueryExecutionId(),
89+
'MaxResults' => 10000
90+
]));
91+
92+
/** @var Row $row */
93+
foreach ($results => $row) {
94+
if ($index === 0) {
95+
$columnLabels = array_column($row->getData(), 'VarCharValue'); // $row->getData() return [ 'VarCharValue' => value, ...]
96+
}
97+
$columnValues[] = array_column($row->getData(), 'VarCharValue');
98+
}
99+
100+
// retrieves the results column structure details
101+
$columnsDetail = $result->getResultSet()->getResultSetMetadata()->getColumnInfo();
102+
103+
print_r($columnsDetail);
104+
```

docs/clients/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ for more information.
138138
| Api Client | Package name |
139139
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
140140
| [AppSync](./app-sync.md) | [async-aws/app-sync](https://packagist.org/packages/async-aws/app-sync) |
141+
| [Athena](./athena.md) | [async-aws/athena](https://packagist.org/packages/async-aws/athena) |
141142
| [CloudFormation](./cf.md) | [async-aws/cloud-formation](https://packagist.org/packages/async-aws/cloud-formation) |
142143
| [CloudFront](./cloud-front.md) | [async-aws/cloud-front](https://packagist.org/packages/async-aws/cloud-front) |
143144
| [CloudWatch](./cloud-watch.md) | [async-aws/cloud-watch](https://packagist.org/packages/async-aws/cloud-watch) |

manifest.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,48 @@
2222
"UpdateResolver"
2323
]
2424
},
25+
"Athena": {
26+
"source": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/api-2.json",
27+
"documentation": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/docs-2.json",
28+
"pagination": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/paginators-1.json",
29+
"endpoint-rule-set": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/endpoint-rule-set-1.json",
30+
"endpoint-tests": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/endpoint-tests-1.json",
31+
"example": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/examples-1.json",
32+
"smoke": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/smoke.json",
33+
"api-reference": "https://docs.aws.amazon.com/athena/latest/APIReference",
34+
"methods": [
35+
"GetCalculationExecution",
36+
"GetCalculationExecutionStatus",
37+
"GetDataCatalog",
38+
"GetDatabase",
39+
"GetNamedQuery",
40+
"GetQueryExecution",
41+
"GetQueryResults",
42+
"GetSession",
43+
"GetSessionStatus",
44+
"GetTableMetadata",
45+
"GetWorkGroup",
46+
"ListDatabases",
47+
"ListNamedQueries",
48+
"ListQueryExecutions",
49+
"ListTableMetadata",
50+
"StartCalculationExecution",
51+
"StartQueryExecution",
52+
"StartSession",
53+
"StopCalculationExecution",
54+
"StopQueryExecution",
55+
"TerminateSession"
56+
],
57+
"patches": {
58+
"pagination": [
59+
{
60+
"value": "ResultSet.Rows",
61+
"op": "add",
62+
"path": "/pagination/GetQueryResults/result_key"
63+
}
64+
]
65+
}
66+
},
2567
"CloudFormation": {
2668
"source": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/cloudformation/2010-05-15/api-2.json",
2769
"documentation": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/cloudformation/2010-05-15/docs-2.json",

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ parameters:
3131
paths:
3232
- src/Core/src/Sts/ValueObject
3333
- src/Service/AppSync/src/ValueObject
34+
- src/Service/Athena/src/ValueObject
3435
- src/Service/CodeBuild/src/ValueObject
3536
- src/Service/CodeCommit/src/ValueObject
3637
- src/Service/CloudFormation/src/ValueObject

psalm.baseline.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,12 @@
551551
<code>uuid_create(\UUID_TYPE_RANDOM)</code>
552552
</UndefinedFunction>
553553
</file>
554+
<file src="src/Service/Athena/src/Result/GetQueryResultsOutput.php">
555+
<InvalidReturnType occurrences="1">
556+
<code>\Traversable&lt;Row&gt;</code>
557+
</InvalidReturnType>
558+
<PossiblyNullReference occurrences="1">
559+
<code>getRows</code>
560+
</PossiblyNullReference>
561+
</file>
554562
</files>

src/Core/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+
- Support for Athena
8+
59
## 1.18.1
610

711
### Changed

src/Core/src/AwsClientFactory.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AsyncAws\Core;
66

77
use AsyncAws\AppSync\AppSyncClient;
8+
use AsyncAws\Athena\AthenaClient;
89
use AsyncAws\CloudFormation\CloudFormationClient;
910
use AsyncAws\CloudFront\CloudFrontClient;
1011
use AsyncAws\CloudWatch\CloudWatchClient;
@@ -576,4 +577,17 @@ public function cognitoIdentityProvider(): CognitoIdentityProviderClient
576577

577578
return $this->serviceCache[__METHOD__];
578579
}
580+
581+
public function athena(): AthenaClient
582+
{
583+
if (!class_exists(AthenaClient::class)) {
584+
throw MissingDependency::create('async-aws/athena', 'Athena');
585+
}
586+
587+
if (!isset($this->serviceCache[__METHOD__])) {
588+
$this->serviceCache[__METHOD__] = new AthenaClient($this->configuration, $this->credentialProvider, $this->httpClient, $this->logger);
589+
}
590+
591+
return $this->serviceCache[__METHOD__];
592+
}
579593
}

0 commit comments

Comments
 (0)