Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
PhilHibbs
Creator II
Creator II

How can a select count(1) from tablename return a null?

I have a job that is generating and executing SQL on Hive, including generating table names.

 

It populates those tables, and then attempts to get a count from them.

 

The count statement, as shown in the job log, is this:

[tLogRow_3] content: select 'phil', 'iter', '20190920', count(1) from staging.traits_phil_iter_20190920_orc

So it's selecting the elements of the generated table name, and the row count from that table.

 

If I run that in a separate Hive SQL client, it works fine and I get something like this:

phil, iter, 20190920, 2094

If I run it in a standalone job that just runs that hard coded SQL, I get this:

.-----------+----+--------+-----.
|           tLogRow_1           |
|=----------+----+--------+----=|
|region_name|type|date    |count|
|=----------+----+--------+----=|
|phil       |iter|20190920|2094 |
'-----------+----+--------+-----'

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:

.-----------+----+--------+-----.
|           tLogRow_7           |
|=----------+----+--------+----=|
|region_name|type|date    |count|
|=----------+----+--------+----=|
|phil       |iter|20190920|null |
'-----------+----+--------+-----'

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!

 

Any suggestions?

 

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. 

 

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.

0683p000009M8cK.png

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!

Labels (2)
1 Solution

Accepted Solutions
PhilHibbs
Creator II
Creator II
Author

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.

 

In order to get the results, you need to drop in a tFlowToIterate and connect that to a tHiveInput.

View solution in original post

3 Replies
PhilHibbs
Creator II
Creator II
Author

So here are the relevant componets in more detail:

0683p000009M8cP.png0683p000009M8cU.png

And the log for the two tLogRow components:

.------------------------------------------------------------------------------------------+-----------+----+--------.
|                                                     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 |
'-----------+----+--------+-----'
PhilHibbs
Creator II
Creator II
Author

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.

PhilHibbs
Creator II
Creator II
Author

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.

 

In order to get the results, you need to drop in a tFlowToIterate and connect that to a tHiveInput.