woshidan's loose leaf

ぼんやり勉強しています

Athenaのテーブル定義にファイル中に存在しない列を定義した場合の振る舞いについて

後からAthenaのテーブル定義に列を追加したい、みたいな場合に気になったので、メモ。

テーブル定義に存在する列で検索対象データ内で型が違うものは怒られますが、テーブル定義に存在して検索対象のデータに存在しない列についてはNULL扱いみたいでした。

以下試したクエリ。

CREATE EXTERNAL TABLE IF NOT EXISTS logs_with_absent (
  `id` String,
  absent_str String, // 存在しない列
  absent_int int     // 存在しない列
  ) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' LOCATION 's3://woshidan-exmaple-test/athena_empty_key_test';
Query successful. 
SELECT COUNT(*) FROM "mydatabase"."logs_with_absent" WHERE "logs_with_absent"."absent_str" IS NULL limit 10 ;
=> 1
SELECT COUNT(*) FROM "mydatabase"."logs_with_absent" WHERE "logs_with_absent"."absent_int" = 0 limit 10 ;
=> 0
SELECT COUNT(*) FROM "mydatabase"."logs_with_absent" WHERE "logs_with_absent"."absent_int" IS NULL limit 10 ;
=> 1