我有一个需要在配置单元中提取的 xml。我正在使用配置单元 serde 来执行此操作。要求是将一列中的 xml 存储为字符串。但是,当我这样做时,属性被颠倒了,因为 xpath 是自下而上填充的。我试图让它完全按照 xml 的显示方式显示。似乎配置单元会自动按字母顺序排列属性。
输入:
<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>
Hive 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>"
);
最佳答案
我不明白这个问题。
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>
关于xml - Hive Serde Xpath 提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42496993/