无法从csv文件定义时间戳

时间:2017-10-12 07:09:51

标签: sql amazon-web-services amazon-athena amazon-quicksight

我正在尝试将数据存储到S3的Athena数据库中,我的日期时间格式如下: -

  

20171011133902

我正在尝试将格式设置为时间戳,但它无法识别,因此没有数据插入到表中。 我将格式设置为bigint只是为了插入数据,我的查询看起来像这样。

  

CREATE EXTERNAL TABLE IF NOT NOT EXISTS default.elb_logs(   'request_timestamp'bigint,'id'int,.....)

我尝试在Quicksight中进行转换,但是当我编辑数据字段并将其更改为日期时,我变成了这样: -

  

2033-12-02T01:51:53.000Z

有人可以帮助我处理这种类型的日期格式吗?

2 个答案:

答案 0 :(得分:1)

有两种解决方案: -

  1. 我在Quicksight上使用过parseDate函数,但它确实有效。 (不更改Athena DB上的数据类型) - >仅在您不使用SPICE时有效
  2.   

    parseDate(uploadtimestamp,' yyyyMMddHHmmss')

    1. 我还想知道我需要将其更改为String(在Athena DB上),以便将转换为日期按钮在QuickSight上正常工作。
    2.   

      CREATE EXTERNAL TABLE IF NOT NOT EXISTS default.elb_logs(' request_timestamp' string,' id' int,.....)

答案 1 :(得分:0)

我建议您将日期时间作为字符串加载,然后使用parse_datetime函数将其解析为选择查询中的时间戳。对于JSON数据,如:

ERROR in [at-loader] ./ClientApp/components/home/home.ts:23:9 
TS2346: Supplied parameters do not match any signature of call target.

ERROR in [at-loader] ./ClientApp/components/home/home.ts:24:9 
TS2346: Supplied parameters do not match any signature of call target.

ERROR in [at-loader] ./ClientApp/components/home/home.ts:25:18 
TS2345: Argument of type '[undefined, undefined] | [number, number]' is not 
assignable to parameter of type '(number | Date | { valueOf(): number; })
[]'.
Type '[undefined, undefined]' is not assignable to type '(number | Date | { 
valueOf(): number; })[]'.
Types of property 'push' are incompatible.
  Type '(...items: undefined[]) => number' is not assignable to type 
'(...items: (number | Date | { valueOf(): number; })[]) => number'.
    Types of parameters 'items' and 'items' are incompatible.
      Type 'number | Date | { valueOf(): number; }' is not assignable to 
 type 'undefined'.
        Type 'number' is not assignable to type 'undefined'.

您的日期/时间字段定义为字符串:

{"dt": "20171011133902", ... }

使用CREATE EXTERNAL TABLE scratch.test_dates ( `dt` string ) ... 将dt重新格式化为适当时间戳的查询:

parse_datetime

将生成带时区的时间戳(在您的情况下为UTC):

SELECT
  parse_datetime(dt, 'YYYYMMddHHmmss') as parsed_date
FROM 
  scratch."test_dates"