如何将在镶木地板中格式化的特定列加载到Redshift频谱中?

时间:2017-07-07 16:27:32

标签: amazon-redshift parquet amazon-redshift-spectrum

我尝试将特定列加载到Redshift Spectrum中,但似乎数据是按位置加载的,这意味着我对列名称的放置并不重要。

使这更具体:

让我们说我要加载的数据以位置A,B,C的形式存储在镶木地板中。我只想要B列,所以我写道:

create external table spectrum.Foo(
  B varchar(500)
)
STORED AS PARQUET
LOCATION 's3://data/';

不幸的是,当我这样做时,它实际上将A的数据加载到Foo.B

我需要一些额外的语法吗?我仔细检查了文档,但找不到任何东西。

谢谢!

2 个答案:

答案 0 :(得分:0)

定义外部表不会将数据加载到Redshift中 - 它只是让您查询它。如果您只想摄取列的子集,可以尝试以下一组查询:

create external table spectrum.Foo(
  A varchar(100), B varchar(100), C varchar(100)
) stored as parquet location 's3://data/';

这定义了外部架构:

create table local_data as select A, C from spectrum.Foo;

这实际上只会将外部表中的指定列加载到Redshift中的本地表中。但是,您不需要这样做:Redshift Spectrum和Parquet的优势在于您运行查询时:

select A, C from spectrum.Foo;

它只会从S3为被访问列加载数据,从而减少了对S3的IO操作数量并降低了成本。

答案 1 :(得分:0)

如果您有现有的红移表,则Spectrify提供了一种易于使用的方法,可将数据移至频谱 - https://github.com/hellonarrativ/spectrify/