<?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 Re: HIVE : counting null values based on group by in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168105#M130435</link>
    <description>&lt;P&gt;Sample create and insert as below - 


&lt;/P&gt;&lt;PRE&gt;create table t1(date_column string, c1 int, c2 int, c3 int, c4 int, c5 int);

insert into t1 values("d1",1,1,1,1,1);
insert into t1 (date_column,c1) values ("d1",1);
insert into t1 (date_column,c1) values ("d2",1);
insert into t1 values("d2",1,1,1,1,1);&lt;/PRE&gt;&lt;P&gt;

I was expecting the below query to return 0 for d1 and d2, unfortunately got an empty result set. 

&lt;/P&gt;&lt;PRE&gt;select count(*) from t1 where c1 is null group by date_column;
&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Mar 2017 02:08:38 GMT</pubDate>
    <dc:creator>arunak</dc:creator>
    <dc:date>2017-03-22T02:08:38Z</dc:date>
    <item>
      <title>HIVE : counting null values based on group by</title>
      <link>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168104#M130434</link>
      <description>&lt;P&gt;Hello All, &lt;/P&gt;&lt;P&gt;I am trying to group all records for a table by "date" which is also a column. I need to count the number of null values for each column in the table grouped by date. &lt;/P&gt;&lt;P&gt;All the columns are of numeric type double/int. &lt;/P&gt;&lt;P&gt;Below is a sample input/output requirement&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="13854-main-table.jpg" style="width: 575px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/20243i44B932BEAE2C1463/image-size/medium?v=v2&amp;amp;px=400" role="button" title="13854-main-table.jpg" alt="13854-main-table.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="13855-result-table.jpg" style="width: 494px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/20244i71C9DD7B3D5F4D05/image-size/medium?v=v2&amp;amp;px=400" role="button" title="13855-result-table.jpg" alt="13855-result-table.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;
Simple select query that helps accomplish this requirement is 
select date,count(*) as c1_null from t1 where c1 is null group by date&lt;/P&gt;&lt;P&gt;I chain this select pattern for every c'i' columns. &lt;/P&gt;&lt;P&gt;This works fine only if every value for a given column is null and returns an empty result set if at least one column is non null. &lt;/P&gt;&lt;P&gt;What is a way to accomplish this? &lt;/P&gt;&lt;P&gt;Any help appreciated. &lt;/P&gt;&lt;P&gt;Thanks 
-arun&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 11:02:17 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168104#M130434</guid>
      <dc:creator>arunak</dc:creator>
      <dc:date>2019-08-18T11:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: HIVE : counting null values based on group by</title>
      <link>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168105#M130435</link>
      <description>&lt;P&gt;Sample create and insert as below - 


&lt;/P&gt;&lt;PRE&gt;create table t1(date_column string, c1 int, c2 int, c3 int, c4 int, c5 int);

insert into t1 values("d1",1,1,1,1,1);
insert into t1 (date_column,c1) values ("d1",1);
insert into t1 (date_column,c1) values ("d2",1);
insert into t1 values("d2",1,1,1,1,1);&lt;/PRE&gt;&lt;P&gt;

I was expecting the below query to return 0 for d1 and d2, unfortunately got an empty result set. 

&lt;/P&gt;&lt;PRE&gt;select count(*) from t1 where c1 is null group by date_column;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2017 02:08:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168105#M130435</guid>
      <dc:creator>arunak</dc:creator>
      <dc:date>2017-03-22T02:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: HIVE : counting null values based on group by</title>
      <link>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168106#M130436</link>
      <description>&lt;PRE&gt;WITH t1nulltest AS
( select date_column
,SUM(IF(c1 IS NULL,1,0)) OVER (PARTITION BY date_column) as c1null
,SUM(IF(c2 IS NULL,1,0)) OVER (PARTITION BY date_column) as c2null
,SUM(IF(c3 IS NULL,1,0)) OVER (PARTITION BY date_column) as c3null
,SUM(IF(c4 IS NULL,1,0)) OVER (PARTITION BY date_column) as c4null
,SUM(IF(c5 IS NULL,1,0)) OVER (PARTITION BY date_column) as c5null
,row_number() OVER (PARTITION BY date_column) as rowno
from t1) 
select 
  date_column, c1null, c2null,c3null,c4null,c5null from t1nulltest
  where rowno =1;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2017 02:34:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168106#M130436</guid>
      <dc:creator>amcbarnett</dc:creator>
      <dc:date>2017-03-22T02:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: HIVE : counting null values based on group by</title>
      <link>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168107#M130437</link>
      <description>&lt;P&gt;Thanks &lt;A rel="user" href="https://community.cloudera.com/users/369/amcbarnett.html" nodeid="369"&gt;@Ancil McBarnett&lt;/A&gt;. Appreciate it. &lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 02:40:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168107#M130437</guid>
      <dc:creator>arunak</dc:creator>
      <dc:date>2017-03-22T02:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: HIVE : counting null values based on group by</title>
      <link>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168108#M130438</link>
      <description>&lt;P&gt;You can also achieve this by using following query:&lt;/P&gt;&lt;PRE&gt;SELECT date_column, 
	count(*)-count(c1) as null_c1, 
	count(*)-count(c2) as null_c2, 
	count(*)-count(c3) as null_c3, 
	count(*)-count(c4) as null_c4 
FROM t1 
GROUP BY date_column;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 01:43:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168108#M130438</guid>
      <dc:creator>vgarg</dc:creator>
      <dc:date>2017-03-23T01:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: HIVE : counting null values based on group by</title>
      <link>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168109#M130439</link>
      <description>&lt;P&gt;@amcbarnett : i am trying to aggregate a data using "state,count( distinct val ) group by state " but want just the "Not Null" &lt;/P&gt;&lt;P&gt;Val - String datatype&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 02:21:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/HIVE-counting-null-values-based-on-group-by/m-p/168109#M130439</guid>
      <dc:creator>shetty_vikas</dc:creator>
      <dc:date>2019-08-01T02:21:29Z</dc:date>
    </item>
  </channel>
</rss>

