简体   繁体   English

Amazon Athena 表创建问题

[英]Amazon Athena table creation issue

I have a table in Athena which has S3 as a source.我在 Athena 中有一张表,其中有 S3 作为源。

One of the table columns "Col1" has a datatype of string.表列“Col1”之一的数据类型为字符串。

Col1
2019-11-21T12:26:13.422Z
2019-11-21T17:12:49.812Z
2019-11-21T17:51:38.299Z

I want this column to be converted to a data type of timestamp .我希望将此列转换为timestamp的数据类型。

I ran the below query:我运行了以下查询:

SELECT
  from_iso8601_timestamp(col1) AS ABC
FROM "testtest"."layer2_keywords" 

Then I get a column with timestamp datatype:然后我得到一个带有时间戳数据类型的列:

col1

    col1
1   2019-11-12 10:11:08.017 UTC
2   2019-11-21 09:19:58.937 UTC
3   2019-11-22 09:23:47.786 UTC

I want to create a new table with this table output.我想用这个表输出创建一个新表。

I tried below query:我尝试了以下查询:

CREATE TABLE NEW_TABLE AS
SLECT
  from_iso8601_timestamp(col1) AS ABC
FROM layer2_keywords

But this command is not creating a new table.但是这个命令不是创建一个新表。

It throws error something like below:它抛出如下错误:

NOT_SUPPORTED: Unsupported Hive type: timestamp with time zone. NOT_SUPPORTED:不支持的 Hive 类型:带时区的时间戳。 You may need to manually clean the data at location 's3://athena-query-results-layer2/XXXXXXXXXX/' before retrying.在重试之前,您可能需要手动清理位置 's3://athena-query-results-layer2/XXXXXXXXXX/' 处的数据。 Athena will not delete data in your account. Athena 不会删除您帐户中的数据。

Can any one guide me how do I get a new table from the select query in AWS Athena for a string to timestamp conversion?任何人都可以指导我如何从 AWS Athena 中的选择查询中获取新表以进行字符串到时间戳的转换?

I have to rely on Athena as neither Glue crawler nor Glue ETL is transforming the string to timestamp transformation.我必须依赖 Athena,因为 Glue crawler 和 Glue ETL 都没有将字符串转换为时间戳转换。

I got the answer.我得到了答案。

I used CREATE TABLE AS SELECT (CTAS).我使用CREATE TABLE AS SELECT (CTAS)。

See: Use the Results of an Amazon Athena Query in Another Query请参阅: 在另一个查询中使用 Amazon Athena 查询的结果

But is there a method like a GROK expression that can be used even before data gets saved in S3?但是有没有一种方法可以在数据保存到 S3 之前使用,比如 GROK 表达式? If yes please can anyone provide a step by step procedure to write a GROK in Glue for this particular issue?如果是,请任何人都可以提供一个分步程序来针对这个特定问题在 Glue 中编写 GROK 吗?

string to timestamp字符串到时间戳

String : 2019-11-21T12:26:13.422Z字符串:2019-11-21T12:26:13.422Z

You could use CAST() function as follow:您可以使用 CAST() 函数如下:

CREATE TABLE NEW_TABLE AS
SLECT
  CAST(from_iso8601_timestamp(col1) AS TIMESTAMP) AS ABC
FROM layer2_keywords

I hope it helps you.我希望它能帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM