开发者社区 问答 正文

hive当中拆解json字段怎么做?

hive当中拆解json字段怎么做?

展开
收起
游客ahv54x37wvm7u 2021-12-08 20:08:26 570 分享 版权
1 条回答
写回答
取消 提交回答
  • hive (hive_explode)> select explode(split(regexp_replace(regexp_replace(sale_info,'\\[\\{',''),'}]',''),'},\\{')) as  sale_info from explode_lateral_view;
    
    然后我们想用get_json_object来获取key为monthSales的数据:
    
    hive (hive_explode)> select get_json_object(explode(split(regexp_replace(regexp_replace(sale_info,'\\[\\{',''),'}]',''),'},\\{')),'$.monthSales') as  sale_info from explode_lateral_view;
    
    
    然后挂了FAILED: SemanticException [Error 10081]: UDTF's are not supported outside the SELECT clause, nor nested in expressions
    UDTF explode不能写在别的函数内
    如果你这么写,想查两个字段,select explode(split(area,',')) as area,good_id from explode_lateral_view;
    会报错FAILED: SemanticException 1:40 Only a single expression in the SELECT clause is supported with UDTF's. Error encountered near token 'good_id'
    使用UDTF的时候,只支持一个字段,这时候就需要LATERAL VIEW出场了
    
    2021-12-08 20:08:40
    赞同 展开评论
问答分类:
问答标签:
问答地址: