【问题标题】:AWS Glue - Adding fileld to a struct fieldAWS Glue - 将字段添加到结构字段
【发布时间】:2020-02-29 13:44:57
【问题描述】:

我在 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<...>'.

我尝试按照here 的说明删除所有分区并修复表,但又遇到另一个错误:

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

因此,架构有一个数据中不存在的字段。 有没有办法指定一个可选字段?如果它不存在,则将其设为 null。

【问题讨论】:

    标签: amazon-web-services parquet aws-glue amazon-athena amazon-kinesis-firehose


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢...我想我必须运行某种 ETL 来使结构变平?
    • @YossiVainshtein - 是的,您需要在您的 etl.xml 中添加关系化。如果你觉得这个答案有帮助,你也可以接受。
    猜你喜欢
    • 2013-01-27
    • 1970-01-01
    • 2021-09-30
    • 2020-05-19
    • 1970-01-01
    • 2022-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多