当我在运行 MSCK REPAIR TABLE 时,Amazon Athena 返回一个分区列表,但之后却未能将这些分区添加到 AWS Glue 数据目录的表中。
简短描述
以下是导致此行为的一些常见原因:
- AWS Identity and Access Management (IAM) 用户或角色没有允许 glue:BatchCreatePartition 操作的策略。
- Amazon Simple Storage Service (Amazon S3) 路径采用驼峰式大小写而不是小写(例如,使用 userId 而不是 userid)。
解决方法
在 IAM 策略中允许 glue:BatchCreatePartition
审核附加到您用于执行 MSCK REPAIR TABLE 的用户或角色的 IAM 策略。当您将 AWS Glue 数据目录与 Athena 一起使用时,IAM 策略必须允许 glue:BatchCreatePartition 操作。如果策略不允许该操作,则 Athena 将无法添加分区到元存储。如需了解允许 glue:BatchCreatePartition 操作的 IAM 策略示例,请参阅 AmazonAthenaFullAccess 托管策略。
将 Amazon S3 路径更改为小写
Amazon S3 路径名称必须为小写。若路径采用驼峰式大小写,则 MSCK REPAIR TABLE 不会添加分区到 AWS Glue 数据目录。例如,如果 Amazon S3 路径为 userId,以下分区不会被添加到 AWS Glue 数据目录:
- s3://awsdoc-example-bucket/path/userId=1/
- s3://awsdoc-example-bucket/path/userId=2/
- s3://awsdoc-example-bucket/path/userId=3/
要解决此问题,请使用小写而不是驼峰式大小写:
- s3://awsdoc-example-bucket/path/userid=1/
- s3://awsdoc-example-bucket/path/userid=2/
- s3://awsdoc-example-bucket/path/userid=3/
相关信息
在 Athena 中对数据进行分区
Amazon Athena 的操作、资源和条件键
AWS Glue 的操作、资源和条件键