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

James Taylor commented on PHOENIX-2433:
---------------------------------------

Thanks for the patch, [~maghamravikiran]. I agree, use Joda time is the right 
approach, but we only need to use it for week/month/year to save the expense of 
instantiating a Joda time object. The second argument must be a constant, so 
instead of having a switch statement in the execute method (which fires per 
row), we can do something simpler at compile time, creating and return a 
different expression for each of the week/month/year constants from this method 
in RoundDateExpression:
{code}
    public static Expression create(List<Expression> children) throws 
SQLException {
        return new RoundDateExpression(children);
    }
{code}
Just get the timeUnit from the children (as is done in the RoundDateExpression 
constructor), switch on it for WEEK, MONTH, YEAR and have the default call the 
existing RoundDateExpression. Then create a RoundWeekExpression, 
RoundMonthExpression, and RoundYearExpression with the appropriate evaluate 
method. You can likely have a common base class like RoundJodaDateExpression to 
prevent copy/paste of the boiler plate code. Don't forget to add your new 
classes to ExpressionType. 

> support additional time units (like week/month/year) in Trunc() round() and 
> Ceil() 
> -----------------------------------------------------------------------------------
>
>                 Key: PHOENIX-2433
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2433
>             Project: Phoenix
>          Issue Type: Improvement
>            Reporter: noam bulvik
>            Assignee: maghamravikiran
>              Labels: newbie
>         Attachments: PHOENIX-2433-firstdrop.patch
>
>
> currently the time units that are supported in trunk(), round(), ceil are 
> day/hour/minute/seconds/milliseconds. 
> It should support also other values like week, month, year 
> You can see how it is documented for Oracle in  
> http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions201.htm and 
> different supported level in 
> http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions230.htm#i1002084



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

Reply via email to