<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question how to export xml data saved in a hive table's string field to other hive table created as SERDE ,how to export xml data saved in a ms-sql field (as single string) into hive table created with SERDE in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145539#M44231</link>
    <description>&lt;P&gt;1) below hive table "books_xml" contains only one field named "xmldata" in which I have saved xml data as a single string.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;hive&amp;gt; select xmldata from books_xml;
OK
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&amp;lt;catalog&amp;gt;&amp;lt;book&amp;gt;  &amp;lt;id&amp;gt;11&amp;lt;/id&amp;gt; 
&amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;  &amp;lt;price&amp;gt;44&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;book&amp;gt;  &amp;lt;id&amp;gt;44&amp;lt;/id&amp;gt; 
&amp;lt;genre&amp;gt;Fantasy&amp;lt;/genre&amp;gt;  &amp;lt;price&amp;gt;5&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/catalog&amp;gt;
Time taken: 0.175 seconds, Fetched: 1 row(s)&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;2) I want to export above xml data (which is in field) into below hive table created with SERDE properties?

CREATE TABLE books_serde (
   id STRING, 
   genre STRING, 
   price DOUBLE
)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES (
"column.xpath.id"="/book/id/text()",
"column.xpath.genre"="/book/genre/text()",
"column.xpath.price"="/book/price/text()"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
TBLPROPERTIES (
"xmlinput.start"="&amp;lt;book&amp;gt;",
"xmlinput.end"="&amp;lt;/book&amp;gt;"
);
&lt;/CODE&gt;&lt;/PRE&gt;,&lt;PRE&gt;&lt;CODE&gt;1) below hive table "books_xml" contains only one field named "xmldata String" in which I have saved xml data as a single string.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;hive&amp;gt; select xmldata from books_xml;
&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;OK
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&amp;lt;catalog&amp;gt;&amp;lt;book&amp;gt;  &amp;lt;id&amp;gt;11&amp;lt;/id&amp;gt; 
&amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;  &amp;lt;price&amp;gt;44&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;book&amp;gt;  &amp;lt;id&amp;gt;44&amp;lt;/id&amp;gt; 
&amp;lt;genre&amp;gt;Fantasy&amp;lt;/genre&amp;gt;  &amp;lt;price&amp;gt;5&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/catalog&amp;gt;
Time taken: 0.175 seconds, Fetched: 1 row(s)&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;2) I want to export above xml data (which is in field) into below hive table created with SERDE properties?
&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;CREATE TABLE books_serde (
   id STRING, 
   genre STRING, 
   price DOUBLE
)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES (
"column.xpath.id"="/book/id/text()",
"column.xpath.genre"="/book/genre/text()",
"column.xpath.price"="/book/price/text()"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
TBLPROPERTIES (
"xmlinput.start"="&amp;lt;book&amp;gt;",
"xmlinput.end"="&amp;lt;/book&amp;gt;"
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 23 Oct 2016 01:32:03 GMT</pubDate>
    <dc:creator>rylala72</dc:creator>
    <dc:date>2016-10-23T01:32:03Z</dc:date>
    <item>
      <title>how to export xml data saved in a hive table's string field to other hive table created as SERDE ,how to export xml data saved in a ms-sql field (as single string) into hive table created with SERDE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145539#M44231</link>
      <description>&lt;P&gt;1) below hive table "books_xml" contains only one field named "xmldata" in which I have saved xml data as a single string.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;hive&amp;gt; select xmldata from books_xml;
OK
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&amp;lt;catalog&amp;gt;&amp;lt;book&amp;gt;  &amp;lt;id&amp;gt;11&amp;lt;/id&amp;gt; 
&amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;  &amp;lt;price&amp;gt;44&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;book&amp;gt;  &amp;lt;id&amp;gt;44&amp;lt;/id&amp;gt; 
&amp;lt;genre&amp;gt;Fantasy&amp;lt;/genre&amp;gt;  &amp;lt;price&amp;gt;5&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/catalog&amp;gt;
Time taken: 0.175 seconds, Fetched: 1 row(s)&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;2) I want to export above xml data (which is in field) into below hive table created with SERDE properties?

