[
https://issues.apache.org/jira/browse/HIVE-28302?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Shohei Okumiya updated HIVE-28302:
----------------------------------
Status: Patch Available (was: Open)
> Let SUM UDF return NULL when all rows have non-numeric texts
> ------------------------------------------------------------
>
> Key: HIVE-28302
> URL: https://issues.apache.org/jira/browse/HIVE-28302
> Project: Hive
> Issue Type: Improvement
> Components: UDF
> Affects Versions: 4.0.0
> Reporter: Shohei Okumiya
> Assignee: Shohei Okumiya
> Priority: Major
> Labels: pull-request-available
>
> The ANSI standard says UDAF should return NULL when all inputs are NULL.
> Hive is very generous and accepts non-numeric texts as input for SUM. To give
> some consistency to the generous specification, we believe `SUM(string_col)`
> should behave in the same way as `SUM(CAST(string_col AS DOUBLE))`.
> However, Hive's SUM returns 0.0 in that case.
> {code:java}
> > SELECT SUM(CAST(null AS STRING)), SUM('invalid num'), SUM(CAST('invalid
> > num' AS DOUBLE));
> +-------+------+-------+
> | _c0 | _c1 | _c2 |
> +-------+------+-------+
> | NULL | 0.0 | NULL |
> +-------+------+-------+ {code}
> We see some more discussions in https://github.com/apache/hive/pull/5091.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)