hive 之 xml 字段解析

1、测试字段

<?xml version="1.0" encoding="UTF-8"?><people><Name>张三</Name><age>20</age><XinXi><XinBie>"男"</XinBie></XinXi></people>
<?xml version="1.0" encoding="UTF-8"?><people><Name>李四</Name><age>22</age><XinXi><XinBie>"男"</XinBie></XinXi></people>
<?xml version="1.0" encoding="UTF-8"?><people><Name>王五</Name><age>21</age><XinXi><XinBie>"男"</XinBie></XinXi></people>

特殊单标签:

<?xml version="1.0" encoding="UTF-8"?><OutputChannel><OnlineInfo><IBStream Level="0"/><IBStream Level="1"/><IBStream Level="2"/><IBStream Level="3"/><IBStream Level="4"/><IBStream Level="5"/></OnlineInfo></OutputChannel>

解析工具查看:

<?xml version="1.0" encoding="UTF-8"?>
<people>
    <Name>张三</Name>
    <age>20</age>
    <XinXi>
        <XinBie>"男"</XinBie>
    </XinXi>
</people>
<?xml version="1.0" encoding="UTF-8"?>
<people>
    <Name>李四</Name>
    <age>22</age>
    <XinXi>
        <XinBie>"男"</XinBie>
    </XinXi>
</people>
<?xml version="1.0" encoding="UTF-8"?>
<people>
    <Name>王五</Name>
    <age>21</age>
    <XinXi>
        <XinBie>"男"</XinBie>
    </XinXi>
</people>

<?xml version="1.0" encoding="UTF-8"?>
<OutputChannel>
    <OnlineInfo>
        <IBStream Level="0"/>
        <IBStream Level="1"/>
        <IBStream Level="2"/>
        <IBStream Level="3"/>
        <IBStream Level="4"/>
        <IBStream Level="5"/>
    </OnlineInfo>
</OutputChannel>

2、HQL解析

使用 xpath_string 函数解析 xml 字段

select xpath_string(ch_xml,'people/Name') ch_xml_Name,
xpath_string(ch_xml,'people/age') ch_xml_age,
xpath_string(ch_xml,'people/XinXi/XinBie') ch_xml_XinBie
from `table_name`;

特殊单标签解析:

select
xpath_string(ch_xml,'/OutputChannel/OnlineInfo/IBStream[1]/@Level'),
xpath_string(ch_xml,'/OutputChannel/OnlineInfo/IBStream[2]/@Level'),
xpath_string(ch_xml,'/OutputChannel/OnlineInfo/IBStream[3]/@Level'),
xpath_string(ch_xml,'/OutputChannel/OnlineInfo/IBStream[4]/@Level'),
xpath_string(ch_xml,'/OutputChannel/OnlineInfo/IBStream[5]/@Level'),
xpath_string(ch_xml,'/OutputChannel/OnlineInfo/IBStream[6]/@Level')
from `table_name`;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值