我有一个需要在hive中提取的xml。我正在使用hive serde来做这件事。要求是将一列中的xml存储为字符串。但是,当我这样做时,属性是颠倒的,因为xpath是自下而上填充的。我正在尝试让它完全像xml那样显示出来。似乎hive会自动按字母顺序排列属性。
输入:
<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>"
);发布于 2017-02-28 07:01:35
我不明白问题所在。
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>https://stackoverflow.com/questions/42496993
复制相似问题