将XML加载到Hive时出现空指针异常

时间:2017-08-14 13:21:28

标签: sql xml hive

我在使用hive-serde将xml文件加载到Hive时遇到了一些问题。我按照这里的提示进行操作,但在尝试读取通过xml文件加载到配置单元中的数据时,我仍然收到空指针异常。下面的SQL运行正常,只有在尝试从表中读取问题时才会发生

这是带有一些虚拟值的xml

    <?xml version="1.0"?><History-Group-Comm-CommB-DT-RBB-Work 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <item id="HISTORY_6_GMT">
    <pxAddedByID>HUBINT</pxAddedByID>
    <pxAddedBySystem>CD</pxAddedBySystem>
    <pxHistoryForReference>GR</pxHistoryForReference>
    <pxInsName>GMT</pxInsName>
    <pxObjClass>Work</pxObjClass>
    <pxTimeCreated>2017-02-13T13:08:28.776Z</pxTimeCreated>
    <pyFlowKey>RULE-OBJ</pyFlowKey>
    <pyFlowName>pyStartCase</pyFlowName>
    <pyFlowType>pyStartCase</pyFlowType>
    <pyMessageKey>ItemCreated</pyMessageKey>
    <pyPerformer>HUB</pyPerformer>
    <pzInsKey>776 GMT</pzInsKey>
    </item>

和加载xml的sql如下

    add jar hdfs://DEVHDPVM01HA:8020/HADOOP/DASD_ACQ/common/lib/hivexmlserde-1.0.5.3.jar;


     DROP TABLE IF EXISTS test.test_tbl_stg;
     CREATE EXTERNAL TABLE test.test_tbl_stg  (
     ADDED_BY_ID STRING COMMENT 'pxAddedByID',
     ADDED_BY_SYSTEM STRING COMMENT 'pxAddedBySystem',
     HISTORY_FOR_REFERENCE STRING COMMENT '',
     INSERT_NAME STRING COMMENT '',
     OBJECT_CLASS STRING COMMENT '',
     TIME_CREATED STRING COMMENT '',
     FLOW_KEY STRING COMMENT '',
     FLOW_NAME STRING COMMENT '',
     FLOW_TYPE FLOAT COMMENT '',
     MESSAGE STRING COMMENT '',
     PERFORMER STRING COMMENT '',
     INSERT_KEY STRING COMMENT '' ) COMMENT 'Optional Table Comment'
     ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
     WITH SERDEPROPERTIES (
     "column.xpath.ADDED_BY_ID"="/item/pxAddedByID/text()", 
     "column.xpath.ADDED_BY_SYSTEM"="/item/pxAddedBySystem/text()",
   "column.xpath.HISTORY_FOR_REFERENCE"="/item/pxHistoryForReference/text()",
    "column.xpath.INSERT_NAME"="/item/pxInsName/text()",
    "column.xpath.OBJECT_CLASS"="/item/pxObjClass/text()",
    "column.xpath.TIME_CREATED"="/item/pxTimeCreated/text()",
    "column.xpath.FLOW_KEY"="/item/pyFlowKey/text()",
    "column.xpath.FLOW_NAME"="/item/pyFlowName/text()",
    "column.xpath.FLOW_TYPE"="/item/pyFlowType/text()",
    "column.xpath.MESSAGE"="/item/pyMessageKey/text()",
    "column.xpath.PERFORMER"="/item/pyPerformer/text()",
    "column.xpath.INSERT_KEY"="/item/pzInsKey/text()")
    STORED AS
    INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
    OUTPUTFORMAT 
    'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
    LOCATION '${stagingFolderPath}'
    TBLPROPERTIES ("xmlinput.start"="<item id=","xmlinput.end"="</item>");

非常感谢有关为何发生此空指针异常的任何建议

1 个答案:

答案 0 :(得分:1)

转换此字段数据类型      FLOW_TYPE FLOAT评论&#39;&#39;         至      FLOW_TYPE STRING COMMENT&#39;&#39;,

因为转换我认为你正面临这个问题