LoginSignup
0
0

More than 3 years have passed since last update.

【Athena】enumを使ったパーティショニング

Posted at

概要

AWSのAthenaで、Partition Projectionを使ってパーティショニングする際のenumを使った例をまとめます。
enumは、連続しておらず、列挙可能なカーディナリティが低いカラムに適しています。
今回はinstance_idに対して適用しています。

S3バケットの構成は以下の通りです。

s3://backet-name/object-name/instance_id/year=yyyy/month=mm/day=dd/

例:
s3://backet-name/object-name/i-xxxxxxxxxxxxxxxxx/year=2021/month=5/day=1/

instance_id, year, month, dayでパーティショニングします。

テーブル作成の構文

テーブル作成の構文の例は以下の通りです。
PARTITIONED BYTBLPROPERTIESにパーティショニングに必要な情報です。
TBLPROPERTIESの中身は参考記事に記載されています。

CREATE EXTERNAL TABLE `table_name`(
  `foo` string, 
  `bar` string
)
PARTITIONED BY (instance_id string, year int, month int, day int)
ROW FORMAT DELIMITED 
  FIELDS TERMINATED BY ' ' 
  MAP KEYS TERMINATED BY 'undefined' 
LOCATION
  's3://backet-name/object-name/'
TBLPROPERTIES (
  'projection.enabled' = 'true',
  'projection.instance_id.type'='enum', 
  'projection.instance_id.values'='i-xxxxxxxxxxxxxxxxx,i-yyyyyyyyyyyyyyyyy',       
  'projection.year.type' = 'integer',
  'projection.year.range' = '2021,2030',
  'projection.year.interval' = '1',
  'projection.month.type' = 'integer',
  'projection.month.range' = '1,12',
  'projection.month.interval' = '1',
  'projection.day.type' = 'integer',
  'projection.day.range' = '1,31',
  'projection.day.interval' = '1',
  'storage.location.template' = 's3://backet-name/object-name/${instance_id}/year=${year}/month=${month}/day=${day}/'
  )

参考URL

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