我正在尝试使用带有Hive的SerDe加载以下XML内容:
<?xml version="1.0"?>
<RootTag xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.website.com/service">
<Code>123</Code>
<ParentElement>
<Entity>
<EntityId>A</EntityId>
<EntityCode i:nil="true"/>
</Entity>
<Entity>
<EntityId>M</EntityId>
<EntityCode i:nil="true"/>
</Entity>
</ParentElement>
</RootTag>
配置单元表创建如下:
CREATE EXTERNAL TABLE database.mytable(
code String,
Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES
(
"column.xpath.Code" = "/RootTag/Code/text()",
"column.xpath.ParentElement" = "/RootTag/ParentElement"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
LOCATION '/xml_content/'
TBLPROPERTIES ("xmlinput.start" = "<RootTag", "xmlinput.end" = "</RootTag>");
我有2个问题:
Caused by: org.apache.hive.service.cli.HiveSQLException:
java.io.IOException:
org.apache.hadoop.hive.serde2.SerDeException:
java.lang.RuntimeException:
org.xml.sax.SAXParseException;
lineNumber: 41;
columnNumber: 33;
The prefix "i" for attribute "i:nil" associated with an element type "ParentCode" is not bound.
我在做什么错?感谢您提出的建议和意见。
答案 0 :(得分:0)
几乎没有东西。
i:nil="true"
column.xpath.Code
和code
不起作用。也没有column.xpath.ParentElement
那么您需要做什么?
<EntityCode i:nil="true"/>
替换为<EntityCode/>
代码
CREATE EXTERNAL TABLE temp.test_xml(
code String,
Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES
(
"column.xpath.code" = "/RootTag/Code/text()",
"column.xpath.Entity" = "/RootTag/ParentElement/Entity"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
LOCATION '/tmp/test_xml1/table/'
TBLPROPERTIES (
"xmlinput.start"="<RootTag",
"xmlinput.end"="</RootTag>");