<?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>topic How can a select count(1) from tablename return a null? in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/How-can-a-select-count-1-from-tablename-return-a-null/m-p/2284627#M58277</link>
    <description>&lt;P&gt;I have a job that is generating and executing SQL on Hive, including generating table names.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;It populates those tables, and then attempts to get a count from them.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The count statement, as shown in the job log, is this:&lt;/P&gt; 
&lt;PRE&gt;[tLogRow_3] content: select 'phil', 'iter', '20190920', count(1) from staging.traits_phil_iter_20190920_orc&lt;/PRE&gt; 
&lt;P&gt;So it's selecting the elements of the generated table name, and the row count from that table.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;If I run that in a separate Hive SQL client, it works fine and I get something like this:&lt;/P&gt; 
&lt;PRE&gt;phil, iter, 20190920, 2094&lt;/PRE&gt; 
&lt;P&gt;If I run it in a standalone job that just runs that hard coded SQL, I get this:&lt;/P&gt; 
&lt;PRE&gt;.-----------+----+--------+-----.
|           tLogRow_1           |
|=----------+----+--------+----=|
|region_name|type|date    |count|
|=----------+----+--------+----=|
|phil       |iter|20190920|2094 |
'-----------+----+--------+-----'&lt;/PRE&gt; 
&lt;P&gt;However, in the actual job that generates the SQL to create a view, create the table if it does not exist, insert data into it, and then run the count, I get this:&lt;/P&gt; 
&lt;PRE&gt;.-----------+----+--------+-----.
|           tLogRow_7           |
|=----------+----+--------+----=|
|region_name|type|date    |count|
|=----------+----+--------+----=|
|phil       |iter|20190920|null |
'-----------+----+--------+-----'&lt;/PRE&gt; 
&lt;P&gt;So everything works just fine apart from the count(1) returning null! Select count(1) should never ever return null! If the table does not exist, it should fail. If the table exists but is empty, it should return 0. null should be impossible!&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Any suggestions?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The job structure is that I have three iterate links, which in order do three things: create external tables and views and insert, then the select count(1) written into a tHashOutput, and thirdly reads the results of the select count(1) form the tHashOutput and creates a view if there is any data.&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;From this screenshot you can see the tLogRow_3 and tLogRow_7 are either side of the tHiveRow_2 component that runs the SQL, which is just running row6.content.&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="selectcountnull.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M8cK.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/152607i146D2A63AC03655D/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M8cK.png" alt="0683p000009M8cK.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;As you can see, the first iterate executes 4 statements, which are the table and view creation and insert. The second iterate executes 1 statement, which is the count from the table that was inserted into. The final iterate creates a view, but only if the count from the table inserted into is greater than zero. The problem is: I get a null from the count!&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 03:56:26 GMT</pubDate>
    <dc:creator>PhilHibbs</dc:creator>
    <dc:date>2024-11-16T03:56:26Z</dc:date>
    <item>
      <title>How can a select count(1) from tablename return a null?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-can-a-select-count-1-from-tablename-return-a-null/m-p/2284627#M58277</link>
      <description>&lt;P&gt;I have a job that is generating and executing SQL on Hive, including generating table names.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;It populates those tables, and then attempts to get a count from them.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The count statement, as shown in the job log, is this:&lt;/P&gt; 
