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

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_r26272833
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/schema/types/PInteger.java ---
    @@ -272,4 +273,10 @@ public PhoenixArray newArray(PDataType type, Object[] 
elements) {
           };
         }
       }
    +
    +  @Override
    +  public int getSign(byte[] bytes, int offset, int length, SortOrder 
sortOrder,
    +          Integer maxLength, Integer scale) {
    +      return SignUtils.getSignForSignedInteger(bytes, offset, length, 
sortOrder, Bytes.SIZEOF_INT);
    --- End diff --
    
    Same idea here. Create an intermediate class, called PWholeNumber or 
PWholeNumeric and derive PLong, PInteger, PShort, PByte and all the unsigned 
variations from this one. Then you can do something like this:
    
        long l = getCodec().decodeLong(bytes, offset, sortOrder);
        return l == 0 ? 0 : l < 0 ? -1 : 1; // Or maybe a mask of the most 
significant bit is better?



> 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