You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Boto3创建Glue表后Athena查询仅显示分区列问题求助

问题原因

该问题核心是Athena的AvroSerDe对schema配置的读取逻辑和Hive不一致:

  • Hive支持从表级参数(TBLPROPERTIES)中读取avro.schema.url配置,但Athena要求该配置必须放在SerDe的参数(SERDEPROPERTIES)中才能正确识别
  • 你当前的建表代码把avro.schema.url放在了表级Parameters下,导致Athena的AvroSerDe无法找到Avro schema,无法正确解析数据列,所以返回的表结构全是找不到schema时的默认异常字段,查询时这些字段自然没有值,只有Glue中明确定义的分区列可以正常返回。
    你贴出的Athena DDL中出现error_error_error_error_error_error_error这类异常字段,就是SerDe无法读取schema的典型特征。
解决方案

直接修改Boto3建表代码,将avro.schema.url从表级参数移动到SerDe参数中即可,修改后的代码示例如下:

response = glue_client.create_table(
        DatabaseName='avro_database',
        TableInput={
            "Name": "avro_table_name",
            "Description": "Table created with boto3 API",
            "StorageDescriptor": {
                "Location": "s3://bucket_name/api/avro_folder",
                "InputFormat": "org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat",
                "OutputFormat": "org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat",
                "SerdeInfo": {
                    "SerializationLibrary": "org.apache.hadoop.hive.serde2.avro.AvroSerDe",
                    "Parameters": { 
                        "DeserializationLibrary": "org.apache.hadoop.hive.serde2.avro.AvroSerDe",
                        # 将avro.schema.url移到此处
                        "avro.schema.url": "s3://bucket/schema/L1/api/schema_avro.avsc"
                    },
                },
                # 不需要提前定义数据列,SerDe会自动从avro schema读取
                "Columns": []
            },
            "PartitionKeys": [
                {
                    "Name": "insert_yyyymmdd",
                    "Type": "string",
                }
            ],
            "TableType": "EXTERNAL_TABLE",
            "Parameters": {
                # 此处删除avro.schema.url配置
                'transient_lastDdlTime': '1635259605'
            }
        },
    )

修改完成后重新建表,再执行MSCK REPAIR TABLE avro_database.avro_table加载分区,再在Athena中查询即可正常返回所有列的数据。

注意事项
  • 确认Athena的执行角色(默认是AmazonAthenaFullAccess对应的角色,或自定义执行角色)拥有Avro schema文件所在S3路径的s3:GetObject权限,否则依然会出现schema读取失败的问题。

内容的提问来源于stack exchange,提问作者bSr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 01:39:05