<?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: Inconsistency by 1 * (NULL), and causes AnalysisException in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91503#M12262</link>
    <description>&lt;P&gt;I see what you're saying there. The different from Hive isn't deliberate, but I believe this only happens in the very special case when all of the values in the CASE are NULL, without any cast. If any of them have a type, the query will execute. E.g. the below query runs and returns NULL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;select 1 * (CASE WHEN '1' IS NULL THEN NULL ELSE cast(NULL as integer) END);&lt;/PRE&gt;&lt;P&gt;Interestingly postgres behaves the same way as Impala&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;psql (9.5.17, server 9.4.8)
Type "help" for help.

postgres=# select 1 * (CASE WHEN '1' IS NULL THEN NULL ELSE NULL END);
ERROR:  operator does not exist: integer * text
LINE 1: select 1 * (CASE WHEN '1' IS NULL THEN NULL ELSE NULL END);
                 ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
postgres=#  select 1 * (NULL);
 ?column? 
----------
         
(1 row)

postgres=# select 1 * (NULL);
 ?column? 
----------
         
(1 row)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We could probably file a bug if this is causing issues for you, there no specific reason it shouldn't work that I know of.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2019 06:27:34 GMT</pubDate>
    <dc:creator>Tim Armstrong</dc:creator>
    <dc:date>2019-06-12T06:27:34Z</dc:date>
    <item>
      <title>Inconsistency by 1 * (NULL), and causes AnalysisException</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91495#M12261</link>
      <description>&lt;PRE&gt;0: jdbc:hive2://localhost:21050/defalt&amp;gt; select 1 * (NULL);
null
+-------------+--+
| 1 * (null)  |
+-------------+--+
+-------------+--+&lt;/PRE&gt;
&lt;P&gt;vs.&lt;/P&gt;
&lt;PRE&gt;0: jdbc:hive2://localhost:21050/defalt&amp;gt; select 1 * (CASE WHEN '1' IS NULL THEN NULL ELSE NULL END);
Error: AnalysisException: Arithmetic operation requires numeric operands: 1 * (CASE WHEN '1' IS NULL THEN NULL ELSE NULL END) (state=HY000,code=0)&lt;/PRE&gt;
&lt;P&gt;Is this a bug in Impala?&lt;/P&gt;
&lt;P&gt;Impala version is 2.11 (CDH 5.14.4)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same statement works with Hive.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 14:26:33 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91495#M12261</guid>
      <dc:creator>h_o</dc:creator>
      <dc:date>2022-09-16T14:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Inconsistency by 1 * (NULL), and causes AnalysisException</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91503#M12262</link>
      <description>&lt;P&gt;I see what you're saying there. The different from Hive isn't deliberate, but I believe this only happens in the very special case when all of the values in the CASE are NULL, without any cast. If any of them have a type, the query will execute. E.g. the below query runs and returns NULL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;select 1 * (CASE WHEN '1' IS NULL THEN NULL ELSE cast(NULL as integer) END);&lt;/PRE&gt;&lt;P&gt;Interestingly postgres behaves the same way as Impala&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;psql (9.5.17, server 9.4.8)
Type "help" for help.

postgres=# select 1 * (CASE WHEN '1' IS NULL THEN NULL ELSE NULL END);
ERROR:  operator does not exist: integer * text
LINE 1: select 1 * (CASE WHEN '1' IS NULL THEN NULL ELSE NULL END);
                 ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
postgres=#  select 1 * (NULL);
 ?column? 
----------
         
(1 row)

postgres=# select 1 * (NULL);
 ?column? 
----------
         
(1 row)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We could probably file a bug if this is causing issues for you, there no specific reason it shouldn't work that I know of.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 06:27:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91503#M12262</guid>
      <dc:creator>Tim Armstrong</dc:creator>
      <dc:date>2019-06-12T06:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: Inconsistency by 1 * (NULL), and causes AnalysisException</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91504#M12263</link>
      <description>&lt;P&gt;Thank you for your reply, &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/11593"&gt;@Tim Armstrong&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;If Impala doesn't throw Exception by CASE, that would be very nice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But now I found more interesting issue &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Old Impala 2.5 =&amp;gt; No error&lt;/P&gt;&lt;PRE&gt;[root@quickstart ~]# beeline -u "jdbc:hive2://`hostname -f`:21050/;auth=noSasl"
