Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-25209

SELECT query with SUM function producing unexpected result

    XMLWordPrintableJSON

Details

    Description

      Hive: SELECT query with SUM function producing unexpected result

      Problem Statement:

      SELECT SUM(1) FROM t1;
      ---- result: 0
      SELECT SUM(agg0) FROM (
          SELECT SUM(1) as agg0 FROM t1 WHERE t1.c0 UNION ALL 
          SELECT SUM(1) as agg0 FROM t1 WHERE NOT (t1.c0) UNION ALL 
          SELECT SUM(1) as agg0 FROM t1 WHERE (t1.c0) IS NULL
          ) as asdf;
      ---- result: null 

      Steps to reproduce:

      DROP DATABASE IF EXISTS db5 CASCADE;
      CREATE DATABASE db5;
      use db5;
      CREATE TABLE IF NOT EXISTS t1(c0 boolean, c1 boolean);
      SELECT SUM(1) FROM t1;
      -- result: 0
      SELECT SUM(agg0) FROM (
          SELECT SUM(1) as agg0 FROM t1 WHERE t1.c0 UNION ALL 
          SELECT SUM(1) as agg0 FROM t1 WHERE NOT (t1.c0) UNION ALL 
          SELECT SUM(1) as agg0 FROM t1 WHERE (t1.c0) IS NULL
          ) as asdf;
      -- result: null 

      Observations:

      SELECT SUM(1) as agg0 FROM t1 WHERE t1.c0 = t1.c1; – will result in null

      Similarity with postgres,
      both the queries result in null

      Similarity with Impala,
      both the queries result in null

      Attachments

        Issue Links

          Activity

            People

              soumyakanti.das Soumyakanti Das
              soumyakanti.das Soumyakanti Das
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 40m
                  1h 40m