我正在尝试将 xml 文件加载到配置单元表中。我正在使用 xml serde [这里][1]。我能够加载简单的平面 xml 文件。但是当 xml 中有嵌套元素时,我使用 hive 复杂数据类型来存储它们(例如,array<struct>
)。下面是我尝试加载的示例 xml。我的目标是将所有元素、属性和内容加载到配置单元表中。
<classif action="del">
<code>123</code>
<class action="aou">
<party>p1</party>
<description action="up">
<name action="aorup" ln="te">
this is name1
</name>
<name action="aorup" ln="tm">
this is name2
</name>
<name action="aorup" ln="hi">
this is name2
</name>
</description>
</class>
<class action="a">
<party>p2</party>
<description action="up">
<name action="aorup" ln="te">
this is name4
</name>
<name action="aorup" ln="tm">
this is name5
</name>
<name action="aorup" ln="hi">
this is name6
</name>
</description>
</class>
</classif>
我试图获得的 Hive 输出是......
{action:"del", classif:{code:"123", class:[{action:"aou", class:{party:"p1", description:{action:"up", description:[{action:"aorup", ln:"te", name:"this is name1"}, {action:"aorup", ln:"tm", name:"this is name2"}, {action:"aorup", ln:"hi", name:"this is name3"}]}}}, {action:"a", class:{party:"p2", description:{action:"up", description:[{action:"aorup", ln:"te", name:"this is name4"}, {action:"aorup", ln:"tm", name:"this is name5"}, {action:"aorup", ln:"hi", name:"this is name6"}]}}}]}}
我想将整个 xml 加载到单个配置单元列中。我尝试了以下方法:
DROP TABLE classif;
CREATE TABLE classif(
classif STRUCT<
Action:STRING, classif:STRUCT<Code:STRING, class:ARRAY<STRUCT<Action:STRING, class:STRUCT<party:STRING, description:STRUCT<action:STRING,description:ARRAY<STRUCT<action:STRING,ln:STRING,name:STRING>>>
>>>
>>)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES (
"xml.processor.class"="com.ximpleware.hive.serde2.xml.vtd.XmlProcessor",
"column.xpath.classif"="/classif")
STORED AS INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
TBLPROPERTIES ("xmlinput.start"="<classif ","xmlinput.end"= "</classif>");
我得到的输出:
{"action":"del","classif":{"code":"123","class":[{"action":null,"class":null},{"action":"up","class":null},{"action":null,"class":null},{"action":"up","class":null}]}}