LoginSignup
2
0

More than 5 years have passed since last update.

[PHP + AWS SDKでAthena] getQueryResultsの結果が扱いづらいので扱いやすくする。2018-08-14

Last updated at Posted at 2018-08-14

概要

長くなるので割愛しますが、PHP + AWS SDKでAthenaの実行結果(結果例)をgetQueryResultsで取得すると少し扱いづらいです
扱いやすい形式に変換してみます

install

% composer require abetomo/convert-athena-query-results-to-array

コード例

こちらのコード例 から変更したところを抜粋して記載します

example.php
<?php
// ... これより上は省略
// 3. 結果の取得
$getQueryResultsResponse = $athenaClient->getQueryResults([
    'QueryExecutionId' => $queryExecutionId
]);

use Abetomo\ConvertAthenaQueryResultstoArray\ConvertAthenaQueryResultstoArray;
// getQueryResultsの結果を
// ConvertAthenaQueryResultstoArray::convert()
// で変換します
print_r(ConvertAthenaQueryResultstoArray::convert($getQueryResultsResponse->get('ResultSet')));

実行結果

string(36) "QueryExecutionId-XXXXX"
[waitForSucceeded] State=RUNNING
[waitForSucceeded] State=RUNNING
[waitForSucceeded] State=SUCCEEDED
Array
(
    [0] => Array
        (
            [account_id] => id1
        )

    [1] => Array
        (
            [account_id] => id2
        )

    [2] => Array
        (
            [account_id] => id3
        )

)

こちらの結果 と比較するとシンプルな配列になりました

まとめ

PHP + AWS SDKでAthenaの実行結果をシンプルな配列に変換して扱いやすくしました

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0