Amazon redshift 我想在将数据从S3存储桶复制到红移表时存储文件夹名

Amazon redshift 我想在将数据从S3存储桶复制到红移表时存储文件夹名,amazon-redshift,Amazon Redshift,我试图将数据从S3 bucket加载到redshift表中,表中有一列作为源id,我想将源文件所在的文件夹名存储到该列中 实际上,我在S3 bucket中有多个文件夹,每个文件夹中有一个文件,我使用红移中的copy命令将所有文件移植到同一个表中,以便识别数据来自哪个文件夹,所以我需要将文件夹名称和数据存储到红移表中,我在表中有单独的列作为源id 任何人都可以帮助我。如果您使用的是红移复制命令,那么除了导入每个文件夹(例如,作为临时表)然后手动将值设置为还原文件夹的值之外,您别无选择。对每个文件夹

我试图将数据从S3 bucket加载到redshift表中,表中有一列作为源id,我想将源文件所在的文件夹名存储到该列中

实际上,我在S3 bucket中有多个文件夹,每个文件夹中有一个文件,我使用红移中的copy命令将所有文件移植到同一个表中,以便识别数据来自哪个文件夹,所以我需要将文件夹名称和数据存储到红移表中,我在表中有单独的列作为源id


任何人都可以帮助我。

如果您使用的是红移复制命令,那么除了导入每个文件夹(例如,作为临时表)然后手动将值设置为还原文件夹的值之外,您别无选择。对每个文件夹重复此操作

另一个选项是使用红移光谱并创建一个外部表,该表作为分区映射到您的文件夹

首先,像这样创建基表

create external table spectrum.sales_part(
salesid integer,
listid integer,
sellerid integer,
buyerid integer,
eventid integer,
dateid smallint,
qtysold smallint,
pricepaid decimal(8,2),
commission decimal(8,2),
saletime timestamp)
partitioned by (saledate date)
row format delimited
fields terminated by '|'
stored as textfile
location 's3://awssampledbuswest2/tickit/spectrum/sales_partition/'
table properties ('numRows'='172000');
然后像这样添加分区

alter table spectrum.sales_part
add partition(saledate='2008-01-01') 
location 's3://awssampledbuswest2/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/';
alter table spectrum.sales_part
add partition(saledate='2008-03-01') 
location 's3://awssampledbuswest2/tickit/spectrum/sales_partition/saledate=2008-03/';
一旦将该表设置为外部表,就可以对该表使用标准sql,例如,可以对该表运行查询,或者使用CTA将其复制到永久红移表

这里是文档的链接

如果您使用的是红移复制命令,则除了导入每个文件夹(例如作为临时表)然后手动将值设置为还原文件夹的值之外,您别无选择。对每个文件夹重复此操作

另一个选项是使用红移光谱并创建一个外部表,该表作为分区映射到您的文件夹

首先,像这样创建基表

create external table spectrum.sales_part(
salesid integer,
listid integer,
sellerid integer,
buyerid integer,
eventid integer,
dateid smallint,
qtysold smallint,
pricepaid decimal(8,2),
commission decimal(8,2),
saletime timestamp)
partitioned by (saledate date)
row format delimited
fields terminated by '|'
stored as textfile
location 's3://awssampledbuswest2/tickit/spectrum/sales_partition/'
table properties ('numRows'='172000');
然后像这样添加分区

alter table spectrum.sales_part
add partition(saledate='2008-01-01') 
location 's3://awssampledbuswest2/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/';
alter table spectrum.sales_part
add partition(saledate='2008-03-01') 
location 's3://awssampledbuswest2/tickit/spectrum/sales_partition/saledate=2008-03/';
一旦将该表设置为外部表,就可以对该表使用标准sql,例如,可以对该表运行查询,或者使用CTA将其复制到永久红移表

这里是文档的链接

问题到底是什么?请根据问题的具体内容编辑您的问题?请相应地编辑您的问题