hive xml udf

<store>
   <book id="book"><title id="titile">hive</title><price id="pri">10</price>
   </book>
   <fruit id="shuiguo">
       <apple id="shuiguo1"><name>apple</name><price>5</price></apple>
       <pear  id="shuiguo2"><name>pear</name><price>3.5</price></pear>
   </fruit>
</store>

-----------------------------

路径表达式  //  从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置

                   @  选取属性

                   . 当前节点

                   ..当前节点的父节点

hive> select xpath('<store><book id="book"><title id="titile">hive</title><price id="pri">10</price></book><fruit id="shuiguo"><apple id="shuiguo1"><name>apple</name><price>5</price></apple><pear id="shuiguo2"><name>pear</name><price>3.5</price></pear></fruit></store>','//@id');
OK
_c0
["book","titile","pri","shuiguo","shuiguo1","shuiguo2"]
Time taken: 0.144 seconds, Fetched: 1 row(s)

路径表达式  //  从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置

hive> select xpath('<store><book id="book"><title id="titile">hive</title><price id="pri">10</price></book><fruit id="shuiguo"><apple id="shuiguo1"><name>apple</name><price>5</price></apple><pear id="shuiguo2"><name>pear</name><price>3.5</price></pear></fruit></store>','store//text()');
OK
_c0
["hive","10","apple","5","pear","3.5"]
Time taken: 0.171 seconds, Fetched: 1 row(s)

hive> select xpath('<store id="shangdian"><book id="book"><title id="titile">hive</title><price id="pri">10</price></book><fruit id="shuiguo"><apple id="shuiguo1"><name>apple</name><price>5</price></apple><pear id="shuiguo2"><name>pear</name><price>3.5</price></pear></fruit></store>','//text()');
OK
_c0
["hive","10","apple","5","pear","3.5"]
Time taken: 0.145 seconds, Fetched: 1 row(s)

路径表达式  / 从根节点选取

扫描二维码关注公众号,回复: 85797 查看本文章

hive> select xpath('<store id="shangdian"><book id="book"><title id="titile">hive</title><price id="pri">10</price></book><fruit id="shuiguo"><apple id="shuiguo1"><name>apple</name><price>5</price></apple><pear id="shuiguo2"><name>pear</name><price>3.5</price></pear></fruit></store>','store/*[@id="shuiguo"]/@id');
OK
_c0
["shuiguo"]
Time taken: 0.154 seconds, Fetched: 1 row(s)

路径表达式  //  从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置
hive> select xpath('<store id="shangdian"><book id="book"><title id="titile">hive</title><price id="pri">10</price></book><fruit id="shuiguo"><apple id="shuiguo1"><name>apple</name><price>5</price></apple><pear id="shuiguo2"><name>pear</name><price>3.5</price></pear></fruit></store>','store/*[@id="shuiguo"]//@id');
OK
_c0
["shuiguo","shuiguo1","shuiguo2"]
Time taken: 0.163 seconds, Fetched: 1 row(s)

猜你喜欢

转载自www.cnblogs.com/playforever/p/8967732.html