Sco*_*ion 8 sql presto amazon-athena
我在 S3 中有日期,我使用它创建了一个 Athena 表。我在 S3 中有一些 json 格式的日期条目,Athena 在运行查询时不接受这些条目作为日期或时间戳。
使用使用 Prestodb 作为查询引擎的 AWS Athena
示例 json :
{"creationdate":"2018-09-12T15:49:07.269Z", "otherfield":"value1"}
{"creationdate":"2018-09-12T15:49:07Z", "otherfield":"value2"}
AWS Glue 将这两个字段都作为字符串,当我将它们分别更改为时间戳和日期时,时间戳周围的查询不起作用,在时间戳字段上给出 ValidationError。
无论如何,我找到了一种使用 prestodb date_parse 函数的方法,但它也不起作用,因为某些字段有毫秒而其他字段没有。
parse_datetime(creationdate, '%Y-%m-%dT%H:%i:%s.%fZ')
parse_datetime(creationdate, '%Y-%m-%dT%H:%i:%sZ')
两者都失败,因为存在不同的条目,即一个有毫秒 %f 和一个没有 有没有办法提供解析器,正则表达式,以便能够在 sql 查询执行期间将这些字符串转换为日期?
jen*_*ter 10
您可以使用该from_iso8601_timestamp函数,而不是提供时间戳格式。
这样,所有时间戳都会被解析。
select from_iso8601_timestamp(creationdate) from table1;
Run Code Online (Sandbox Code Playgroud)
小智 -3
你只需要约会吗?
\n\n如果是这样,您可以使用 date_parse(string, format)。
\n\ndate_parse(creationdate, \xe2\x80\x98%Y-%m-%d\xe2\x80\x99)\nRun Code Online (Sandbox Code Playgroud)\n