CloudFrontのアクセスログ取得用に外部テーブルを作成するため、AWS AthenaのQuery Editorで以下のCREATE文を発行した。
CREATE EXTERNAL TABLE IF NOT EXISTS cf_log ( request_date string, request_time string, x_edge_location string, sc_bytes int, client_ip string, cs_method string, cs_host string, cs_uri_stem string, sc_status string, cs_referer string, user_agent string, uri_query string, cookie string, x_edge_result_type string, x_edge_request_id string, x_host_header string, cs_protocol string, cs_bytes int, time_taken DECIMAL(8,3), x_forwarded_for string, ssl_protocol string, ssl_cipher string, x_edge_response_result_type string, cs-protocol-version string, fle-status string, fle-encrypted-fields string ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' WITH SERDEPROPERTIES ( 'serialization.format' = '\t', 'field.delim' = '\t' ) LOCATION 's3://{S3のバケット名}}/' TBLPROPERTIES ( 'has_encrypted_data'='false', 'skip.header.line.count'='2' );
しかし、以下のようなエラーが出て、テーブルを作ることができない。
line 1:8: no viable alternative at input 'create external' (service: amazonathena; status code: 400; error code: invalidrequestexception; request id: {リクエストID})
原因は、カラム名にハイフンを含んだ文字列があるためだった。
cs-protocol-version string, fle-status string, fle-encrypted-fields string
アンダーバーに修正し、エラーなく実行できた。
cs_protocol_version string, fle_status string, fle_encrypted_fields string