[ 
https://issues.apache.org/jira/browse/HIVE-26683?focusedWorklogId=830838&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-830838
 ]

ASF GitHub Bot logged work on HIVE-26683:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Dec/22 15:44
            Start Date: 03/Dec/22 15:44
    Worklog Time Spent: 10m 
      Work Description: scarlin-cloudera commented on code in PR #3800:
URL: https://github.com/apache/hive/pull/3800#discussion_r1038800916


##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFSum.java:
##########
@@ -337,29 +345,35 @@ public GenericUDAFEvaluator 
getWindowingEvaluator(WindowFrameDef wFrameDef) {
         return null;
       }
 
-      return new 
GenericUDAFStreamingEvaluator.SumAvgEnhancer<HiveDecimalWritable, HiveDecimal>(
+      return new 
GenericUDAFStreamingEvaluator.SumAvgEnhancer<HiveDecimalWritable, Object[]>(

Review Comment:
   I probably should also add:  We can't just put a NULL in the window because 
of the way the algorithm works.
   
   The sum algorithm keeps track of the running sum total within the window 
that is stored.  The sum of the items in the window is the new running sum 
minus the running total being booted out of the window. So we need an extra 
data structure to hold the NULL value within the window.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 830838)
    Time Spent: 1h 50m  (was: 1h 40m)

> Sum over window produces 0 when row contains null
> -------------------------------------------------
>
>                 Key: HIVE-26683
>                 URL: https://issues.apache.org/jira/browse/HIVE-26683
>             Project: Hive
>          Issue Type: Bug
>          Components: HiveServer2
>            Reporter: Steve Carlin
>            Assignee: Steve Carlin
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> Ran the following sql:
>  
> {code:java}
> create table sum_window_test_small (id int, tinyint_col tinyint);
> insert into sum_window_test_small values (5,5), (10, NULL), (11,1);
> select id,
> tinyint_col,
> sum(tinyint_col) over (order by id nulls last rows between 1 following and 1 
> following)
> from sum_window_test_small order by id;
> select id,
> tinyint_col,
> sum(tinyint_col) over (order by id nulls last rows between current row and 1 
> following)
> from sum_window_test_small order by id;
> {code}
> The result is
> {code:java}
> +-----+--------------+---------------+
> | id  | tinyint_col  | sum_window_0  |
> +-----+--------------+---------------+
> | 5   | 5            | 0             |
> | 10  | NULL         | 1             |
> | 11  | 1            | NULL          |
> +-----+--------------+---------------+{code}
> The first row should have the sum as NULL
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to