Aws Athena - 创建跳过第一行的外部表

nic*_*ola 14 amazon-athena

我正在尝试使用Aws Athena在csv文件上创建一个外部表,但代码如下,但该行TBLPROPERTIES ("skip.header.line.count"="1")不起作用:它不会跳过csv文件的第一行(标题).

CREATE EXTERNAL TABLE mytable
(
  colA string,
  colB int
  )

 ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
 WITH SERDEPROPERTIES (
   'separatorChar' = ',',
   'quoteChar' = '\"',
   'escapeChar' = '\\'
   )
STORED AS TEXTFILE
LOCATION 's3://mybucket/mylocation/'
TBLPROPERTIES (
  "skip.header.line.count"="1")
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

Fil*_*ddo 22

刚尝试了"skip.header.line.count"="1",现在似乎工作正常.

  • 它开始工作自2018-01-19.请参阅https://docs.aws.amazon.com/athena/latest/ug/release-note-2018-01-19.html (4认同)
  • TBLPROPERTIES('skip.header.line.count'='1')..对我来说很好 (3认同)

Gun*_*ach 7

在AWS控制台上,您可以将其指定为Serde参数键值键对

跳过 athena 表中的标头

如果您使用 terraform 将基础设施作为代码应用,则可以使用ser_de_info参数 - "skip.header.line.count" = 1。示例如下

resource "aws_glue_catalog_table" "banana_datalake_table" {
  name          = "mapping"
  database_name = "banana_datalake"
  table_type    = "EXTERNAL_TABLE"
    owner = "owner"
    storage_descriptor {
        location        = "s3://banana_bucket/"
        input_format    = "org.apache.hadoop.mapred.TextInputFormat"
        output_format   = "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"
        compressed  = "false"
        number_of_buckets = -1    
        ser_de_info {
            name    = "SerDeCsv"
            serialization_library = "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"
            parameters {
                "field.delim" = ","
                "skip.header.line.count" = 1    # Skip file headers
            }
        }
        columns {
            name    = "column_1"
            type    = "string"
        }
        columns {
            name    = "column_2"
            type    = "string"
        }
        columns {
            name    = "column_3"
            type    = "string"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 5

这是一项尚未实施的功能.请在此处查看Abhishek @ AWS'的回复:

"我们正在研究它,并会在我们得到结果时立即报告.对此再次抱歉.这最终花费的时间比我们预期的要长."

我的解决方法是在创建表之前预处理数据:

  1. 从S3下载csv文件
  2. 使用bash删除标题 sed -e 1d -e 's/\"//g' file.csv > file-2.csv
  3. 将结果上传到S3上的自己的文件夹
  4. 创建表

  • 此功能自2018-01-19以来已在AWS Athena上提供.请参阅https://docs.aws.amazon.com/athena/latest/ug/release-note-2018-01-19.html>支持忽略标题.定义表时可以使用skip.header.line.count属性,以允许Athena忽略标头. (3认同)

小智 5

我最近尝试过:

TBLPROPERTIES ('skip.header.line.count'='1')
Run Code Online (Sandbox Code Playgroud)

现在效果很好。当我将列标题作为字符串(时间戳)并且记录包含实际时间戳时,就会出现此问题。我的查询会轰炸,因为它会扫描表并找到一个字符串而不是timestamp.

像这样的东西:

时间
2015-06-14 14:45:19.537
2015-06-14 14:50:20.546