xml - Hive Serde Xpath 提取

标签 xml hadoop xpath hive xml-serialization

我有一个需要在配置单元中提取的 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/

相关文章:

java - 我的方法中出现错误 ""- XPATH 与特定文本

java - 如何找到具有随机生成的 id 的元素的 xpath?

typescript - Protractor 从使用 mat-select 实现的下拉列表中选择值

php - 具有属性 php 的 xml 节点上的解析错误

xml - 如何使 xsd 元素扩展另一个

C++ Boost 循环遍历未知的 ptree 和属性的列表值

hadoop - 将目录的Map输出合并到一个文件

java - 将 ODT 转换为单个 XML 文件

python - 使用 python 的 Jaydebeapi 连接到 Hive

Hadoop 生态系统 : Map Reduce needed for Pig/Hive