跳过 AWS Redshift 外部表中的 header 行

Skipping header rows in AWS Redshift External Tables

我在 S3 中有一个包含以下数据的文件:

name,age,gender
jill,30,f
jack,32,m

还有一个红移 external table to query that data using spectrum:

create external table spectrum.customers ( 
 "name" varchar(50),
 "age" int,
 "gender" varchar(1))
row format delimited
fields terminated by ','
lines terminated by \n'
stored as textfile 
location 's3://...';

查询数据时得到以下结果:

select * from spectrum.customers;
name,age,g
jill,30,f
jack,32,m

是否有一种优雅的方法可以跳过 header 行作为外部 table 定义的一部分,类似于 Hive 中的 tblproperties ("skip.header.line.count"="1") 选项?或者我唯一的选择(至少现在)是过滤掉 header 行作为 select 语句的一部分?

目前,AWS Redshift Spectrum 不支持跳过 header 行。如果可以,您可以提出支持问题,以便跟踪此功能的可用性。

可以将此请求转发给开发团队考虑。

回答于:

这适用于 Redshift:

您想使用table properties ('skip.header.line.count'='1') 如果需要,可以与其他属性一起使用,例如'numRows'='100'。 这是一个示例:

create external table exreddb1.test_table
(ID BIGINT 
,NAME VARCHAR
)
row format delimited
fields terminated by ','
stored as textfile
location 's3://mybucket/myfolder/'
table properties ('numRows'='100', 'skip.header.line.count'='1');