amazon-web-services - 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
因此,模式有一个数据中不存在的字段。有没有办法指定一个可选字段?如果它不存在,就让它为空。
解决方案
Athena 不支持根据链接架构更新嵌套结构。完成这项工作的一种方法是在 Glue 中的 relalaionalize 运算符的帮助下展平结构类型。例如:
val frames: Seq[DynamicFrame] = lHistory.relationalize(rootTableName = "hist_root", stagingPath = redshiftTmpDir, JsonOptions.empty)
推荐阅读
- google-cloud-platform - 从 GCP 中的命令行获取客户端 ID
- python - 熊猫的 itterows 更新问题
- kubernetes - Kubernetes 从 GCR 私有仓库下载镜像
- python - python raises syntax error in environment variable path
- python - 如何从数据框中的第 5 列应用 cummax 逻辑
- monads - 如何在 Idris 中使用 ST 来获得 ReaderT r Maybe a 的功能?
- python - 使用 Python SQLAlchemy 将 JSON 发布到数据库
- centos - Centos iptables 显示规则但没有安装服务
- node.js - 路由处理程序中的函数
- c++ - 如何有效地对满足给定谓词的向量中的所有项目进行操作?