首页 > 解决方案 > 如何定义嵌套数组来摄取数据并进行转换?

问题描述

我正在使用 Firehose 和 Glue 来摄取数据并将 JSON 转换为 S3 中的 parquet 文件。

我成功地使用普通 JSON(不是嵌套或数组)实现了它。但是我对嵌套的 JSON 数组失败了。我做了什么:

JSON结构

{
    "class_id": "test0001",
    "students": [{
        "student_id": "xxxx",
        "student_name": "AAAABBBCCC",
        "student_gpa": 123
    }]
}

胶水模式

  1. class_id : 字符串
  2. 学生:数组ARRAY<STRUCT<student_id:STRING,student_name:STRING,student_gpa:INT>>

我收到错误:

The schema is invalid. Error parsing the schema: Error: type expected at the position 0 of 'ARRAY<STRUCT<student_id:STRING,student_name:STRING,student_gpa:INT>>' but 'ARRAY' is found.

任何建议表示赞赏。

标签: jsonamazon-web-servicesparquetaws-glueamazon-kinesis-firehose

解决方案


我遇到了这个问题,因为我在 AWS 控制台中手动创建了模式。问题是,它会在表单旁边显示一些帮助文本以输入您的嵌套数据,这些数据将所有内容都大写,但 Parquet 只能使用小写定义。

尽管 AWS 给出了示例,但还是要写:

array<struct<student_id:string,student_name:string,student_gpa:int>>

推荐阅读