2019-06-12 07:27:40,131 WARN  [main] mapreduce.TableMapReduceUtil: The hbase-prefix-tree module jar containing PrefixTreeCodec is not present.  Continuing without it.
scan complete in 2ms
Connecting to jdbc:hive2://quickstart.cloudera:21050/;auth=noSasl
Connected to: Impala (version 2.5.0-cdh5.7.0)
Driver: Hive JDBC (version 1.1.0-cdh5.7.0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 1.1.0-cdh5.7.0 by Apache Hive
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt; SELECT (-1 * CASE WHEN CAST(
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;    SUM(
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;            CASE when dummy_t.col1 = 1 then dummy_t.col2 else 0 END
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;        ) AS DECIMAL(32, 2)
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt; ) IS NULL THEN NULL WHEN COALESCE(CAST(NULL AS DOUBLE), 0) = 0 THEN NULL ELSE CAST(
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;    CASE WHEN CAST(NULL AS DOUBLE) = 0 THEN NULL ELSE (
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;            CAST(
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;                    SUM(
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;                            CASE when dummy_t.col1 = 1 then dummy_t.col2 else 0 END
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;                        ) AS DECIMAL(32, 2)
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;                ) / CAST(NULL AS DOUBLE)
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;        ) END AS DOUBLE
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt; ) END) FROM (SELECT 1 as col1, 2 as col2) dummy_t;
null
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--+
| (-1 * 1 * case when cast(sum(case when dummy_t.col1 = 1 then dummy_t.col2 else 0 end) as decimal(32,2)) is null then null when coalesce(cast(null as double), 0) = 0 then null else cast(case when cast(null as double) = 0 then null else (cast(sum(case when dummy_t.col1 = 1 then dummy_t.col2 else 0 end) as decimal(32,2)) / cast(null as double)) end as double) end)  |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--+
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--+
No rows selected (0.093 seconds)
0: jdbc:hive2://quickstart.cloudera:21050/&amp;gt;&lt;/PRE&gt;&lt;P&gt;Newer Impala 2.11 and 3.0 doesn't like above:&lt;/P&gt;&lt;PRE&gt;[root@test /]# beeline -u "jdbc:hive2://`hostname -f`:21050/;auth=noSasl"
scan complete in 2ms
Connecting to jdbc:hive2://test.impala.com:21050/;auth=noSasl
Connected to: Impala (version 2.11.0-cdh5.14.4)
Driver: Hive JDBC (version 1.1.0-cdh5.14.4)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 1.1.0-cdh5.14.4 by Apache Hive
0: jdbc:hive2://hadoop-node-01.docker.infra.a&amp;gt; SELECT (-1 * CASE WHEN CAST(
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;    SUM(
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;            CASE when dummy_t.col1 = 1 then dummy_t.col2 else 0 END
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;        ) AS DECIMAL(32, 2)
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt; ) IS NULL THEN NULL WHEN COALESCE(CAST(NULL AS DOUBLE), 0) = 0 THEN NULL ELSE CAST(
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;    CASE WHEN CAST(NULL AS DOUBLE) = 0 THEN NULL ELSE (
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;            CAST(
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;                    SUM(
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;                            CASE when dummy_t.col1 = 1 then dummy_t.col2 else 0 END
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;                        ) AS DECIMAL(32, 2)
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;                ) / CAST(NULL AS DOUBLE)
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt;        ) END AS DOUBLE
. . . . . . . . . . . . . . . . . . . . . . .&amp;gt; ) END) FROM (SELECT 1 as col1, 2 as col2) dummy_t;
Error: AnalysisException: Arithmetic operation requires numeric operands: (-1 * CASE WHEN CAST(sum(CASE WHEN dummy_t.col1 = 1 THEN dummy_t.col2 ELSE 0 END) AS DECIMAL(32,2)) IS NULL THEN NULL ELSE NULL END) (state=HY000,code=0)&lt;/PRE&gt;&lt;P&gt;Did I find a bug this time? &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 07:42:21 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91504#M12263</guid>
      <dc:creator>h_o</dc:creator>
      <dc:date>2019-06-12T07:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Inconsistency by 1 * (NULL), and causes AnalysisException</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91505#M12264</link>
      <description>&lt;P&gt;I mean, the output/result of the following query is different by Impala version:&lt;/P&gt;&lt;PRE&gt;SELECT (-1 * CASE WHEN CAST(
   SUM(
           CASE when dummy_t.col1 = 1 then dummy_t.col2 else 0 END
       ) AS DECIMAL(32, 2)
) IS NULL THEN NULL WHEN COALESCE(CAST(NULL AS DOUBLE), 0) = 0 THEN NULL ELSE CAST(
   CASE WHEN CAST(NULL AS DOUBLE) = 0 THEN NULL ELSE (
           CAST(
                   SUM(
                           CASE when dummy_t.col1 = 1 then dummy_t.col2 else 0 END
                       ) AS DECIMAL(32, 2)
               ) / CAST(NULL AS DOUBLE)
       ) END AS DOUBLE
) END) FROM (SELECT 1 as col1, 2 as col2) dummy_t;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 07:43:02 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91505#M12264</guid>
      <dc:creator>h_o</dc:creator>
      <dc:date>2019-06-12T07:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Inconsistency by 1 * (NULL), and causes AnalysisException</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91534#M12265</link>
      <description>&lt;P&gt;We have made some changes to decimal type resolution behaviour in recent versions. Most of them are controlled by the DECIMAL_V2 option and the default was changed starting in Impala 3.0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The best way forward is to report a bug in the Impala issue tracker -&amp;nbsp;&lt;A href="https://cwiki.apache.org/confluence/display/IMPALA/Contributing+to+Impala" target="_blank"&gt;https://cwiki.apache.org/confluence/display/IMPALA/Contributing+to+Impala&lt;/A&gt;&amp;nbsp;with the steps required to reproduce the symptoms you see. Then it can be tracked and triaged properly. This forum is not great for doing that.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 17:48:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91534#M12265</guid>
      <dc:creator>Tim Armstrong</dc:creator>
      <dc:date>2019-06-12T17:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: Inconsistency by 1 * (NULL), and causes AnalysisException</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91561#M12266</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/11593"&gt;@Tim Armstrong&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I submitted&amp;nbsp;&lt;A href="https://issues.apache.org/jira/browse/IMPALA-8664" target="_blank"&gt;https://issues.apache.org/jira/browse/IMPALA-8664&lt;/A&gt; . Hope it makes sense.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After reading your response, I thought DECIMAL would be the issue, but it seems not.&lt;/P&gt;&lt;P&gt;Using Impala 2.11 (CDH 5.14.4), no DECIMAL, no CAST, but still fails:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;0: jdbc:hive2://test&amp;gt; SELECT (-1 * CASE WHEN SUM(1) IS NULL THEN NULL WHEN COALESCE(NULL, 0) = 0 THEN NULL ELSE 0 END) FROM (SELECT 1 as ytd_id, 2 as derv_alw_amt) dummy_t;&lt;BR /&gt;Error: AnalysisException: Arithmetic operation requires numeric operands: (-1 * CASE WHEN sum(1) IS NULL THEN NULL ELSE NULL END) (state=HY000,code=0)&lt;/PRE&gt;&lt;P&gt;No COALESCE, works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;0: jdbc:hive2://test&amp;gt; SELECT (-1 * CASE WHEN SUM(1) IS NULL THEN NULL WHEN 1 = 0 THEN NULL ELSE 0 END) FROM (SELECT 1 as ytd_id, 2 as derv_alw_amt) dummy_t;
