[ 
https://issues.apache.org/jira/browse/HIVE-12941?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15132450#comment-15132450
 ] 

Yongzhi Chen commented on HIVE-12941:
-------------------------------------

>From the behavior of primitive types, null value is lowest priority in getting 
>the min and max values: trying to get the min and max value from non-null 
>values first, only return null when all the values are null. The algorithm 
>treat null value as if largest value for function min and smallest value for 
>max.
But the original min code does not apply the rule recursively for other complex 
types for example struct. It can handle null struct, but not struct with null 
fields {null}. max function works because ,by default, null is treated as 
minimum value for compare function. Attach the patch apply the rule for 
function min too. 


> Unexpected result when using MIN() on struct with NULL in first field
> ---------------------------------------------------------------------
>
>                 Key: HIVE-12941
>                 URL: https://issues.apache.org/jira/browse/HIVE-12941
>             Project: Hive
>          Issue Type: Bug
>          Components: Hive
>    Affects Versions: 1.1.0
>            Reporter: Jan-Erik Hedbom
>            Assignee: Yongzhi Chen
>         Attachments: HIVE-12941.1.patch
>
>
> Using MIN() on struct with NULL in first field of a row yields NULL as result.
> Example:
> select min(a) FROM (select 1 as a union all select 2 as a union all select 
> cast(null as int) as a) tmp;
> OK
> _c0
> 1
> As expected. But if we wrap it in a struct:
> select min(a) FROM (select named_struct("field",1) as a union all select 
> named_struct("field",2) as a union all select named_struct("field",cast(null 
> as int)) as a) tmp;
> OK
> _c0
> NULL
> Using MAX() works as expected for structs.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to