<?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 handle nulls when exporting from Hive? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-handle-nulls-when-exporting-from-Hive/m-p/198390#M65862</link>
    <description>&lt;P&gt;I often need to export data from Hive to CSV files so that I can share with folks - usually they will ultimately import the CSV data into some sort of standard DB.&lt;/P&gt;&lt;P&gt;Currently, I use a CLI command like this:&lt;/P&gt;&lt;P&gt;hive -e 'set hive.cli.print.header=true; select * from blah where condition ' | sed 's/[\t]/,/g' &amp;gt; myfile.csv&lt;/P&gt;&lt;P&gt;However, when I do it this way, null values actually get printed as "NULL". &lt;/P&gt;&lt;P&gt;For example, an output row might be:&lt;/P&gt;&lt;P&gt;0|true|NULL|1|0|'my string'|NULL|etc&lt;/P&gt;&lt;P&gt;So, my question: What can I add to my command to replace those NULL entries with just an empty character?&lt;/P&gt;&lt;P&gt;In other words, how do I instead get this:&lt;/P&gt;&lt;P&gt;0|true||1|0|'my string'||etc&lt;/P&gt;&lt;P&gt;?&lt;/P&gt;</description>
    <pubDate>Tue, 01 Aug 2017 17:52:41 GMT</pubDate>
    <dc:creator>zack_riesland</dc:creator>
    <dc:date>2017-08-01T17:52:41Z</dc:date>
    <item>
      <title>How to handle nulls when exporting from Hive?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-handle-nulls-when-exporting-from-Hive/m-p/198390#M65862</link>
      <description>&lt;P&gt;I often need to export data from Hive to CSV files so that I can share with folks - usually they will ultimately import the CSV data into some sort of standard DB.&lt;/P&gt;&lt;P&gt;Currently, I use a CLI command like this:&lt;/P&gt;&lt;P&gt;hive -e 'set hive.cli.print.header=true; select * from blah where condition ' | sed 's/[\t]/,/g' &amp;gt; myfile.csv&lt;/P&gt;&lt;P&gt;However, when I do it this way, null values actually get printed as "NULL". &lt;/P&gt;&lt;P&gt;For example, an output row might be:&lt;/P&gt;&lt;P&gt;0|true|NULL|1|0|'my string'|NULL|etc&lt;/P&gt;&lt;P&gt;So, my question: What can I add to my command to replace those NULL entries with just an empty character?&lt;/P&gt;&lt;P&gt;In other words, how do I instead get this:&lt;/P&gt;&lt;P&gt;0|true||1|0|'my string'||etc&lt;/P&gt;&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 17:52:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-handle-nulls-when-exporting-from-Hive/m-p/198390#M65862</guid>
      <dc:creator>zack_riesland</dc:creator>
      <dc:date>2017-08-01T17:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle nulls when exporting from Hive?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-handle-nulls-when-exporting-from-Hive/m-p/198391#M65863</link>
      <description>&lt;P&gt;Using your sed approach, this should replace all NULL with empty character&lt;/P&gt;&lt;PRE&gt;sed 's/[\t]/,/g; s/NULL//g'  &amp;gt; myfile.csv&lt;/PRE&gt;&lt;P&gt;If there is a chance that NULL is a substring of a value you will need to do the following where ^ is beginning of line and $ is end of line and , is your field delimiter&lt;/P&gt;&lt;PRE&gt;sed 's/[\t]/,/g; s/^NULL,/,/g; s/,NULL,/,,/g; s/,NULL$/,/g;'  &amp;gt; myfile.csv&lt;/PRE&gt;&lt;P&gt;Note that if your resultset is large, it is probably best to use Pig on HDFS and not sed (to leverage the parallel processing of hadoop and save yourself a lot of time.&lt;/P&gt;&lt;P&gt;Note also: To use empty character as nulls in the actual hive table, use the following in the DDL&lt;/P&gt;&lt;PRE&gt;TBLPROPERTIES('serialization.null.format'='');&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Aug 2017 18:35:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-handle-nulls-when-exporting-from-Hive/m-p/198391#M65863</guid>
      <dc:creator>gkeys</dc:creator>
      <dc:date>2017-08-01T18:35:06Z</dc:date>
    </item>
  </channel>
</rss>