0&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW, because of the inconsistency I mentioned in the first comment, faliing below &lt;STRONG&gt;MAKES SENSE&lt;/STRONG&gt; (because CASE returns NULL):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;0: jdbc:hive2://test&amp;gt; SELECT (-1 * CASE WHEN SUM(1) IS NULL THEN NULL WHEN 0 = 0 THEN NULL ELSE 0 END) FROM (SELECT 1 as ytd_id, 2 as derv_alw_amt) dummy_t;
Error: AnalysisException: Arithmetic operation requires numeric operands: (-1 * CASE WHEN sum(1) IS NULL THEN NULL ELSE NULL END) (state=HY000,code=0)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;HOWEVER&lt;/STRONG&gt;, removing SUM returns different result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;0: jdbc:hive2://test&amp;gt; SELECT (-1 * CASE WHEN COALESCE(NULL, 0) = 0 THEN NULL ELSE 0 END) FROM (SELECT 1 as ytd_id, 2 as derv_alw_amt) dummy_t;
null&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is a bit too confusing for me, and I think this would be an Impala bug.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 01:55:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91561#M12266</guid>
      <dc:creator>h_o</dc:creator>
      <dc:date>2019-06-13T01:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Inconsistency by 1 * (NULL), and causes AnalysisException</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91594#M12267</link>
      <description>&lt;P&gt;Yeah I agree there is some inconsistency in behaviour here - the casting rules, especially around NULL, are too complex and inconsistent.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 17:42:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Inconsistency-by-1-NULL-and-causes-AnalysisException/m-p/91594#M12267</guid>
      <dc:creator>Tim Armstrong</dc:creator>
      <dc:date>2019-06-13T17:42:16Z</dc:date>
    </item>
  </channel>
</rss>

