Athena查询不会返回任何比表创建更新的结果

时间:2018-03-12 06:21:52

标签: amazon-web-services amazon-cloudfront amazon-athena

the formal instructions for querying CloudFront access logs using Athena之后,我在Athena中创建了一个名为default.cloudfront_logs的表,它指向我在我的CloudFront分配的访问日志正在写入的S3中的路径:

CREATE EXTERNAL TABLE `cloudfront_logs`( <fields here> )
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.serde2.RegexSerDe' 
WITH SERDEPROPERTIES ( 
  'input.regex'='^(?!#)([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)\\s+([^ \\t]+)$') 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  's3://mybucket/examplecom'
TBLPROPERTIES (
  'transient_lastDdlTime'='1520796451')

然后我验证了查询返回数据:

SELECT date, count(*)
FROM cloudfront_logs
order by date
group by date;

但是,在创建表后的几天内,我的查询中没有出现更新的数据,尽管我的S3存储桶中出现了更多的访问日志文件(后续日期)。

我尝试删除并重新创建表,但查询仍会返回相同的结果(在创建原始Athena表后没有更新的访问日志数据)。

为什么S3中出现的较新数据未显示在我的Athena查询结果中?

1 个答案:

答案 0 :(得分:0)

如果您的数据被分区为子目录,那么Athena可能不知道新创建的目录。

使用MSCK REPAIR TABLE扫描分区:

MSCK REPAIR TABLE cloudfront_logs;

然后,再次运行您的查询。

只要文件夹结构发生变化,就必须这样做。