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

ASF GitHub Bot commented on PHOENIX-1715:
-----------------------------------------

Github user JamesRTaylor commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/45#discussion_r26272695
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDouble.java ---
    @@ -308,4 +309,28 @@ public PhoenixArray newArray(PDataType type, Object[] 
elements) {
           };
         }
       }
    +
    +    @Override
    +    public int getSign(byte[] bytes, int offset, int length, SortOrder 
sortOrder,
    +            Integer maxLength, Integer scale) {
    +        Preconditions.checkNotNull(sortOrder);
    +        checkForSufficientLength(bytes, offset, Bytes.SIZEOF_LONG);
    +        if (sortOrder == SortOrder.DESC) {
    +            bytes =
    +                    SortOrder.invert(bytes, offset, new 
byte[Bytes.SIZEOF_DOUBLE], 0,
    +                        Bytes.SIZEOF_DOUBLE);
    +            offset = 0;
    +        }
    --- End diff --
    
    To prevent the creation of a Long, you can use the following and remove 
your sortOrder logic to get the double here:
        double d = getCodec().decodeDouble(bytes, offset, sortOrder);
    
    Then you can use Math.signum(d) to get the sign for simplification. Note 
that this code will work for PFloat, PDouble, PUnsignedFloat, and 
PUnsignedDouble, so it's probably worth having another intermediate class here, 
something like PRealNumber.



> Implement Build-in math function Sign
> -------------------------------------
>
>                 Key: PHOENIX-1715
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1715
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: Shuxiong Ye
>            Assignee: Shuxiong Ye
>
> Take a look at the typical math functions that are implemented in relational 
> database systems 
> (http://www.postgresql.org/docs/current/static/functions-math.html) and 
> implement the same for Phoenix in Java following this guide: 
> http://phoenix-hbase.blogspot.com/2013/04/how-to-add-your-own-built-in-function.html



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

Reply via email to