0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【第5回】TrinoのIceberg分析をAmazon Athenaへ移行する

0
Last updated at Posted at 2026-09-19

はじめに

先行シリーズでGlue Catalogに登録済みのS3 Iceberg tableを、既存のAthena workgroupから参照する。新しいquery結果bucketやworkgroupは作らず、Trinoで使っていた基本queryを移す。

1. 既存profile、query結果bucket、workgroupを確認する

source /etc/iceberg/aws.env
export AWS_PROFILE=home-aws

aws sts get-caller-identity --profile "${AWS_PROFILE}"
aws s3api head-bucket \
  --bucket "${ATHENA_RESULT_BUCKET}" \
  --profile "${AWS_PROFILE}"
aws athena get-work-group \
  --work-group "${ATHENA_WORKGROUP}" \
  --profile "${AWS_PROFILE}"

出力先がs3://${ATHENA_RESULT_BUCKET}/athena-results/、engineがversion 3であることを確認する。設定変更が必要な場合だけhome-aws-adminへ切り替え、既存workgroupを更新する。

2. tableを確認する

SHOW TABLES IN logs;
DESCRIBE logs.syslog_iceberg;
DESCRIBE logs.authlog_iceberg;

Athenaから外部作成Iceberg tableを直接queryできるため、同じS3 locationへ通常のHive external tableを重ねて作らない。

3. 件数と時刻範囲を確認する

SELECT COUNT(*) AS cnt, MIN(ts) AS min_ts, MAX(ts) AS max_ts
FROM logs.syslog_iceberg;

SELECT COUNT(*) AS cnt, MIN(ts) AS min_ts, MAX(ts) AS max_ts
FROM logs.authlog_iceberg;

4. 日付を指定する

SELECT host, severity, COUNT(*) AS cnt
FROM logs.syslog_iceberg
WHERE dt = DATE '2026-09-16'
GROUP BY host, severity
ORDER BY cnt DESC;

SELECT hr, COUNT(*) AS cnt
FROM logs.authlog_iceberg
WHERE dt = DATE '2026-09-16'
GROUP BY hr
ORDER BY hr;

5. streaming tableを確認する

SELECT window_start, host, cnt
FROM logs.syslog_host_1m
WHERE dt = current_date
ORDER BY window_start DESC
LIMIT 100;

SELECT window_start, host, cnt
FROM logs.authlog_host_1m
WHERE dt = current_date
ORDER BY window_start DESC
LIMIT 100;

6. snapshotを確認する

SELECT committed_at, snapshot_id, operation
FROM "logs"."syslog_iceberg$snapshots"
ORDER BY committed_at DESC;

AthenaはIceberg v2をqueryし、partition predicateをS3へpush downする。常にdtを指定し、scan量を抑える。

7. CLIから実行する

EXECUTION_ID=$(aws athena start-query-execution \
  --work-group "${ATHENA_WORKGROUP}" \
  --query-string "SELECT COUNT(*) FROM logs.syslog_iceberg WHERE dt = DATE '2026-09-16'" \
  --query 'QueryExecutionId' --output text \
  --profile "${AWS_PROFILE}")

while :; do
  QUERY_STATE=$(aws athena get-query-execution \
    --query-execution-id "${EXECUTION_ID}" \
    --query 'QueryExecution.Status.State' --output text \
    --profile "${AWS_PROFILE}")
  case "${QUERY_STATE}" in
    SUCCEEDED) break ;;
    FAILED|CANCELLED)
      aws athena get-query-execution --query-execution-id "${EXECUTION_ID}" \
        --query 'QueryExecution.Status' --profile "${AWS_PROFILE}"
      exit 1 ;;
  esac
  sleep 2
done

aws athena get-query-results --query-execution-id "$EXECUTION_ID" \
  --profile "${AWS_PROFILE}"

Trinoとの差分

  • catalog prefixはiceberg.logs.tableからAthenaのlogs.tableへ変わる
  • timestamp/time zone関数の互換性をquery単位で確認する
  • Athenaはscan量課金なのでSELECT *を常用しない
  • Grafana等はAthena datasource/JDBCへ切り替え、旧dashboardと同じ期間を比較する

参考資料

関連記事

実機検証について

本稿は未検証である。timestamp表示はworkgroup/sessionとclientのtimezoneを含めてsample値を比較する。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?