LoginSignup
0
0

More than 1 year has passed since last update.

Athenaのunloadが業務で必要だったので試してみた

Posted at

結論

クエリを実行した結果、s3に想定したファイルが出力がされた
また、CLIからも実行可能

実行

以下のクエリを記載しathenaのコンソール上から実行

UNLOAD (SELECT
  hoge,
  fuga,
  piyo
FROM
  db.table) TO 's3://xxxxx/xxx/'
WITH (format = 'AVRO')

→指定のS3にavro形式でファイルが出力された

AWS CLIを利用してクエリを出力することが可能なのか?
以下のCLIを実行

aws athena start-query-execution \
    --query-string "UNLOAD (SELECT hoge, fuga, piyo FROM db.table) TO 's3://xxxxx/xxx/' WITH (format = 'AVRO')"

結果を確認

aws athena get-query-execution --query-execution-id xxxxxxxx | jq '.QueryExecution.Status.State'
"SUCCEEDED"

→同様にs3にファイルが出力された

エラー

[ErrorCode: INTERNAL_ERROR_QUERY_ENGINE] Amazon Athena experienced an internal error while executing this query. Please contact AWS support for further assistance. You will not be charged for this query. We apologize for the inconvenience.

→オブジェクトのパスをs3://xxxxxにしていた→s3://xxxxx/xxx/でうまくいった
同じパス配下におけるクエリ結果は1つのため、定期実行の際は日付などでパスを区切る必要がある

まとめ

これで他システムのデータ連携において、様々なファイル形式で可能になった
boto3を使用しても可能か検証したい

参考

0
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
0
0