在AWS Redshift外部表中跳过标题行

fez*_*fez 4 amazon-web-services amazon-redshift amazon-redshift-spectrum

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

name,age,gender
jill,30,f
jack,32,m
Run Code Online (Sandbox Code Playgroud)

以及使用频谱查询数据的redshift 外部表:

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://...';
Run Code Online (Sandbox Code Playgroud)

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

select * from spectrum.customers;
name,age,g
jill,30,f
jack,32,m
Run Code Online (Sandbox Code Playgroud)

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

The*_*ata 10

回答这个问题:当我们从s3中的csv文件读取数据并在aws athena中创建表时,如何跳过标题.

这适用于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');
Run Code Online (Sandbox Code Playgroud)

  • 以下是有关“创建外部表”的 AWS Redshift SQL 文档,http://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_EXTERNAL_TABLE.html (2认同)