给予 这是我的 JSON
...
"actions": [
{
"action_type": "link_click",
"value": "1"
},
{
"action_type": "page_engagement",
"value": "1"
},
{
"action_type": "post_engagement",
"value": "1"
},
.....
]
}
...
我想将每个action_type
的值映射到我的外部表的特定列
CREATE EXTERNAL TABLE raw_marketing_other.facebook_ad_cost_dtl_hrly (
...
linkClick : int
pageEngagement : int
...
)
例如,linkClick
列将具有从该 json 对象派生的值 1
。
问题 这在 serdeProperties 的映射中是否可行?像这样。
create table ...
...
ROW FORMAT serde 'org.openx.data.jsonserde.JsonSerDe'
WITH serdeproperties(
"mapping.linkClick" = "actions[action_type="link_click].value",
...
注意:哪里的 actions[action_type="link_click]"是为了返回具有该条件的 json 对象的第一次出现?
如果无法通过自定义映射实现,那么是否有其他解决方案?
最佳答案
我会按原样加载数据,然后使用 get_json_object
UDF 查询它。
沿着这些线的东西:
SELECT *
FROM my_table
WHERE get_json_object(json_column, '$.actions.action_type') = 'link_click';
关于hadoop - 从 JSONserde 中的 JSON 数组访问 sibling 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45846908/