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

    https://github.com/apache/incubator-drill/pull/52#discussion_r12215926
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
 ---
    @@ -201,125 +210,96 @@ public void eval() {
             }
         }
     
    -    @FunctionTemplate(names = {"date_add", "add"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
    -    public static class DateIntervalAdd implements DrillSimpleFunc{
    -
    -        @Param DateHolder dateType;
    -        @Param IntervalHolder intervalType;
    +    @FunctionTemplate(name = "current_date", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
    +    public static class CurrentDate implements DrillSimpleFunc {
    +        @Workspace long queryStartDate;
             @Output DateHolder out;
     
    -        public void setup(RecordBatch b){}
    -
    -        public void eval(){
    -
    -            org.joda.time.MutableDateTime temp = new 
org.joda.time.MutableDateTime(dateType.value, org.joda.time.DateTimeZone.UTC);
    -            temp.addMonths(intervalType.months);
    -            temp.addDays(intervalType.days);
    -            temp.add(intervalType.milliSeconds);
    +        public void setup(RecordBatch incoming) {
     
    -            out.value = temp.getMillis();
    +            org.joda.time.DateTime now = new 
org.joda.time.DateTime(incoming.getContext().getQueryStartTime());
    +            queryStartDate = (new 
org.joda.time.DateMidnight(now.getYear(), now.getMonthOfYear(), 
now.getDayOfMonth(), org.joda.time.DateTimeZone.UTC)).getMillis();
             }
    -    }
    -
    -    @FunctionTemplate(names = {"date_add", "add"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
    -    public static class IntervalDateAdd implements DrillSimpleFunc{
     
    -        @Param IntervalHolder intervalType;
    -        @Param DateHolder dateType;
    -        @Output DateHolder out;
    -
    -        public void setup(RecordBatch b){}
    -
    -        public void eval(){
    -
    -            org.joda.time.MutableDateTime temp = new 
org.joda.time.MutableDateTime(dateType.value, org.joda.time.DateTimeZone.UTC);
    -            temp.addMonths(intervalType.months);
    -            temp.addDays(intervalType.days);
    -            temp.add(intervalType.milliSeconds);
    -
    -            out.value = temp.getMillis();
    +        public void eval() {
    +            out.value = queryStartDate;
             }
    -    }
    -
    -
    -    @FunctionTemplate(names = {"date_sub", "subtract"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
    -    public static class DateIntervalSub implements DrillSimpleFunc{
    -
    -        @Param DateHolder dateType;
    -        @Param IntervalHolder intervalType;
    -        @Output DateHolder out;
     
    -        public void setup(RecordBatch b){}
    +    }
     
    -        public void eval(){
    +    @FunctionTemplate(names = {"current_timestamp", "now"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
    +    public static class CurrentTimeStamp implements DrillSimpleFunc {
    +        @Workspace long queryStartDate;
    +        @Workspace int timezoneIndex;
    +        @Output TimeStampTZHolder out;
     
    -            org.joda.time.MutableDateTime temp = new 
org.joda.time.MutableDateTime(dateType.value, org.joda.time.DateTimeZone.UTC);
    -            temp.addMonths(intervalType.months * -1);
    -            temp.addDays(intervalType.days * -1);
    -            temp.add(intervalType.milliSeconds * -1);
    +        public void setup(RecordBatch incoming) {
     
    -            out.value = temp.getMillis();
    +            org.joda.time.DateTime now = new 
org.joda.time.DateTime(incoming.getContext().getQueryStartTime());
    +            queryStartDate = now.getMillis();
    +            timezoneIndex = 
org.apache.drill.exec.expr.fn.impl.DateUtility.getIndex(now.getZone().toString());
             }
    -    }
    -
    -    @FunctionTemplate(names = {"date_sub", "subtract"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
    -    public static class IntervalDateSub implements DrillSimpleFunc{
     
    -        @Param IntervalHolder intervalType;
    -        @Param DateHolder dateType;
    -        @Output DateHolder out;
    +        public void eval() {
    +            out.value = queryStartDate;
    +            out.index = timezoneIndex;
    +        }
     
    -        public void setup(RecordBatch b){}
    +    }
     
    -        public void eval(){
    +    @FunctionTemplate(name = "clock_timestamp", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL, 
isRandom = true)
    +    public static class ClockTimeStamp implements DrillSimpleFunc {
    +        @Workspace int timezoneIndex;
    +        @Output TimeStampTZHolder out;
     
    -            org.joda.time.MutableDateTime temp = new 
org.joda.time.MutableDateTime(dateType.value, org.joda.time.DateTimeZone.UTC);
    -            temp.addMonths(intervalType.months * -1);
    -            temp.addDays(intervalType.days * -1);
    -            temp.add(intervalType.milliSeconds * -1);
    +        public void setup(RecordBatch incoming) {
    +            org.joda.time.DateTime now = new org.joda.time.DateTime();
    +            timezoneIndex = 
org.apache.drill.exec.expr.fn.impl.DateUtility.getIndex(now.getZone().toString());
    +        }
     
    -            out.value = temp.getMillis();
    +        public void eval() {
    +            org.joda.time.DateTime now = new org.joda.time.DateTime();
    +            out.value = now.getMillis();
    +            out.index = timezoneIndex;
             }
         }
     
    -    @FunctionTemplate(name = "current_date", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
    -    public static class CurrentDate implements DrillSimpleFunc {
    -        @Workspace long queryStartDate;
    -        @Output DateHolder out;
    +    @FunctionTemplate(name = "timeofday", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL, 
isRandom = true)
    +    public static class TimeOfDay implements DrillSimpleFunc {
    +        @Workspace ByteBuf buffer;
    +        @Output VarCharHolder out;
     
             public void setup(RecordBatch incoming) {
    -
    -            org.joda.time.DateTime now = new 
org.joda.time.DateTime(incoming.getContext().getQueryStartTime());
    -            queryStartDate = (new 
org.joda.time.DateMidnight(now.getYear(), now.getMonthOfYear(), 
now.getDayOfMonth(), org.joda.time.DateTimeZone.UTC)).getMillis();
    +            buffer = io.netty.buffer.Unpooled.wrappedBuffer(new byte[100]);
             }
     
             public void eval() {
    -            out.value = queryStartDate;
    +            org.joda.time.DateTime temp = new org.joda.time.DateTime();
    +            String str = 
org.apache.drill.exec.expr.fn.impl.DateUtility.formatTimeStampTZ.print(temp);
    +            out.buffer = buffer;
    +            out.start = 0;
    +            out.end = Math.min(100,  str.length()); // truncate if target 
type has length smaller than that of input's string
    +            out.buffer.setBytes(0, str.substring(0,out.end).getBytes());
             }
    -
         }
     
    -    @FunctionTemplate(name = "current_timestamptz", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
    -    public static class CurrentTimeStampTZ implements DrillSimpleFunc {
    +    @FunctionTemplate(name = "localtimestamp", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
    +    public static class LocalTimeStamp implements DrillSimpleFunc {
             @Workspace long queryStartDate;
    -        @Workspace int timezoneIndex;
    -        @Output TimeStampTZHolder out;
    +        @Output TimeStampHolder out;
     
             public void setup(RecordBatch incoming) {
     
    -            org.joda.time.DateTime now = new 
org.joda.time.DateTime(incoming.getContext().getQueryStartTime());
    +            org.joda.time.DateTime now = (new 
org.joda.time.DateTime(incoming.getContext().getQueryStartTime())).withZoneRetainFields(org.joda.time.DateTimeZone.UTC);
                 queryStartDate = now.getMillis();
    -            timezoneIndex = 
org.apache.drill.exec.expr.fn.impl.DateUtility.getIndex(now.getZone().toString());
             }
     
             public void eval() {
                 out.value = queryStartDate;
    -            out.index = timezoneIndex;
             }
    -
         }
     
    -    @FunctionTemplate(name = "current_time", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
    +    @FunctionTemplate(names = {"current_time", "localtime"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
    --- End diff --
    
    CURRENT_TIMESTAMP and LOCALTIMESTAMP follow the above convention where the 
former returns TIMESTAMPTZ and latter returns TIMESTAMP.
    
    However since we don't support TIME with time zone we cannot make that 
distinction in the case of CURRENT_TIME vs LOCALTIME


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to