2017-02-27 58 views
0

我有一個需要在配置單元中提取的xml。我正在使用配置單元來執行此操作。要求是將一列中的xml存儲爲字符串。但是,當我這樣做時,屬性被逆轉,因爲xpath從下到上填充。我試圖讓它顯示完全和xml一樣。似乎配置單元會自動按字母順序排列屬性。Hive Serde Xpath Extract

輸入:

<example> 
    <context> 
     <field1 b_attribute ="first" a_attribute1 ="second" ></field1> 
    </context> 
</example> 

什麼我現在越來越:

<example> 
    <context> 
     <field1 a_attribute1 ="second" b_attribute ="first" ></field1> 
    </context> 
</example> 

預期輸出:

<example> 
    <context> 
     <field1 b_attribute ="first" a_attribute1 ="second" ></field1> 
    </context> 
</example> 

蜂巢SERDE創作:

create external table EXAMPLE (
example_xml string 
) 
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe' 
WITH SERDEPROPERTIES (
"column.xpath.example_xml"="reverse(/context/*)" 
) 
STORED AS 
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat' 
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat' 
LOCATION 'mypathinhdfs' 
TBLPROPERTIES (
"xmlinput.start"="<example>", 
"xmlinput.end"="</example>" 
); 

回答

1

我不明白這個問題。

hive> create external table EXAMPLE (
    > example_xml string 
    >) 
    > ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe' 
    > WITH SERDEPROPERTIES (
    > "column.xpath.example_xml"="/" 
    >) 
    > STORED AS 
    > INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat' 
    > OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat' 
    > LOCATION '/user/hive/warehouse/example' 
    > TBLPROPERTIES (
    > "xmlinput.start"="<example>", 
    > "xmlinput.end"="</example>" 
    >); 
OK 
Time taken: 0.186 seconds 
hive> select * from EXAMPLE; 
OK 
example.example_xml 
<example><context><field1 attribute="first" attribute1="second"/></context></example> 
+0

我修改了示例XML條目複製的問題。似乎蜂巢按屬性排序。 – Defcon