

# Parquet 사용 파티션 프로젝션을 통해 Athena에서 CloudFront 로그용 테이블 생성
<a name="create-cloudfront-table-partition-parquet"></a>

다음 CREATE TABLE 문 예제에서는 하나의 AWS 리전에 대해 Parquet의 지정된 날짜부터 현재까지의 CloudFront 로그에 파티션 프로젝션을 자동으로 사용합니다. 쿼리가 성공적으로 실행되면 테이블을 쿼리할 수 있습니다.

```
CREATE EXTERNAL TABLE `cloudfront_logs_parquet_pp`(
`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)
PARTITIONED BY(
 distributionid string,
 year int,
 month int,
 day int,
 hour int )
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/AWSLogs/AWS_ACCOUNT_ID/CloudFront/'
TBLPROPERTIES (
'projection.distributionid.type'='enum',
'projection.distributionid.values'='E3OK0LPUNWWO3',
'projection.day.range'='01,31',
'projection.day.type'='integer',
'projection.day.digits'='2',
'projection.enabled'='true',
'projection.month.range'='01,12',
'projection.month.type'='integer',
'projection.month.digits'='2',
'projection.year.range'='2019,2025',
'projection.year.type'='integer',
'projection.hour.range'='01,12',
'projection.hour.type'='integer',
'projection.hour.digits'='2',
'storage.location.template'='s3://amzn-s3-demo-bucket/AWSLogs/AWS_ACCOUNT_ID/CloudFront/${distributionid}/${year}/${month}/${day}/${hour}/')
```

다음은 이전 예제에서 사용된 속성에 대한 몇 가지 고려 사항입니다.
+ **테이블 이름** - 테이블 이름 *`cloudfront_logs_pp`*을 바꿀 수 있습니다. 원하는 이름으로 변경할 수 있습니다.
+ **위치** - `s3://amzn-s3-demo-bucket/AWSLogs/AWS_ACCOUNT_ID/`가 Amazon S3 버킷을 가리키도록 수정합니다.
+ **배포 ID** - `projection.distributionid.values`의 경우 여러 배포 ID를 쉼표로 구분하여 지정할 수 있습니다. 예: *<distributionID1>*, *<distributionID2>*.
+ **연도 범위** - `projection.year.range`에서 데이터를 기반으로 연도 범위를 정의할 수 있습니다. 예를 들어 *2025년*, *2026년*과 같은 기간으로 조정할 수 있습니다.
**참고**  
미래 날짜(예: 2025\$12040)와 같은 빈 파티션을 포함하면 쿼리 성능에 영향을 미칠 수 있습니다. 그러나 파티션 프로젝션은 향후 날짜를 효과적으로 처리하도록 설계되었습니다. 최적의 성능을 유지하려면 파티션을 신중하게 관리하고 가능한 경우 과도한 빈 파티션을 피해야 합니다.
+ **스토리지 위치 템플릿** - 다음 CloudFront 파티셔닝 구조 및 S3 경로를 기반으로 `storage.location.template`를 올바르게 업데이트해야 합니다.  
****    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/athena/latest/ug/create-cloudfront-table-partition-parquet.html)

  CloudFront 파티셔닝 구조와 S3 구조가 필요한 패턴과 일치하는지 확인한 후 `storage.location.template`을 다음과 같이 업데이트합니다.

  ```
  'storage.location.template'='s3://amzn-s3-demo-bucket/AWSLogs/account_id/CloudFront/${distributionid}/folder2/${year}/${month}/${day}/${hour}/folder3/'
  ```
**참고**  
올바른 데이터 스토리지 및 검색을 보장하려면 `storage.location.template`을 적절히 구성하는 것이 중요합니다.