XML 从架构到 Hive 架构
XML Schema to Hive Schema
我正在尝试将 xml 文件加载到配置单元 table 中。我正在使用 xml serde here。我能够加载简单的平面 xml 文件。但是当 xml 中有嵌套元素时,我使用 hive 复杂数据类型来存储它们(例如 array<struct>
)。下面是我尝试加载的示例 xml。我的目标是将所有元素、属性和内容加载到配置单元 table.
<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>
我试图获得的 Hive 输出是...
{action:"up", name:[{action:"aorup", ln:"te", content:"this is name1"}, {action:"aorup", ln:"tm", content:"this is name2"}, {action:"aorup", ln:"hi", content:"this is name3"}]}
我想将整个 xml 加载到一个配置单元列中。我尝试了以下方法:
CREATE TABLE description(
description STRUCT<
Action:STRING,
name:ARRAY<STRUCT<
Action:STRING, ln:STRING, content: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.description"="/description")
STORED AS INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
TBLPROPERTIES ("xmlinput.start"="<description ","xmlinput.end"= "</description>");
但我得到的 Label
字段为空值。有人可以帮助我吗?
谢谢
create external table description
(
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
(
"column.xpath.description" = "/description"
)
stored as
inputformat 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
outputformat 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
tblproperties
(
"xmlinput.start" = "<description "
,"xmlinput.end" = "</description>"
)
;
select * from description
;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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 name2"}]} |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
我正在尝试将 xml 文件加载到配置单元 table 中。我正在使用 xml serde here。我能够加载简单的平面 xml 文件。但是当 xml 中有嵌套元素时,我使用 hive 复杂数据类型来存储它们(例如 array<struct>
)。下面是我尝试加载的示例 xml。我的目标是将所有元素、属性和内容加载到配置单元 table.
<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>
我试图获得的 Hive 输出是...
{action:"up", name:[{action:"aorup", ln:"te", content:"this is name1"}, {action:"aorup", ln:"tm", content:"this is name2"}, {action:"aorup", ln:"hi", content:"this is name3"}]}
我想将整个 xml 加载到一个配置单元列中。我尝试了以下方法:
CREATE TABLE description(
description STRUCT<
Action:STRING,
name:ARRAY<STRUCT<
Action:STRING, ln:STRING, content: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.description"="/description")
STORED AS INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
TBLPROPERTIES ("xmlinput.start"="<description ","xmlinput.end"= "</description>");
但我得到的 Label
字段为空值。有人可以帮助我吗?
谢谢
create external table description
(
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
(
"column.xpath.description" = "/description"
)
stored as
inputformat 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
outputformat 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
tblproperties
(
"xmlinput.start" = "<description "
,"xmlinput.end" = "</description>"
)
;
select * from description
;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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 name2"}]} |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+