如何在Hive中解析XML属性?

时间:2018-09-18 20:47:12

标签: xml hive xml-parsing

我可以解析出类似9531的值,因为它们包含在标记StatusValue中。但是我如何对DateTimeFromAppIdMessageId做同样的事情?

<PhoneCallEvent DateTime="2018-09-10T12:51:33.743-04:00" 
                FromAppId="200002" 
                MessageId="3407802">   
  <LoanNumber>307375</LoanNumber> 
  <StatusValue>9531</StatusValue>
  <StatusUserCommonID>2561550</StatusUserCommonID>
  <CallDirection>Inbound</CallDirection>
  <CallStartTime>2018-09-10T12:49:37.000-04:00</CallStartTime>
  <CallEndTime>2018-09-10T12:51:28.000-04:00</CallEndTime>
  <VectorDirectoryNumber/>
</PhoneCallEvent>

1 个答案:

答案 0 :(得分:0)

Hive具有XPath功能:

SELECT xpath ( xml_string , xpath ) FROM src LIMIT 1

SELECT xpath_string ( xml_string , xpath ) FROM src LIMIT 1

SELECT xpath_ 类型 ( xml_string , xpath ) FROM src LIMIT 1

例如,您可以将xpath_string与XPath一起使用

/PhoneCallEvent/@DateTime

选择DateTime属性值。