-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
|
||
## NOT RELEASED | ||
|
||
### Added | ||
|
||
- Support for Athena | ||
|
||
## 1.18.1 | ||
|
||
### Changed | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
|
||
## NOT RELEASED | ||
|
||
### Added | ||
|
||
- Support for Athena | ||
|
||
## 1.10.0 | ||
|
||
### Added | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [nyholm, jderusse] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[*.yml] | ||
indent_size = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.