把資料收到 S3 資料,就可以到 Athena 建 table 撈取資料,使用 year 、 month 和 day 當 PARTITIONED 建完資料表後,就能查詢看看也沒有資料。
CREATE EXTERNAL TABLE IF NOT EXISTS ad_clicks_raw (
ad_id STRING,
click_id STRING,
impression_id STRING,
user_id STRING,
timestamp BIGINT,
timestamp_iso STRING,
source_url STRING,
processedAt STRING,
sqs_message_id STRING
)
PARTITIONED BY (
year STRING,
month STRING,
day STRING
)
ROW FORMAT SERDE 'com.amazon.ionhiveserde.IonHiveSerDe'
STORED AS INPUTFORMAT 'com.amazon.ionhiveserde.formats.IonInputFormat'
OUTPUTFORMAT 'com.amazon.ionhiveserde.formats.IonOutputFormat'
LOCATION 's3://ad-clicks-raw-dev-262969866776/raw-clicks/'
TBLPROPERTIES (
'projection.enabled' = 'true',
'projection.year.type' = 'integer',
'projection.year.range' = '2024,2030',
'projection.month.type' = 'integer',
'projection.month.range' = '1,12',
'projection.month.digits' = '2',
'projection.day.type' = 'integer',
'projection.day.range' = '1,31',
'projection.day.digits' = '2',
'storage.location.template' = 's3://ad-clicks-raw-dev-262969866776/raw-clicks/${year}/${month}/${day}/'
);
建 table 需要一些時間,建完之後,簡單的下 SELECT * FROM ad_clicks_raw LIMIT 100; 查詢,就可以看到 S3 的資料有匯入資料表!
Medium: 使用 Serverless 架構設計廣告點擊系統 — 使用 S3 儲存數據