aws athena中为不同的表设置不同的输出结果位置

Set different output result location for different tables in aws athena

我启用了云端日志,想通过它获取一些信息。

为此,我正在使用 aws athena 查询 cf 日志。这对我的暂存环境来说绝对没问题,因为它将查询结果存储在我的暂存桶中。

对于生产,我创建了另一个 table,它将从生产存储桶中查询 cf 日志文件,我想将结果存储在不同的 s3 存储桶(生产存储桶)中。但我没有找到任何方法来拥有不同的输出查询结果位置。 有什么方法可以为不同的 tables

设置不同的输出结果位置

如果您使用 CREATE TABLE AS 语句创建 table,您可以在 WITH 子句中设置特定 table 的结果位置。例如:

 CREATE TABLE table_name
 WITH (
   external_location ='s3://my-bucket/tables/table_name/'
 )
 AS
 SELECT * FROM database.my_table

不幸的是,这需要一个空位置才能使查询正常工作。如果要 re-run 此查询或更改位置,则需要删除该位置中的所有文件。有关详细信息,请参阅 Athena documentation

我假设您是在谈论 S3 中的 QueryResultLocation:

QueryResultsLocationInS3 is the query result location specified either by workgroup settings or client-side settings.

您可以在 Specifying a Query Result Location 中找到有关如何设置位置的更多详细信息:

The query result location that Athena uses is determined by a combination of workgroup settings and client-side settings. Client-side settings are based on how you run the query.

  • If you run the query using the Athena console, the Query result location entered under Settings in the navigation bar determines the client-side setting.
  • If you run the query using the Athena API, the OutputLocation parameter of the StartQueryExecution action determines the client-side setting.
  • If you use the ODBC or JDBC drivers to run queries, the S3OutputLocation property specified in the connection URL determines the client-side setting.