java - 如何动态使用java在spark数据框中展平复杂的嵌套json
问题描述
我的输入 json 数据框文件如下所示:
company: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- address: struct (nullable = true)
| | | |-- city: string (nullable = true)
| | | |-- county: string (nullable = true)
| | | |-- latitude: string (nullable = true)
| | | |-- line1: string (nullable = true)
| | | |-- line2: string (nullable = true)
| | | |-- longitude: string (nullable = true)
| | | |-- postalCode: long (nullable = true)
| | | |-- state: struct (nullable = true)
| | | | |-- code: int (nullable = true)
| | | | |-- name: string (nullable = true)
| | | |-- stateOtherDescription: string (nullable = true)
| | |-- addressSourceOther: string (nullable = true)
| | |-- addressSourceType: struct (nullable = true)
| | | |-- code: int (nullable = true)
| | | |-- name: string (nullable = true)
| | |-- reasons: array (nullable = true)
| | | |-- element: struct (containsNull = true)
| | | |-- improve: string (nullable = true)
| | | |-- far: string (nullable = true)
| | | |-- home: string (nullable = true)
我想使用 spark java 动态地展平它。有人可以帮我弄这个吗
解决方案
查看http://stefanfrings.de/bfUtilities/bfUtilities.zip中的 de.stefanfrings/parsing/JsonSlurper 类。它读取 JSON 文档并根据内容创建平面 HashMap。
推荐阅读
- reactjs - useDispatch 渲染不变的子元素
- javascript - 任务上的 Maximo Anywhere 条件必填字段
- sql - ROW_NUMBER() PARTITION BY ORDER BY 等效的 DAX 表达式
- laravel - 根据两个布尔值 laravel 针对 `user_id` 查找结果
- javascript - 如何告诉 eslint:禁用下一行“'import' 和 'export' 可能只出现在 'sourceType: module' 中”
- java - 如何用 JodaTime 表示“时间”
- java - Java PrinterJob,高质量打印最终以 72 DPI 结束
- xamarin - 如何在 Visual Studio 2019 中生成 .csproj 文件?
- ruby-on-rails - puma 的 redmine 错误:错误转换执行错误(NoMethodError(未定义的方法 `do' for false:FalseClass))
- reactjs - 如何根据 css 媒体查询重定向到 next.js 中的另一个页面?