配置单元xml服务器-键/值对-Map

koaltpgm  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(340)
<Search>

<Country>USA</Country>
<Region>West</Region>
<Address>
    <Home>
        <Item>
                <id>Number</id>
                <value>135</value>
            </Item>
        <Item>
                <id>Street</id>
                <value>Pacific</value>
            </Item>
        <Item>
                <id>City</id>
                <value>Irvine</value>
            </Item>
        </Home>
     <Home>
        <Item>
                <id>Number</id>
                <value>1672</value>
            </Item>
        <Item>
                <id>Street</id>
                <value>Madison</value>
            </Item>
        <Item>
                <id>City</id>
                <value>Denver</value>
            </Item>
         </Home>
     </Address>

我试图创建下表结构,但我没有得到想要的结果
我试图创建下表结构,但我没有得到想要的结果我试图创建下表结构,但我没有得到想要的结果我试图创建下表结构,但我没有得到想要的结果

Country    Region                      Map
USA        West             {Number:135,Street:Pacific,City:Irvine}
USA        West             {Number:1672,Street:Madison,City:Denver}

`CREATE EXTERNAL TABLE search(
country string,
region string,
search array<struct<item:map<string,string>>>
)
PARTITIONED BY(date STRING)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES(
"column.xpath.country" = "/Search/country/text()",
"column.xpath.region" = "/Search/region/text()",
"column.xpath.item"="/Search/Address/Home/Item"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
LOCATION '/search'
TBLPROPERTIES (
"xmlinput.start"="",
"xmlinput.end"=""
);

这是可能的或任何其他关于如何获得上述格式的数据的建议。任何帮助都会很好。谢谢你`

0qx6xfy6

0qx6xfy61#

考虑到xml,您所能做的最好的事情可能是:

DROP TABLE IF EXISTS xml_47;

CREATE  TABLE xml_47(
  country string,
  region string,
  address array<struct<Home:array<struct<Item:struct<id:string,value:string>>>>>
)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES(
"column.xpath.country" = "/Search/Country/text()",
"column.xpath.region" = "/Search/Region/text()",
"column.xpath.address"="/Search/Address/Home"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
TBLPROPERTIES (
"xmlinput.start"="<Search>",
"xmlinput.end"="</Search>"
);

load data local inpath '/Users/dvasilen/Misc/XML/47.xml' OVERWRITE into table xml_47;

select * from xml_47;

以下是输出:

USA West    [{"home":[{"item":{"id":"Number","value":"135"}},{"item":{"id":"Street","value":"Pacific"}},{"item":{"id":"City","value":"Irvine"}}]},{"home":[{"item":{"id":"Number","value":"1672"}},{"item":{"id":"Street","value":"Madison"}},{"item":{"id":"City","value":"Denver"}}]}]
Time taken: 0.067 seconds, Fetched: 1 row(s)

要了解要素:

select address[0].home[0] from xml_47;
OK
{"item":{"id":"Number","value":"135"}}
Time taken: 0.076 seconds, Fetched: 1 row(s)

要获得所需的输出:

USA West {Number:135,Street:Pacific,City:Irvine}
USA West {Number:1672,Street:Madison,City:Denver}

你得把地板弄平 address 使用侧视图的阵列https://cwiki.apache.org/confluence/display/hive/languagemanual+lateralview

相关问题