&lt;PRE&gt;[tLogRow_3] content: select 'phil', 'iter', '20190920', count(1) from staging.traits_phil_iter_20190920_orc&lt;/PRE&gt; 
&lt;P&gt;So it's selecting the elements of the generated table name, and the row count from that table.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;If I run that in a separate Hive SQL client, it works fine and I get something like this:&lt;/P&gt; 
&lt;PRE&gt;phil, iter, 20190920, 2094&lt;/PRE&gt; 
&lt;P&gt;If I run it in a standalone job that just runs that hard coded SQL, I get this:&lt;/P&gt; 
&lt;PRE&gt;.-----------+----+--------+-----.
|           tLogRow_1           |
|=----------+----+--------+----=|
|region_name|type|date    |count|
|=----------+----+--------+----=|
|phil       |iter|20190920|2094 |
'-----------+----+--------+-----'&lt;/PRE&gt; 
&lt;P&gt;However, in the actual job that generates the SQL to create a view, create the table if it does not exist, insert data into it, and then run the count, I get this:&lt;/P&gt; 
&lt;PRE&gt;.-----------+----+--------+-----.
|           tLogRow_7           |
|=----------+----+--------+----=|
|region_name|type|date    |count|
|=----------+----+--------+----=|
|phil       |iter|20190920|null |
'-----------+----+--------+-----'&lt;/PRE&gt; 
&lt;P&gt;So everything works just fine apart from the count(1) returning null! Select count(1) should never ever return null! If the table does not exist, it should fail. If the table exists but is empty, it should return 0. null should be impossible!&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Any suggestions?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The job structure is that I have three iterate links, which in order do three things: create external tables and views and insert, then the select count(1) written into a tHashOutput, and thirdly reads the results of the select count(1) form the tHashOutput and creates a view if there is any data.&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;From this screenshot you can see the tLogRow_3 and tLogRow_7 are either side of the tHiveRow_2 component that runs the SQL, which is just running row6.content.&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="selectcountnull.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M8cK.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/152607i146D2A63AC03655D/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M8cK.png" alt="0683p000009M8cK.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;As you can see, the first iterate executes 4 statements, which are the table and view creation and insert. The second iterate executes 1 statement, which is the count from the table that was inserted into. The final iterate creates a view, but only if the count from the table inserted into is greater than zero. The problem is: I get a null from the count!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 03:56:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-can-a-select-count-1-from-tablename-return-a-null/m-p/2284627#M58277</guid>
      <dc:creator>PhilHibbs</dc:creator>
      <dc:date>2024-11-16T03:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can a select count(1) from tablename return a null?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-can-a-select-count-1-from-tablename-return-a-null/m-p/2284628#M58278</link>
      <description>&lt;P&gt;So here are the relevant componets in more detail:&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="selectcountnull.png" style="width: 454px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M8cP.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/136270i621FCF9222BEEEBD/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M8cP.png" alt="0683p000009M8cP.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="selectcountnull2.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M8cU.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/151762i788163A9E3DA8DA7/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M8cU.png" alt="0683p000009M8cU.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;And the log for the two tLogRow components:&lt;/P&gt; 
&lt;PRE&gt;.------------------------------------------------------------------------------------------+-----------+----+--------.
|                                                     tLogRow_3                                                      |
|=-----------------------------------------------------------------------------------------+-----------+----+-------=|
|content                                                                                   |region_name|type|date    |
|=-----------------------------------------------------------------------------------------+-----------+----+-------=|
|select 'phil', 'full', '20190920', count(1) from `staging`.`traits_phil_full_20190920_orc`|phil       |full|20190920|
'------------------------------------------------------------------------------------------+-----------+----+--------'
.-----------+----+--------+-----.
|           tLogRow_7           |
|=----------+----+--------+----=|
|region_name|type|date    |count|
|=----------+----+--------+----=|
|phil       |full|20190920|null |
'-----------+----+--------+-----'&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2019 14:35:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-can-a-select-count-1-from-tablename-return-a-null/m-p/2284628#M58278</guid>
      <dc:creator>PhilHibbs</dc:creator>
      <dc:date>2019-12-03T14:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: How can a select count(1) from tablename return a null?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-can-a-select-count-1-from-tablename-return-a-null/m-p/2284629#M58279</link>
      <description>&lt;P&gt;Ok, breaking news.. it isn't actually running the query. The output does not depend on the row6.content at all, the tHiveRow_6 component is just passing the variables through from row6 to row8 and setting the count output column to null.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 16:14:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-can-a-select-count-1-from-tablename-return-a-null/m-p/2284629#M58279</guid>
      <dc:creator>PhilHibbs</dc:creator>
      <dc:date>2019-12-03T16:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can a select count(1) from tablename return a null?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-can-a-select-count-1-from-tablename-return-a-null/m-p/2284630#M58280</link>
      <description>&lt;P&gt;I found the problem! It IS running the query, but a tHiveRow component does not return the results of the statement executed, it just runs it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to get the results, you need to drop in a tFlowToIterate and connect that to a tHiveInput.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 09:16:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-can-a-select-count-1-from-tablename-return-a-null/m-p/2284630#M58280</guid>
      <dc:creator>PhilHibbs</dc:creator>
      <dc:date>2019-12-04T09:16:43Z</dc:date>
    </item>
  </channel>
</rss>

