将带有时间戳列的 csv 加载到 athena table

Load csv with timestamp column to athena table

我已经开始在我的 S3 文件上使用 Athena 查询引擎 其中一些是时间戳格式列。

我创建了一个包含 2 列的简单 table

CREATE EXTERNAL TABLE `test`(
  `date_x` timestamp, 
  `clicks` int)
ROW FORMAT DELIMITED 
  FIELDS TERMINATED BY ',' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  's3://aws-athena-query-results-123-us-east-1/test'
TBLPROPERTIES (
  'has_encrypted_data'='false', 
  'transient_lastDdlTime'='1525003090')

我尝试加载一个文件并使用 Athena 查询它: 看起来像这样:

"2018-08-09 06:00:00.000",12
"2018-08-09 06:00:00.000",42
"2018-08-09 06:00:00.000",22

我尝试了不同类型的时间戳格式,例如 DD/MM/YYYY 和 YYY-MM-DD...,尝试为每一行设置时区 - 但其中 none 行得通。

我尝试过的每个值都在 Athena 中显示为以下结果:

        date_x  clicks
        1       12
        2       42
        3       22

我试过使用带和不带 headers 的 CSV 文件 尝试使用带引号和不带引号, 但所有这些都显示有缺陷的时间戳。 我在 Athena 上的专栏必须是时间戳 - 而不是没有时区。 请不要提供使用 STRING 列或 DATE 列,这不是我需要的。

CSV 文件应该是什么样子,这样 Athena 才能识别时间戳列?

试试格式:yyyy-MM-dd HH:mm:ss.SSSSSS

文章 https://docs.amazonaws.cn/en_us/redshift/latest/dg/r_CREATE_EXTERNAL_TABLE.html 建议:

"Timestamp values in text files must be in the format yyyy-MM-dd HH:mm:ss.SSSSSS, as the following timestamp value shows: 2017-05-01 11:30:59.000000 . "