Redshift Spectrum:按日期/文件夹自动分区表

Goa*_*ine 7 amazon-s3 amazon-redshift amazon-redshift-spectrum

我们目前生成我们上传到S3存储桶的每日CSV导出,进入以下结构:

<report-name>
|--reportDate-<date-stamp>
    |-- part0.csv.gz
    |-- part1.csv.gz
Run Code Online (Sandbox Code Playgroud)

我们希望能够运行按日出口分区的报告.

根据页面,您可以通过一个密钥在Redshift Spectrum中对数据进行分区,该密钥基于Spectrum表格中的数据源S3文件夹.但是,从示例中,您似乎需要ALTER为每个分区创建一个语句:

alter table spectrum.sales_part
add partition(saledate='2008-01-01') 
location 's3://bucket/tickit/spectrum/sales_partition/saledate=2008-01/';

alter table spectrum.sales_part
add partition(saledate='2008-02-01') 
location 's3://awssampledbuswest2/tickit/spectrum/sales_partition/saledate=2008-02/';
Run Code Online (Sandbox Code Playgroud)

有没有办法设置表格,以便数据由它来自的文件夹自动分区,或者我们是否需要每天的工作ALTER来添加当天的分区?

Sum*_*abh 8

解决方案1:

每个表最多可以创建20000个分区.您可以创建一次性脚本来为所有未来的s3分区文件夹添加分区(最大20k).

例如.

如果文件夹s3:// bucket/ticket/spectrum/sales_partition/saledate = 2017-12 /不存在,您甚至可以为其添加分区.

alter table spectrum.sales_part
add partition(saledate='2017-12-01') 
location 's3://bucket/tickit/spectrum/sales_partition/saledate=2017-12/';
Run Code Online (Sandbox Code Playgroud)

解决方案2:

https://aws.amazon.com/blogs/big-data/data-lake-ingestion-automatically-partition-hive-external-tables-with-aws/

  • 我在 AWS 文档中找不到有关最大分区数的任何信息。能给个链接吗?更新:我为一个表创建了 20001 个分区,没有任何问题。也许 20k 限制已被弃用。 (2认同)