配置单元xml服务器:加载xml内容时分析错误

yqlxgs2m  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(258)

我正在尝试使用serde with hive加载以下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>");

我有两个问题:
当我如上所述指定“xmlinput.start”时,它不起作用。我不得不手动删除内容”xmlns:i = ... /“roottage”旁边的“服务”,以便开始解析xml。
尽管如此,“entitycode”属性还有另一个问题。我得到一个错误:

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.

我做错什么了?我将非常感谢您对此的建议和意见。

d5vmydt9

d5vmydt91#

事情很少。
我认为只有1.5.0.3或更高版本才支持带有名称空间的根标记。检查以下链接https://github.com/dvasilen/hive-xml-serde/issues/15
我不认为它支持 i:nil="true" 列的Map应与列名匹配并且区分大小写。 column.xpath.Code 以及 code 不起作用。也没有腐 eclipse 柱 column.xpath.ParentElement 那你需要做什么?
升级你的serde。
替换 <EntityCode i:nil="true"/><EntityCode/> 在xml中
修复下面提到的代码
代码

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>");

相关问题