首页 > 解决方案 > AWS Glue - 将 fileld 添加到结构字段

问题描述

我在 AWS Glue 中定义了一个表。我使用 AWS Kinesis 流通过这个表定义,使用 parquet 文件格式将日志流式传输到 S3。它按日期划分。

表中的字段之一是具有多个字段的结构event_payload,其中一个是结构数组。最近我在日志数据的内部结构中添加了一个新字段。我想将它添加到表定义中,以便将其写入 S3,以便我可以使用 AWS Athena 查询它。

我尝试直接在控制台中编辑表模式。它确实将数据写入 S3,但查询时在 Athena 中出现异常:

HIVE_PARTITION_SCHEMA_MISMATCH: There is a mismatch between the table and partition schemas. The types are incompatible and cannot be coerced. The column 'event_payload' in table 'c2s.logs' is declared as type 'struct<...>', but partition 'year=2019/month=201910/day=20191026/hour=2019102623' declared column 'event_payload' as type 'struct<...>'.

我尝试按照此处指定的方式删除所有分区并修复表,但出现另一个错误:

HIVE_CANNOT_OPEN_SPLIT: Error opening Hive split s3://.../year=2019/month=201910/day=20191022/hour=2019102216/beaconFirehose-4-2019-10-22-16-34-21-71f183d2-207e-4ae9-98fe-07dda0bab70c.parquet (offset=0, length=801679): Schema mismatch, metastore schema for row column event_payload.markings.element has 8 fields but parquet schema has 7 fields

因此,模式有一个数据中不存在的字段。有没有办法指定一个可选字段?如果它不存在,就让它为空。

标签: amazon-web-servicesparquetaws-glueamazon-athenaamazon-kinesis-firehose

解决方案


Athena 不支持根据链接架构更新嵌套结构。完成这项工作的一种方法是在 Glue 中的 relalaionalize 运算符的帮助下展平结构类型。例如:

val frames: Seq[DynamicFrame] = lHistory.relationalize(rootTableName = "hist_root", stagingPath = redshiftTmpDir, JsonOptions.empty)

推荐阅读