美文网首页
Hive解析json

Hive解析json

作者: hello琳123 | 来源:发表于2018-05-14 20:28 被阅读0次

需要解析的json为:

{

    "_id":{

     "$oid":"580db8cf8ead0e093c876a72"

         }

,

    "aClassId":["15397303000114"],

    "iBookId":{

        "$numberLong":"145"

         }

,

    "iCreateTime":{

      "$numberLong":"1477294287"

       }

,

    "iEndTime":{

       "$numberLong":"1477324799"

        }

,

    "iQuestId":{

       "$numberLong":"17"

     }

,

    "iState":{

       "$numberLong":"1"

      }

,

    "iTchId":{

      "$numberLong":"39250"

      }

,

    "sQuestInfo":"{"parentId":3,"parentName":"Starter unit 2","childName":"3c"}"

}

解析代码为:

select

c.oid,

regexp_replace(b.aClassId, '"', '') as aClassId,   //去掉引号 " "

c.parentId,

c.parentName,

c.childName,

c.iBookId,

c.iCreateTime,

c.iEndTime,

c.iQuestId,

c.iState,

c.iTchId

from odsdata.speaktrain_0001_teacher_homework a

lateral view json_tuple(a.json,'_id','aClassId','iBookId','iCreateTime','iEndTime','iQuestId','iState','iTchId','sQuestInfo') b as id,aClassId,iBookId,iCreateTime,iEndTime,iQuestId,iState,iTchId,sQuestInfo

lateral view json_tuple(b.id,'$oid') c as oid

lateral view json_tuple(b.iBookId,'$numberLong') c as iBookId

lateral view json_tuple(b.iCreateTime,'$numberLong') c as iCreateTime

lateral view json_tuple(b.iEndTime,'$numberLong') c as iEndTime

lateral view json_tuple(b.iQuestId,'$numberLong') c as iQuestId

lateral view json_tuple(b.iState,'$numberLong') c as iState

lateral view json_tuple(b.iTchId,'$numberLong') c as iTchId

lateral view json_tuple(b.sQuestInfo,'parentId','parentName','childName') c as parentId,parentName,childName limit 2;

相关文章

  • hive 中实现对json格式数据的解析

    1. json对象 hive 中有json解析的工具get_json_object 和json_tupple,这里...

  • Hive解析json

    需要解析的json为: { "_id":{ "$oid":"580db8cf8ead0e093c876a72"...

  • Hive解析Json数据

    HIVE直接读入json的函数有两个: (1)get_json_object(string json_string...

  • Hive解析json数组

    在使用Hive搭建数据仓库,处理数据时,同传统数仓的结构化数据不同,我们经常会遇到一些非结构化的数据,json格式...

  • JSON

    JSON解析(反序列化) JSON解析(序列化) JSON解析补充

  • Json解析方式

    1.传统的JSON解析 1.1 生成Json 1.2 解析Json 2.Gson解析Json 2.1生成Json ...

  • hive 解析 json 字符串

    json_tuple (推荐用这个) json_tuple udtf 功能是在 hive 0.7 版本之后加入的,...

  • hive解析json字符串

    简单说明下,最近工作中需要把json字符串解析,并把json中数组拆成多行。最开始做这个工作的同事使用自定义udt...

  • JSON解析数据

    JsonObject解析 和JSonArray解析: JSON创建和JSON解析: 一。效果图: 创建: 解析: ...

  • get_json_object()的用法

    hive> select get_json_object('{ > "store": > { ...

网友评论

      本文标题:Hive解析json

      本文链接:https://www.haomeiwen.com/subject/fmtsdftx.html