<?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 IllegalStateException during insert into table in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/IllegalStateException-during-insert-into-table/m-p/45889#M42613</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I am inserting a result of simple aggregation and my query fails when the result of the aggregation is an empty record set. The results are inserted into a partitioned table. The insert fails with this message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: IllegalStateException: null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The query which should prepare the data is containing aggregations. I thought the error is because the query does not return any row, but if I change the subquery from GROUP by to a simple select, then it works, and Inserts 0 rows.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;create table tmp.tab (&lt;BR /&gt;file_name string,&lt;BR /&gt;rc int&lt;BR /&gt;) partitioned by ( day_id int ) stored as parquet;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-- this fails:&lt;/P&gt;&lt;P&gt;insert into tmp.tab partition (day_id)&lt;BR /&gt;select t.fn, cast( t.ROW_COUNT as int ), cast(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') as int) as DAY_ID&lt;BR /&gt;from ( select count(*) as row_count, max( file_name ) as fn from tmp.tab group by file_name ) t;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-- this works:&lt;/P&gt;&lt;P&gt;insert into tmp.tab partition (day_id)&lt;BR /&gt;select t.fn, cast( t.ROW_COUNT as int ), cast(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') as int) as DAY_ID&lt;BR /&gt;from ( select rc as ROW_COUNT, file_name as fn from tmp.tab ) t;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using Impala&amp;nbsp; 2.2.0-cdh5.4.8&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tomas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 10:43:11 GMT</pubDate>
    <dc:creator>Tomas79</dc:creator>
    <dc:date>2022-09-16T10:43:11Z</dc:date>
    <item>
      <title>IllegalStateException during insert into table</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/IllegalStateException-during-insert-into-table/m-p/45889#M42613</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I am inserting a result of simple aggregation and my query fails when the result of the aggregation is an empty record set. The results are inserted into a partitioned table. The insert fails with this message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: IllegalStateException: null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The query which should prepare the data is containing aggregations. I thought the error is because the query does not return any row, but if I change the subquery from GROUP by to a simple select, then it works, and Inserts 0 rows.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;create table tmp.tab (&lt;BR /&gt;file_name string,&lt;BR /&gt;rc int&lt;BR /&gt;) partitioned by ( day_id int ) stored as parquet;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-- this fails:&lt;/P&gt;&lt;P&gt;insert into tmp.tab partition (day_id)&lt;BR /&gt;select t.fn, cast( t.ROW_COUNT as int ), cast(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') as int) as DAY_ID&lt;BR /&gt;from ( select count(*) as row_count, max( file_name ) as fn from tmp.tab group by file_name ) t;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-- this works:&lt;/P&gt;&lt;P&gt;insert into tmp.tab partition (day_id)&lt;BR /&gt;select t.fn, cast( t.ROW_COUNT as int ), cast(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') as int) as DAY_ID&lt;BR /&gt;from ( select rc as ROW_COUNT, file_name as fn from tmp.tab ) t;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using Impala&amp;nbsp; 2.2.0-cdh5.4.8&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tomas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 10:43:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/IllegalStateException-during-insert-into-table/m-p/45889#M42613</guid>
      <dc:creator>Tomas79</dc:creator>
      <dc:date>2022-09-16T10:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: IllegalStateException during insert into table</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/IllegalStateException-during-insert-into-table/m-p/45951#M42614</link>
      <description>&lt;P&gt;Update:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the explain function on the problematic query fails:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;explain insert into tmp.tab partition (day_id)
select t.fn, cast( t.ROW_COUNT as int ), cast(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') as int) as DAY_ID
from ( select count(*) as row_count, max( file_name ) as fn from tmp.tab group by file_name ) t;
Query: explain insert into tmp.tab partition (day_id)
select t.fn, cast( t.ROW_COUNT as int ), cast(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') as int) as DAY_ID
from ( select count(*) as row_count, max( file_name ) as fn from tmp.tab group by file_name ) t
ERROR: IllegalStateException: null&lt;/PRE&gt;&lt;P&gt;but the explain on the working query suceeds:&lt;/P&gt;&lt;PRE&gt;explain insert into tmp.tab partition (day_id)
                  &amp;gt; select t.fn, cast( t.ROW_COUNT as int ), cast(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') as int) as DAY_ID
                  &amp;gt; from ( select rc as ROW_COUNT, file_name as fn from tmp.tab ) t;
Query: explain insert into tmp.tab partition (day_id)
select t.fn, cast( t.ROW_COUNT as int ), cast(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') as int) as DAY_ID
from ( select rc as ROW_COUNT, file_name as fn from tmp.tab ) t
+--------------------------------------------------------------------------------------------------------------------------+
| Explain String                                                                                                           |
+--------------------------------------------------------------------------------------------------------------------------+
| WARNING: The following tables are missing relevant table and/or column statistics.                                       |
| tmp.tab                                                                                                                  |
|                                                                                                                          |
| WRITE TO HDFS [tmp.tab, OVERWRITE=false, PARTITION-KEYS=(CAST(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') AS INT))] |
| |  partitions=1                                                                                                          |
| |                                                                                                                        |
| 00:SCAN HDFS [tmp.tab]                                                                                                   |
|    partitions=0/0 files=0 size=0B                                                                                        |
+--------------------------------------------------------------------------------------------------------------------------+
Fetched 8 row(s) in 0.03s&lt;/PRE&gt;&lt;P&gt;I noticed the warning about missing stats on empty table, so I did compute stats on tm,p.tab&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This helped, so the problem is solved!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Query: explain insert into tmp.tab partition (day_id)
select t.fn, cast( t.ROW_COUNT as int ), cast(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') as int) as DAY_ID
from ( select count(*) as row_count, max( file_name ) as fn from tmp.tab group by file_name ) t
+--------------------------------------------------------------------------------------------------------------------------+
| Explain String                                                                                                           |
+--------------------------------------------------------------------------------------------------------------------------+
| Estimated Per-Host Requirements: Memory=0B VCores=0                                                                      |
|                                                                                                                          |
| WRITE TO HDFS [tmp.tab, OVERWRITE=false, PARTITION-KEYS=(CAST(from_unixtime(unix_timestamp(now()), 'yyyyMMdd') AS INT))] |
| |  partitions=1                                                                                                          |
| |                                                                                                                        |
| 01:AGGREGATE [FINALIZE]                                                                                                  |
| |  output: count(*), max(file_name)                                                                                      |
| |  group by: file_name                                                                                                   |
| |                                                                                                                        |
| 00:SCAN HDFS [tmp.tab]                                                                                                   |
|    partitions=0/0 files=0 size=0B                                                                                        |
+--------------------------------------------------------------------------------------------------------------------------+
Fetched 11 row(s) in 0.03s&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Oct 2016 09:34:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/IllegalStateException-during-insert-into-table/m-p/45951#M42614</guid>
      <dc:creator>Tomas79</dc:creator>
      <dc:date>2016-10-05T09:34:29Z</dc:date>
    </item>
  </channel>
</rss>

