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

James Taylor commented on PHOENIX-1704:
---------------------------------------

Thanks for the revisions, [~ayingshu]. Here's some feedback:
- You don't need to check the PDataType in your evaluate method (though there's 
a bug I see in PUnignedTimestamp that needs to be fixed -- see below).  
Instead, just do this:
{code}
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression expression = getExpression();
+        if (!expression.evaluate(tuple, ptr)) {
+            return false;
+        }
+        if ( ptr.getLength() == 0) {
+            return true; //means null
+        }
+        long dateTime = expression.getDataType().decodeLong(ptr, 
expression.getSortOrder());
+        DateTime dt = new DateTime(dateTime);
+        int year = dt.getYear();
+        PDataType returnType = getDataType();
+        byte[] byteValue = new byte[returnType.getByteSize()];
+        returnType.getCodec().encodeInt(year, byteValue, 0);
+        ptr.set(byteValue);
+        return true;
+    }
+
{code}
- PUnsignedTimestamp should define its codec (4th argument to the super 
constructor currently null) as new PUnsignedDate.UnsignedDateCodec(), like this:
{code}
  private PUnsignedTimestamp() {
    super("UNSIGNED_TIMESTAMP", 20, java.sql.Timestamp.class, new 
PUnsignedDate.UnsignedDateCodec(), 12);
  }
{code}

> Add year() built-in function
> ----------------------------
>
>                 Key: PHOENIX-1704
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1704
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Alicia Ying Shu
>            Assignee: Alicia Ying Shu
>         Attachments: Phoenix-1704-v1.patch, Phoenix-1704-v2.patch, 
> Phoenix-1704-v3.patch, Phoenix-1704-v4.patch
>
>
> Support Year() with date and timestamp.



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

Reply via email to