尝试查询多个分区文件时 Athena 数据不匹配

Athena data mismatch when attempting to query multiple partitioned files

我在 S3 中有多个按天分区的镶木地板文件。这些镶木地板文件的每一列都包含 'string' 类型,我使用以下代码进行了检查:

import awswrangler as wr
results = wr.s3.list_objects('s3://datalake/buildings/upload_year=*/upload_month=*/upload_day=*/*.parquet.gzip')
for result in results:
    df = wr.s3.read_parquet(result)
        column_not_string = sum([1 if str(x) != 'string' else 0 for x in df.dtypes])
        print(column_not_string)

column_not_string是每个文件中非字符串类型字段的总和。文件的每次迭代 returns 0,符合预期。

这些 parquet 文件然后由 AWS Glue 爬网程序进行爬网。在我 运行 爬虫之后,我检查了新创建的 table。所有数据类型均为 'string'。我检查了分区,分区属性中的每个字段都是 'string'.

问题:

当我去雅典娜查询新创建的table:

select *
from "default".buildings;

我收到以下错误:

SQL Error [100071] [HY000]: [Simba]AthenaJDBC An error has been thrown from the AWS Athena client. HIVE_BAD_DATA: Field buildingcode's type INT64 in parquet is incompatible with type string defined in table schema

我不明白这是怎么回事。如果parquet文件的元数据都是string类型,抓取的文件都是string,table创建成string,怎么会出现int类型的数据不匹配?

当我在 Glue 中查看 table 分区属性时(AWS Glue > Tables > [your table] > View Partitions > View properties)我注意到 'objectCount' 属性 在某些分区上为 1,在其他分区上为 > 1。我注意到如果我将我的 SQL 过滤到那个特定的分区,那么具有 > 1 的分区也是 Athena 出错的分区。

我检查了该分区的 S3 位置代表并注意到我有多个对象,而我只希望有 1 个。额外的对象是一个镶木地板文件,其数据类型不是字符串。吸取教训。