[
https://issues.apache.org/jira/browse/PHOENIX-1704?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14361283#comment-14361283
]
James Taylor commented on PHOENIX-1704:
---------------------------------------
Thanks for the patch [~ayingshu]. It's looking good. Here's some feedback:
- remove YearParseNode and the nodeClass attribute in your YearFunction as it's
not required.
- remove PDate.class from allowedTypes as dates are coercible to Timestamp so
are automatically allowed.
- don't call evaluateExpression in your evaluate as it's not necessary and
would cause the byte[] to be copied which isn't necessary. Also, only return
false if the child cannot be evaluated. Something like this instead:
{code}
+ if (!expression.evaluate(tuple, ptr)) {
+ return false; // means could not evaluate due to lack of
information
+ }
+ if (ptr.getLength() == 0) {
+ return true; // means null
+ }
+ long dateTime= PLong.INSTANCE.getCodec().decodeLong(ptr,
expression.getSortOrder());
{code}
- use Joda DateTime instead of Calendar as performance will be better.
Something like:
{code}
DateTime dt = new DateTime(dateTime);
int year = dt.getYear();
{code}
- minor, but if you declare your test function to return an int instead of
Integer, all of those casts can be removed:
{code}
+ private static int callYearFunction(Connection conn, String invocation)
throws SQLException {
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery(String.format("SELECT %s FROM
SYSTEM.CATALOG LIMIT 1", invocation));
+ assertTrue(rs.next());
+ int returnValue = rs.getInt();
+ assertFalse(rs.next());
+ rs.close();
+ return returnValue;
+ }
{code}
- Write at least one unit test that uses YEAR in a WHERE clause as that tests
pushing the function to the server and running it as a filter.
> 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
>
>
> Support Year() with date and timestamp.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)