【发布时间】:2016-07-31 01:42:24
【问题描述】:
有没有办法传入 current_date 来复制 S3 路径的命令
例如:从 AWS Redshift 中的 's3/rootlocation/_current_date_/*.txt 复制表名
【问题讨论】:
标签: copy amazon-redshift
有没有办法传入 current_date 来复制 S3 路径的命令
例如:从 AWS Redshift 中的 's3/rootlocation/_current_date_/*.txt 复制表名
【问题讨论】:
标签: copy amazon-redshift
John 是正确的,动态构建 COPY 语句是不可能的。但是,我找到了一种解决此问题的方法,仅使用 SQL,只需几个命令:
create temporary table _path as
select (
'{"entries":[{"url":"s3://bucket/customer' ||
getdate()::date ||
'.txt", "mandatory":true}]}'
)::varchar(255)
;
unload ('select * from _path') to 's3://bucket/customer.manifest'
credentials '' parallel off
;
copy customer from 's3://bucket/customer.manifest000' credentials '' manifest;
请参阅 http://docs.aws.amazon.com/redshift/latest/dg/r_UNLOAD.html 和 http://docs.aws.amazon.com/redshift/latest/dg/loading-data-files-using-manifest.html。
【讨论】:
我的实验表明 FROM 参数需要是单个字符串,而不是计算值。因此,不可能做这样的事情:
copy customer
from 's3://mybucket/customer' + CURRENT_DATE
credentials '<aws-auth-args>';
您需要通过您用来触发COPY 命令的任何系统来计算字符串在发送到 Redshift 之前。
另一种类似的方法是使用包含要加载的文件列表的manifest file。这在许多文件存储在给定目录中并且只需要加载一些文件的情况下很有用。它还可以避免混淆哪些文件包含在加载中。
【讨论】: