sql - 使用结构检索数组中的值
问题描述
我在 Hive 表中有一个类型为:
array<array<struct<type:string,value:string,currency:string>>>
以下是列中的数据示例:
[
[
{
"type": "PROFIT",
"value": "100",
"currency": "USD"
},
{
"type": "NET",
"value": "50",
"currency": "USD"
},
{
"type": "TOTAL",
"value": "250",
"currency": "USD"
}
]
]
如何将每个“类型”查询到一列?
利润 | 网 | 全部的 |
---|
解决方案
展开上层数组得到struct的内部数组,使用数组索引[]访问struct,使用dot访问struct元素:
select a1.inner_array[0].type as type1,
a1.inner_array[1].type as type2,
a1.inner_array[2].type as type3
from yourtable t
--explode upper array
lateral view outer explode(col_name) a1 as inner_array
推荐阅读
- intellij-idea - 如何在 PyCharm 中找到“从/到源的自动滚动”?
- django - Django 在其他字段中形成所有更改,除了图像字段正在工作
- php - 自动从某个目录导入所有 CSS 文件的 PHP 函数
- java - 玉兰日志中的 AbstractFieldFactory 警告
- python - 从 Python 中的字符表达式创建列表的优雅方式
- javascript - page.js 库:如何启用 onbeforeunload?
- java - RemoteServer - 如何在 Robotframework 中使用 Java 关键字?
- python - python绘制特征向量
- .htaccess - htaccess localhost - mod-rewrite,htdocs,mamp
- angular - Angular中contentEditable元素上的focus()不起作用