[
https://issues.apache.org/jira/browse/IMPALA-15013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18089057#comment-18089057
]
ASF subversion and git services commented on IMPALA-15013:
----------------------------------------------------------
Commit f4a82dc1c26daa7f26c3c1a8d5b9c222bfb4085f in impala's branch
refs/heads/master from Xuebin Su
[ https://gitbox.apache.org/repos/asf?p=impala.git;h=f4a82dc1c ]
IMPALA-15013: Fix NULL issues for PIVOT
Previously, the PIVOT operation returned NULL instead of 0 for `count()`
when no row matches the value. This was because the `aggif()` function
it used returns NULL when its predicate is never satisfied.
This patch fixes the issue by adding a `ifnull()` call on the output of
`aggif()` so that a non-NULL value can be returned based on the return
type of the original aggregate function. For `count()`, 0 will be
returned in this case since its return type is BIGINT.
To support specifying the NULL literal in the PIVOT clause, this patch
changes to using the `IsNullPredicate` instead of the `BinaryPredicate`
in the `aggif()` calls.
This patch also changes `returnsNonNullOnEmpty` to true when creating
the `aggif()` and the `appx_median()` functions to match the actual
behavior.
Testing:
- Added E2E tests for NULL cases.
- Added AnalyzeStmtsTests for unsupported aggregate functions.
Change-Id: Idae4a510dd3d6c4cd16a3e03aa0161ad84863e5a
Reviewed-on: http://gerrit.cloudera.org:8080/24325
Reviewed-by: Impala Public Jenkins <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
> PIVOT returns incorrect result for count() when no row matches the value
> ------------------------------------------------------------------------
>
> Key: IMPALA-15013
> URL: https://issues.apache.org/jira/browse/IMPALA-15013
> Project: IMPALA
> Issue Type: Bug
> Reporter: Xuebin Su
> Assignee: Xuebin Su
> Priority: Critical
>
> The result of the following query is incorrect:
> {code:java}
> [localhost:21050] default> with t1(a, b) as (
> values (1, null), (2, null)
> )
> select * from t1 pivot (
> count(a) as c for b in (2 as v2, 4 as v4)
> ) as t;
> +---+------+------+
> | a | v2 | v4 |
> +---+------+------+
> | 1 | NULL | NULL |
> | 2 | NULL | NULL |
> +---+------+------+
> Fetched 2 row(s) in 0.11s {code}
> while the expected result is
> {code:java}
> +---+----+----+
> | a | v2 | v4 |
> +---+----+----+
> | 1 | 0 | 0 |
> | 2 | 0 | 0 |
> +---+----+----+ {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]