Skip to content

async_aws (Athena Client): create aws Athena Client with somes operations #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ See full documentation on [https://async-aws.com](https://async-aws.com).
| --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [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) |
| [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) |
| [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) |
| [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) |
| [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) |
| [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) |
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"autoload": {
"psr-4": {
"AsyncAws\\AppSync\\": "src/Service/AppSync/src",
"AsyncAws\\Athena\\": "src/Service/Athena/src",
"AsyncAws\\CloudFormation\\": "src/Service/CloudFormation/src",
"AsyncAws\\CloudFront\\": "src/Service/CloudFront/src",
"AsyncAws\\CloudWatchLogs\\": "src/Service/CloudWatchLogs/src",
Expand Down Expand Up @@ -100,6 +101,7 @@
"autoload-dev": {
"psr-4": {
"AsyncAws\\AppSync\\Tests\\": "src/Service/AppSync/tests",
"AsyncAws\\Athena\\Tests\\": "src/Service/Athena/tests",
"AsyncAws\\CloudFormation\\Tests\\": "src/Service/CloudFormation/tests",
"AsyncAws\\CloudFront\\Tests\\": "src/Service/CloudFront/tests",
"AsyncAws\\CloudWatchLogs\\Tests\\": "src/Service/CloudWatchLogs/tests",
Expand Down
3 changes: 3 additions & 0 deletions couscous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ menu:
app-sync:
text: AppSync
url: /clients/app-sync.html
athena:
text: Athena
url: /clients/athena.html
cf:
text: Cloud Formation
url: /clients/cf.html
Expand Down
104 changes: 104 additions & 0 deletions docs/clients/athena.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
layout: client
category: clients
name: Athena
package: async-aws/athena
---

## Usage

### List Databases

```php
use AsyncAws\Athena\AthenaClient;
use AsyncAws\Athena\Input\ListDatabasesInput;

$athena = new AthenaClient();

$result = $athena->listDatabases(new ListDatabasesInput([
'CatalogName' => 'my_catalog'
]));

foreach ($result->getDatabaseList() as $database) {
echo 'Database name : ' . $database->getName();
echo 'Database description : ' . $database->getDescription();
echo 'Database parameter : '.PHP_EOL;
print_r($database->getParameters());
}

```
more information [listDatabases](https://docs.aws.amazon.com/athena/latest/APIReference/API_ListDatabases.html)

### Query to Amazon Athena

```php
use AsyncAws\Athena\AthenaClient;
use AsyncAws\Athena\Input\StartQueryExecutionInput;
use AsyncAws\Athena\Input\DescribeTableInput;
use AsyncAws\Athena\ValueObject\QueryExecutionContext;
use AsyncAws\Athena\ValueObject\ResultConfiguration;
use AsyncAws\Athena\ValueObject\EncryptionConfiguration;
use AsyncAws\Athena\ValueObject\AclConfiguration;
use AsyncAws\Athena\ValueObject\ResultReuseByAgeConfiguration;
use AsyncAws\Athena\Input\GetQueryExecutionInput;
use AsyncAws\Athena\Input\GetQueryResultsInput;
use AsyncAws\Athena\ValueObject\Row;
use AsyncAws\Athena\ValueObject\Datum;
use AsyncAws\Athena\Enum\QueryExecutionState;

$athena = new AthenaClient();

// Submits a sample query to Amazon Athena and returns the execution ID of the query.
$startQueryResult = $athena->startQueryExecution(new StartQueryExecutionInput([
'QueryString' => 'select * from product limit 30',
'QueryExecutionContext' => new QueryExecutionContext([
'Database' => 'production_db', // REQUIRED
]),
'ResultConfiguration' => new ResultConfiguration([
'OutputLocation' => 's3://test_output_bucket', // REQUIRED
'EncryptionConfiguration' => new EncryptionConfiguration([
'EncryptionOption' => 'SSE_S3', // REQUIRED
])
]),
]));


// Wait for an Amazon Athena query to complete, fail or to be cancelled.
$isQueryStillRunning = true;
while ($isQueryStillRunning) {
$queryExecutionResult = $athena->getQueryExecution( new GetQueryExecutionInput([
'QueryExecutionId' => $startQueryResult->getQueryExecutionId(), // REQUIRED
]));
$queryState=$queryExecutionResult->getQueryExecution()->getStatus()->getState();
if($queryState === QueryExecutionState::FAILED) {
throw new \Exception(
'Athena query failed to run with error message: '.$queryExecutionResult->getQueryExecution()->getStatus()->getStateChangeReason()
)
} elseif ($queryState === QueryExecutionState::CANCELLED) {
throw new \Exception('Athena query was cancelled.')
} elseif ($queryState === QueryExecutionState::SUCCEEDED) {
$isQueryStillRunning = false;
}
echo 'The current status is: : ' . $queryState;
}


// retrieves the results of a query
$results = $athena->getQueryResults(new GetQueryResultsInput([
'QueryExecutionId' => $startQueryResult->getQueryExecutionId(),
'MaxResults' => 10000
]));

/** @var Row $row */
foreach ($results => $row) {
if ($index === 0) {
$columnLabels = array_column($row->getData(), 'VarCharValue'); // $row->getData() return [ 'VarCharValue' => value, ...]
}
$columnValues[] = array_column($row->getData(), 'VarCharValue');
}

// retrieves the results column structure details
$columnsDetail = $result->getResultSet()->getResultSetMetadata()->getColumnInfo();

print_r($columnsDetail);
```
1 change: 1 addition & 0 deletions docs/clients/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ for more information.
| Api Client | Package name |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| [AppSync](./app-sync.md) | [async-aws/app-sync](https://packagist.org/packages/async-aws/app-sync) |
| [Athena](./athena.md) | [async-aws/athena](https://packagist.org/packages/async-aws/athena) |
| [CloudFormation](./cf.md) | [async-aws/cloud-formation](https://packagist.org/packages/async-aws/cloud-formation) |
| [CloudFront](./cloud-front.md) | [async-aws/cloud-front](https://packagist.org/packages/async-aws/cloud-front) |
| [CloudWatch](./cloud-watch.md) | [async-aws/cloud-watch](https://packagist.org/packages/async-aws/cloud-watch) |
Expand Down
42 changes: 42 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,48 @@
"UpdateResolver"
]
},
"Athena": {
"source": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/api-2.json",
"documentation": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/docs-2.json",
"pagination": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/paginators-1.json",
"endpoint-rule-set": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/endpoint-rule-set-1.json",
"endpoint-tests": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/endpoint-tests-1.json",
"example": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/examples-1.json",
"smoke": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/athena/2017-05-18/smoke.json",
"api-reference": "https://docs.aws.amazon.com/athena/latest/APIReference",
"methods": [
"GetCalculationExecution",
"GetCalculationExecutionStatus",
"GetDataCatalog",
"GetDatabase",
"GetNamedQuery",
"GetQueryExecution",
"GetQueryResults",
"GetSession",
"GetSessionStatus",
"GetTableMetadata",
"GetWorkGroup",
"ListDatabases",
"ListNamedQueries",
"ListQueryExecutions",
"ListTableMetadata",
"StartCalculationExecution",
"StartQueryExecution",
"StartSession",
"StopCalculationExecution",
"StopQueryExecution",
"TerminateSession"
],
"patches": {
"pagination": [
{
"value": "ResultSet.Rows",
"op": "add",
"path": "/pagination/GetQueryResults/result_key"
}
]
}
},
"CloudFormation": {
"source": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/cloudformation/2010-05-15/api-2.json",
"documentation": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/cloudformation/2010-05-15/docs-2.json",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ parameters:
paths:
- src/Core/src/Sts/ValueObject
- src/Service/AppSync/src/ValueObject
- src/Service/Athena/src/ValueObject
- src/Service/CodeBuild/src/ValueObject
- src/Service/CodeCommit/src/ValueObject
- src/Service/CloudFormation/src/ValueObject
Expand Down
8 changes: 8 additions & 0 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,12 @@
<code>uuid_create(\UUID_TYPE_RANDOM)</code>
</UndefinedFunction>
</file>
<file src="src/Service/Athena/src/Result/GetQueryResultsOutput.php">
<InvalidReturnType occurrences="1">
<code>\Traversable&lt;Row&gt;</code>
</InvalidReturnType>
<PossiblyNullReference occurrences="1">
<code>getRows</code>
</PossiblyNullReference>
</file>
</files>
7 changes: 7 additions & 0 deletions src/Core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## NOT RELEASED

## 1.19.0

### Added

- Support for Athena
- AWS enhancement: Documentation updates.

## 1.18.1

### Changed
Expand Down
14 changes: 14 additions & 0 deletions src/Core/src/AwsClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AsyncAws\Core;

use AsyncAws\AppSync\AppSyncClient;
use AsyncAws\Athena\AthenaClient;
use AsyncAws\CloudFormation\CloudFormationClient;
use AsyncAws\CloudFront\CloudFrontClient;
use AsyncAws\CloudWatch\CloudWatchClient;
Expand Down Expand Up @@ -576,4 +577,17 @@ public function cognitoIdentityProvider(): CognitoIdentityProviderClient

return $this->serviceCache[__METHOD__];
}

public function athena(): AthenaClient
{
if (!class_exists(AthenaClient::class)) {
throw MissingDependency::create('async-aws/athena', 'Athena');
}

if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new AthenaClient($this->configuration, $this->credentialProvider, $this->httpClient, $this->logger);
}

return $this->serviceCache[__METHOD__];
}
}
6 changes: 6 additions & 0 deletions src/Integration/Symfony/Bundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## NOT RELEASED

## 1.11.0

### Added

- Support for Athena

## 1.10.0

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public static function getAllServices(): array
'class' => \AsyncAws\AppSync\AppSyncClient::class,
'package' => 'async-aws/app-sync',
],
'athena' => [
'class' => \AsyncAws\Athena\AthenaClient::class,
'package' => 'async-aws/athena',
],
'cloud_formation' => [
'class' => \AsyncAws\CloudFormation\CloudFormationClient::class,
'package' => 'async-aws/cloud-formation',
Expand Down
5 changes: 5 additions & 0 deletions src/Service/Athena/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.github export-ignore
/tests export-ignore
/.gitignore export-ignore
/Makefile export-ignore
/phpunit.xml.dist export-ignore
3 changes: 3 additions & 0 deletions src/Service/Athena/.github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [nyholm, jderusse]
2 changes: 2 additions & 0 deletions src/Service/Athena/.github/workflows/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.yml]
indent_size = 2
76 changes: 76 additions & 0 deletions src/Service/Athena/.github/workflows/branch_alias.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Update branch alias

on:
push:
tags: ['*']

jobs:
branch-alias:
name: Update branch alias
runs-on: ubuntu-latest

steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- name: Find branch alias
id: find_alias
run: |
TAG=$(echo $GITHUB_REF | cut -d'/' -f 3)
echo "Last tag was $TAG"
ARR=(${TAG//./ })
ARR[1]=$((${ARR[1]}+1))
echo ::set-output name=alias::${ARR[0]}.${ARR[1]}

- name: Checkout main repo
run: |
git clone --branch master https://${{ secrets.BOT_GITHUB_TOKEN }}:[email protected]/async-aws/aws aws

- name: Update branch alias
run: |
cd aws/src/Service/Athena
CURRENT_ALIAS=$(composer config extra.branch-alias.dev-master | cut -d'-' -f 1)

# If there is a current value on the branch alias
if [ ! -z $CURRENT_ALIAS ]; then
NEW_ALIAS=${{ steps.find_alias.outputs.alias }}
CURRENT_ARR=(${CURRENT_ALIAS//./ })
NEW_ARR=(${NEW_ALIAS//./ })

if [ ${CURRENT_ARR[0]} -gt ${NEW_ARR[0]} ]; then
echo "The current value for major version is larger"
exit 1;
fi

if [ ${CURRENT_ARR[0]} -eq ${NEW_ARR[0]} ] && [ ${CURRENT_ARR[1]} -gt ${NEW_ARR[1]} ]; then
echo "The current value for minor version is larger"
exit 1;
fi
fi

composer config extra.branch-alias.dev-master ${{ steps.find_alias.outputs.alias }}-dev

- name: Commit & push the new files
run: |
echo "::group::git status"
cd aws
git status
echo "::endgroup::"

git add -N .
if [[ $(git diff --numstat | wc -l) -eq 0 ]]; then
echo "No changes found. Exiting."
exit 0;
fi

git config --local user.email "[email protected]"
git config --local user.name "AsyncAws Bot"

echo "::group::git push"
git add .
git commit -m "Update branch alias"
git push
echo "::endgroup::"
27 changes: 27 additions & 0 deletions src/Service/Athena/.github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: BC Check

on:
push:
branches:
- master

jobs:
roave-bc-check:
name: Roave BC Check
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Modify composer.json
run: |
sed -i -re 's/"require": \{/"minimum-stability": "dev","prefer-stable": true,"require": \{/' composer.json
cat composer.json

git config --local user.email "[email protected]"
git config --local user.name "AsyncAws Bot"
git commit -am "Allow unstable dependencies"

- name: Roave BC Check
uses: docker://nyholm/roave-bc-check-ga
Loading