首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >配置单元Serde Xpath提取

配置单元Serde Xpath提取
EN

Stack Overflow用户
提问于 2017-02-28 06:31:51
回答 1查看 258关注 0票数 0

我有一个需要在hive中提取的xml。我正在使用hive serde来做这件事。要求是将一列中的xml存储为字符串。但是,当我这样做时,属性是颠倒的,因为xpath是自下而上填充的。我正在尝试让它完全像xml那样显示出来。似乎hive会自动按字母顺序排列属性。

输入:

代码语言:javascript
复制
 <example>
    <context>
         <field1 b_attribute ="first" a_attribute1 ="second" ></field1>
    </context>
 </example>

我现在得到的是:

代码语言:javascript
复制
<example>
    <context>
         <field1 a_attribute1 ="second" b_attribute ="first" ></field1>
    </context>
 </example>

预期输出:

代码语言:javascript
复制
<example>
    <context>
         <field1 b_attribute ="first" a_attribute1 ="second" ></field1>
    </context>
 </example>

配置单元Serde创建:

代码语言:javascript
复制
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>"
);
EN

回答 1

Stack Overflow用户

发布于 2017-02-28 07:01:35

我不明白问题所在。

代码语言:javascript
复制
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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42496993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档