【问题标题】:How to avoid AWS Athena CTAS query creating small files?如何避免 AWS Athena CTAS 查询创建小文件?
【发布时间】:2019-07-22 20:23:12
【问题描述】:

我无法弄清楚我的 CTAS 查询出了什么问题,即使我没有提到任何分桶列,它也会将数据分成更小的文件,同时存储在一个分区中。有没有办法避免这些小文件并将每个分区存储为一个文件,因为小于 128 MB 的文件会导致额外开销?

CREATE TABLE sampledb.yellow_trip_data_parquet
WITH(
    format = 'PARQUET'
    parquet_compression = 'GZIP',
    external_location='s3://mybucket/Athena/tables/parquet/'
    partitioned_by=ARRAY['year','month']
)
AS SELECT
    VendorID,
    tpep_pickup_datetime,
    tpep_dropoff_datetime,
    passenger_count,
    trip_distance,
    RatecodeID,
    store_and_fwd_flag,
    PULocationID,
    DOLocationID,
    payment_type,
    fare_amount,
    extra,
    mta_tax,
    tip_amount,
    tolls_amount,
    improvement_surcharge,
    total_amount,
    date_format(date_parse(tpep_pickup_datetime,'%Y-%c-%d %k:%i:%s'),'%Y')  AS year,
    date_format(date_parse(tpep_pickup_datetime,'%Y-%c-%d %k:%i:%s'),'%c')  AS month
FROM sampleDB.yellow_trip_data_raw;

【问题讨论】:

  • 这可能是由于 Athena 的分布式特性,每个“节点”生成一个单独的文件?

标签: amazon-web-services amazon-athena


【解决方案1】:

我能够通过创建一个桶列month_a 来解决这个问题。下面是代码

CREATE TABLE sampledb.yellow_trip_data_avro
WITH (
    format = 'AVRO',
    external_location='s3://a4189e1npss3001/Athena/internal_tables/avro/',
    partitioned_by=ARRAY['year','month'],
    bucketed_by=ARRAY['month_a'],
    bucket_count=12
) AS SELECT
    VendorID,
    tpep_pickup_datetime,
    tpep_dropoff_datetime,
    passenger_count,
    trip_distance,
    RatecodeID,
    store_and_fwd_flag,
    PULocationID,
    DOLocationID,
    payment_type,
    fare_amount,
    extra,
    mta_tax,
    tip_amount,
    tolls_amount,
    improvement_surcharge,
    total_amount,
    date_format(date_parse(tpep_pickup_datetime, '%Y-%c-%d %k:%i:%s'),'%c') AS month_a,
    date_format(date_parse(tpep_pickup_datetime, '%Y-%c-%d %k:%i:%s'),'%Y') AS year,
    date_format(date_parse(tpep_pickup_datetime, '%Y-%c-%d %k:%i:%s'),'%c') AS month
FROM sampleDB.yellow_trip_data_raw;

【讨论】:

    【解决方案2】:

    Athena 是一个分布式系统,它会通过一些不可观察的机制来扩展查询的执行。看起来它决定为您的 CTAS 查询使用五个工作人员,这将导致每个分区中有五个文件。

    您可以尝试明确指定存储桶大小为 1,但如果我没记错的话,您可能仍会获得多个文件。

    【讨论】:

      猜你喜欢
      • 2021-07-26
      • 2019-11-07
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      • 2018-04-06
      • 2021-01-20
      • 2023-03-30
      • 1970-01-01
      相关资源
      最近更新 更多