CREATE TABLE books_serde (
   id STRING, 
   genre STRING, 
   price DOUBLE
)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES (
"column.xpath.id"="/book/id/text()",
"column.xpath.genre"="/book/genre/text()",
"column.xpath.price"="/book/price/text()"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
TBLPROPERTIES (
"xmlinput.start"="&amp;lt;book&amp;gt;",
"xmlinput.end"="&amp;lt;/book&amp;gt;"
);
&lt;/CODE&gt;&lt;/PRE&gt;,&lt;PRE&gt;&lt;CODE&gt;1) below hive table "books_xml" contains only one field named "xmldata String" in which I have saved xml data as a single string.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;hive&amp;gt; select xmldata from books_xml;
&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;OK
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&amp;lt;catalog&amp;gt;&amp;lt;book&amp;gt;  &amp;lt;id&amp;gt;11&amp;lt;/id&amp;gt; 
&amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;  &amp;lt;price&amp;gt;44&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;book&amp;gt;  &amp;lt;id&amp;gt;44&amp;lt;/id&amp;gt; 
&amp;lt;genre&amp;gt;Fantasy&amp;lt;/genre&amp;gt;  &amp;lt;price&amp;gt;5&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/catalog&amp;gt;
Time taken: 0.175 seconds, Fetched: 1 row(s)&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;2) I want to export above xml data (which is in field) into below hive table created with SERDE properties?
&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;CREATE TABLE books_serde (
   id STRING, 
   genre STRING, 
   price DOUBLE
)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES (
"column.xpath.id"="/book/id/text()",
"column.xpath.genre"="/book/genre/text()",
"column.xpath.price"="/book/price/text()"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
TBLPROPERTIES (
"xmlinput.start"="&amp;lt;book&amp;gt;",
"xmlinput.end"="&amp;lt;/book&amp;gt;"
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Oct 2016 01:32:03 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145539#M44231</guid>
      <dc:creator>rylala72</dc:creator>
      <dc:date>2016-10-23T01:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to export xml data saved in a hive table's string field to other hive table created as SERDE ,how to export xml data saved in a ms-sql field (as single string) into hive table created with SERDE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145540#M44232</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/13924/rylala72.html" nodeid="13924"&gt;@Riaz Lala&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Have you looked at the &lt;A target="_blank" href="https://community.hortonworks.com/questions/54917/what-is-the-best-way-to-load-xml-data-into-hive.html"&gt;post&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Let me know if this is helpful&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2016 03:06:19 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145540#M44232</guid>
      <dc:creator>hrongali</dc:creator>
      <dc:date>2016-10-23T03:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to export xml data saved in a hive table's string field to other hive table created as SERDE ,how to export xml data saved in a ms-sql field (as single string) into hive table created with SERDE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145541#M44233</link>
      <description>&lt;P&gt;Thanks Hari, yes I have seen that post which is bit different in scenario. Post explains loading xml file "sample.xml"  into hive serde table. In my case I have xml stored in a hive table field 'xmldata' and i want to use some sort of 'insert into table_serde select xmlfield from XmlTable'. I mean xml data moving from hive table to hive table.&lt;/P&gt;&lt;P&gt;Other way for me is that I can add location parameter in serde table pointing to location where single field hive table has stored its data but this has draw back if I add other fields in single field hive table it will invalidate serde table.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Riaz Lala&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2016 03:54:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145541#M44233</guid>
      <dc:creator>rylala72</dc:creator>
      <dc:date>2016-10-23T03:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to export xml data saved in a hive table's string field to other hive table created as SERDE ,how to export xml data saved in a ms-sql field (as single string) into hive table created with SERDE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145542#M44234</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/13924/rylala72.html" nodeid="13924"&gt;@Riaz Lala&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Okay, I have got two options for you that you can try:&lt;/P&gt;&lt;P&gt;Option#11) Using xpath builtin function:&lt;/P&gt;&lt;P&gt;You might have to do some data transformations to your input file to break down the book nodes to individual records. My input data looks like below:&lt;/P&gt;&lt;PRE&gt;&amp;lt;catalog&amp;gt;&amp;lt;book&amp;gt;&amp;lt;id&amp;gt;11&amp;lt;/id&amp;gt;&amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;&amp;lt;price&amp;gt;44&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/catalog&amp;gt; 

&amp;lt;catalog&amp;gt;&amp;lt;book&amp;gt;&amp;lt;id&amp;gt;45&amp;lt;/id&amp;gt;&amp;lt;genre&amp;gt;Fantasy&amp;lt;/genre&amp;gt;&amp;lt;price&amp;gt;5&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/catalog&amp;gt;

&lt;/PRE&gt;&lt;PRE&gt;hive&amp;gt; select * from books_xml; 

OK 

&amp;lt;catalog&amp;gt;&amp;lt;book&amp;gt;&amp;lt;id&amp;gt;11&amp;lt;/id&amp;gt;&amp;lt;genre&amp;gt;Computer&amp;lt;/genre&amp;gt;&amp;lt;price&amp;gt;44&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/catalog&amp;gt; 

&amp;lt;catalog&amp;gt;&amp;lt;book&amp;gt;&amp;lt;id&amp;gt;45&amp;lt;/id&amp;gt;&amp;lt;genre&amp;gt;Fantasy&amp;lt;/genre&amp;gt;&amp;lt;price&amp;gt;5&amp;lt;/price&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/catalog&amp;gt;
Time taken: 0.483 seconds, Fetched: 2 row(s)&lt;/PRE&gt;&lt;P&gt;Then you can use xpath function like below to access individual columns:&lt;/P&gt;&lt;PRE&gt;hive&amp;gt; select xpath_int(xmldata, '/catalog/book/id'), xpath_string(xmldata, '/catalog/book/genre') as genre, xpath_int(xmldata, '/catalog/book/price') from books_xml;
OK
11	Computer	44
45	Fantasy		5
Time taken: 0.508 seconds, Fetched: 2 row(s)&lt;/PRE&gt;&lt;P&gt;You can do insert overwrite to load into any other external table you want with regular column names&lt;/P&gt;&lt;P&gt;Option#2) Use of external UDF function that parses the xml data into an array and use explode function to select the indivudual values and load them to any target table you have.&lt;/P&gt;&lt;P&gt;Let me know if this helps&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2016 04:34:17 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145542#M44234</guid>
      <dc:creator>hrongali</dc:creator>
      <dc:date>2016-10-23T04:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to export xml data saved in a hive table's string field to other hive table created as SERDE ,how to export xml data saved in a ms-sql field (as single string) into hive table created with SERDE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145543#M44235</link>
      <description>&lt;P&gt;Thank you very much Hari. Option#1 is perfect in my case.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2016 08:37:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145543#M44235</guid>
      <dc:creator>rylala72</dc:creator>
      <dc:date>2016-10-23T08:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to export xml data saved in a hive table's string field to other hive table created as SERDE ,how to export xml data saved in a ms-sql field (as single string) into hive table created with SERDE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145544#M44236</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/13924/rylala72.html" nodeid="13924"&gt;@Riaz Lala&lt;/A&gt; &lt;/P&gt;&lt;P&gt;Glad that it was helpful. Can you upvote and accept the answer please? &lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2016 08:42:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145544#M44236</guid>
      <dc:creator>hrongali</dc:creator>
      <dc:date>2016-10-23T08:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to export xml data saved in a hive table's string field to other hive table created as SERDE ,how to export xml data saved in a ms-sql field (as single string) into hive table created with SERDE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145545#M44237</link>
      <description>&lt;P&gt;@Riaz Lala&lt;/P&gt;&lt;P&gt;Have you find solution to your post? If yes, Can you please pose your approach please. I am struggling with the same situation. Help needed. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 10:06:32 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-export-xml-data-saved-in-a-hive-table-s-string-field/m-p/145545#M44237</guid>
      <dc:creator>naveenraja_k</dc:creator>
      <dc:date>2018-11-29T10:06:32Z</dc:date>
    </item>
  </channel>
</rss>

