如何在CloudFormation中通过AWS Glue配置Athena表跳过表头
在CloudFormation的AWS Glue Table中配置Athena跳过表头行
嘿,这个需求我刚好处理过,其实在CloudFormation定义Glue Table的时候,只需要在TableInput的顶层参数里加个配置就能轻松搞定!
你需要给Glue Table的Parameters字段添加skip.header.line.count属性,值设为1(代表跳过1行表头,如果你的文件有多行表头,对应调整数字就行)。下面是一个完整的CloudFormation资源示例,你可以直接参考:
Resources: MyAthenaTable: Type: AWS::Glue::Table Properties: CatalogId: !Ref AWS::AccountId DatabaseName: my-glue-database TableInput: Name: my-athena-table Description: 配置了表头跳过的Athena表 StorageDescriptor: Columns: - Name: user_id Type: string - Name: order_amount Type: double Location: s3://my-data-bucket/order-data/ InputFormat: org.apache.hadoop.mapred.TextInputFormat OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat SerdeInfo: SerializationLibrary: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe Parameters: field.delim: ',' Parameters: skip.header.line.count: '1' # 核心配置就在这里!
需要注意的点:
- 这个
skip.header.line.count是Glue Table的顶层参数,别不小心放到SerdeInfo的Parameters里了,那样是不生效的。 - 参数值必须是字符串格式(比如
'1'而不是数字1),符合CloudFormation对Glue Table参数的格式要求。
配置完成后,当你用Athena查询这张表时,就会自动跳过数据文件的第一行表头,不会把表头当成有效数据读取啦!
内容的提问来源于stack exchange,提问作者user3002273
相关产品推荐
相关产品推荐

