【问题标题】:Partitioning table for amazon athena亚马逊雅典娜的分区表
【发布时间】:2017-06-07 16:17:10
【问题描述】:

我正在尝试按年、月和日对 amazon athena 查询的数据进行分区。但是,当我尝试从分区数据中查询时,我无法获得任何记录。我按照blog 帖子中的说明进行操作。

创建表查询:

CREATE external TABLE mvc_test2 (
ROLE struct<Scope: string, Id: string>,
ACCOUNT struct<ClientId: string, Id: string, Name: string>,
USER struct<Id: string, Name: string>,
IsAuthenticated INT,
Device struct<IpAddress: string>,
Duration double,
Id string,
ResultMessage string,
Application struct<Version: string, Build: string, Name: string>,
Timestamp string,
ResultCode INT
)
Partitioned by(year string, month string, day string)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3://firehose-titlesdesk-logs/Mvc/'

表创建成功,结果信息说:

"查询成功。如果你的表有分区,需要加载这些 分区以便能够查询数据。您可以加载所有 分区或单独加载它们。如果您使用所有负载 partitions (MSCK REPAIR TABLE) 命令,分区必须是格式 被 Hive 理解。了解更多。”

跑步

msck repair table mvc_test2;

我得到了结果:

"分区不在 元存储:mvc_test2:2017/06/06/21 mvc_test2:2017/06/06/22"

此时,我尝试查询表时没有得到任何结果。

日志按年/月/日/小时以子文件夹格式存储。 例如:'s3://firehose-application-logs/process/year/month/day/hour'

如何正确分区数据?

【问题讨论】:

  • "如果您使用加载所有分区 (MSCK REPAIR TABLE) 命令,分区必须采用 Hive 可以理解的格式"

标签: amazon-web-services hive presto amazon-athena


【解决方案1】:

您的目录格式似乎是2017/06/06/22。这与命名转换为 year=2017/month=06/day=06/hour=22 的 HIVE 分区不兼容。

因此,当前的数据格式使您无法使用分区。您需要重命名目录或(最好)通过 HIVE 处理您的数据,以便以正确的格式存储它。

另请参阅:Analyzing Data in S3 using Amazon Athena

【讨论】:

    【解决方案2】:

    按日期添加每个分区。这种方式速度更快,并为您节省更多的钱。仅加载您需要的分区,而不是所有分区。

    ALTER TABLE mvc_test2 
    ADD PARTITION (year='2017',month='06',day='06')
    location 's3://firehose-titlesdesk-logs/Mvc/'
    

    您可以根据需要通过更改年、月和/或日来加载更多分区,只要确保它们有效即可。然后您可以通过运行以下查询来检查以确保您的分区已加载:

    show partitions mvc_test2
    

    【讨论】:

      【解决方案3】:

      AWS 现在支持Athena Partition Projections,这将自动进行分区管理并在添加新数据时自动添加新分区

      https://docs.aws.amazon.com/athena/latest/ug/cloudtrail-logs.html#create-cloudtrail-table-partition-projection

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-02
        • 2013-10-09
        • 2016-11-26
        • 2012-12-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多