Hi,

While working with C++ client, we found the timestamp data type is kind of
confusing.

When we do the following query:

select localtimestamp from sys.drillbits

SQLline works fine. For the C++ client, I thought we will get the converted
UTC time but it actually returns the UTC time without conversion.

After searching the code, I found the following code for localtimestamp
function here

https://github.com/apache/incubator-drill/blob/master/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java#L295

@FunctionTemplate(name = "localtimestamp",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = NullHandling.NULL_IF_NULL)
    public static class LocalTimeStamp implements DrillSimpleFunc {
        @Workspace long queryStartDate;
        @Output TimeStampHolder out;

        public void setup(RecordBatch incoming) {

            org.joda.time.DateTime now = (new org.joda.time.DateTime(
incoming.getContext().getQueryStartTime()))
.withZoneRetainFields(org.joda.time.DateTimeZone.UTC);
            queryStartDate = now.getMillis();
        }

        public void eval() {
            out.value = queryStartDate;
        }
    }

It seems getQueryStartTime() return a timestamptz value and Drill will
preserve the field value but then use the UTC timezone. So for example, if
we get a timestamp with unix time 0 (that is 1970-01-01T00:00:00Z) and the
drillbit is at PST timezone. Should we expect the "real" value of timestamp
is actually PST time 1970-01-01T00:00:00?  Is that the intended behavior?

Thanks,

Xiao

Reply via email to