You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "James Taylor (JIRA)" <ji...@apache.org> on 2017/06/15 22:09:00 UTC

[jira] [Commented] (PHOENIX-3940) NullPointerException on PERCENTILE_CONT over an empty result set

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

James Taylor commented on PHOENIX-3940:
---------------------------------------

Thanks for the patch, [~elserj]. I'd recommend setting ptr to an empty byte array and returning true. The client-side aggregators would always return true.  Something like this:
{code}
             double result = 0.0;
             Number n1 = (Number)o1;
-            if (o2 == null || o1 == o2) {
+            if (o1 == null && o2 == null) {
+                ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
+                return true;
+            } else if (o2 == null || o1 == o2) {
                 result = n1.doubleValue();
             } else {
                 Number n2 = (Number)o2;
{code}
Longer explanation of returning true versus false here: https://issues.apache.org/jira/browse/PHOENIX-3918?focusedCommentId=16043672&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-16043672. Since there aren't any child expressions for client-side aggregators and we essentially have all the information we'll ever have from the server, we can always calculate a value (which might be null), so we always return true.

> NullPointerException on PERCENTILE_CONT over an empty result set
> ----------------------------------------------------------------
>
>                 Key: PHOENIX-3940
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-3940
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Josh Elser
>            Assignee: Josh Elser
>            Priority: Minor
>             Fix For: 4.12.0
>
>         Attachments: PHOENIX-3940.001.patch
>
>
> A user reported that when running a query with {{PERCENTILE_CONT}} where the selection has no results (e.g. nothing to compute the P_C on), a NullPointerException is thrown.
> Glancing at the code, it can handle the case where there is only one value, but handling the case where there are no values fails.
> Reading over Oracle and SqlServer docs, it doesn't saw what "should" happen in these cases. Is "0" a sane value? Or is an exception actually a good idea?
> https://docs.microsoft.com/en-us/sql/t-sql/functions/percentile-cont-transact-sql
> https://docs.oracle.com/cd/B28359_01/server.111/b28286/functions115.htm#SQLRF00687



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)