本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 Parquet 格式建立 CloudFront 標準日誌檔案欄位的資料表
-
複製下列範例 DDL 陳述式,並將其貼到 Athena 主控台查詢編輯器。範例陳述式使用《Amazon CloudFront 開發人員指南》中標準日誌檔欄位章節中所述的日誌檔欄位。
此查詢使用 ParquetHiveSerDe 搭配下列 SerDe 屬性,以正確讀取 Athena 中的 Parquet 欄位。
CREATE EXTERNAL TABLE `cf_logs_manual_partition_parquet`( `date` string, `time` string, `x_edge_location` string, `sc_bytes` string, `c_ip` string, `cs_method` string, `cs_host` string, `cs_uri_stem` string, `sc_status` string, `cs_referer` string, `cs_user_agent` string, `cs_uri_query` string, `cs_cookie` string, `x_edge_result_type` string, `x_edge_request_id` string, `x_host_header` string, `cs_protocol` string, `cs_bytes` string, `time_taken` string, `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, `c_port` string, `time_to_first_byte` string, `x_edge_detailed_result_type` string, `sc_content_type` string, `sc_content_len` string, `sc_range_start` string, `sc_range_end` string) ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat' LOCATION 's3://amzn-s3-demo-bucket/'
-
在 Athena 主控台中執行查詢。查詢完成之後,Athena 會註冊
cf_logs_manual_partition_parquet
資料表,讓其中的資料可供您發出查詢。
查詢範例
下列查詢會加總 CloudFront 在 2025 年 1 月 19 日的位元組數。
SELECT sum(cast("sc_bytes" as BIGINT)) as sc
FROM cf_logs_manual_partition_parquet
WHERE "date"='2025-01-19'
若要從查詢結果中除去重複的資料列 (例如,重複的空白資料列),您可以使用 SELECT DISTINCT
陳述式,如下列範例所示。
SELECT DISTINCT * FROM cf_logs_manual_partition_parquet