[
https://issues.apache.org/jira/browse/DRILL-7926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17398575#comment-17398575
]
ASF GitHub Bot commented on DRILL-7926:
---------------------------------------
dzamo commented on a change in pull request #2284:
URL: https://github.com/apache/drill/pull/2284#discussion_r688407522
##########
File path:
exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/AgeFunction.java
##########
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+<@pp.dropOutputFile />
+<#assign className="GAge"/>
+
+<@pp.changeOutputFile
name="/org/apache/drill/exec/expr/fn/impl/${className}.java"/>
+
+<#include "/@includes/license.ftl"/>
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import javax.inject.Inject;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.*;
+import org.apache.drill.exec.record.RecordBatch;
+import org.apache.drill.exec.ops.ContextInformation;
+
+/*
+ * This class is generated using freemarker and the ${.template_name} template.
+ */
+
+public class ${className} {
+
+<#list dateIntervalFunc.dates as fromUnit>
+<#list dateIntervalFunc.dates as toUnit>
+
+ @FunctionTemplate(name = "age",
+ scope = FunctionTemplate.FunctionScope.SIMPLE,
+ nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+ public static class Age${fromUnit}To${toUnit} implements DrillSimpleFunc {
+
+ @Param ${toUnit}Holder left;
+ @Param ${fromUnit}Holder right;
+ @Output IntervalHolder out;
+
+ public void setup() {
+ }
+
+ public void eval() {
+ java.time.LocalDateTime from =
java.time.Instant.ofEpochMilli(right.value).atZone(java.time.ZoneOffset.UTC).toLocalDateTime();
+ java.time.LocalDateTime to =
java.time.Instant.ofEpochMilli(left.value).atZone(java.time.ZoneOffset.UTC).toLocalDateTime();
+
+ long months = from.until(to, java.time.temporal.ChronoUnit.MONTHS);
+ from = from.plusMonths(months);
+ long days = from.until(to, java.time.temporal.ChronoUnit.DAYS);
+ from = from.plusDays(days);
+ long millis = from.until(to, java.time.temporal.ChronoUnit.MILLIS);
+
+ out.months = (int) months;
+ out.days = (int) days;
+ out.milliseconds = (int) millis;
+ }
+ }
+</#list>
+ @FunctionTemplate(name = "age",
+ scope = FunctionTemplate.FunctionScope.SIMPLE,
+ nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+ public static class Age${fromUnit}ToMidnight implements DrillSimpleFunc {
+
+ @Param ${fromUnit}Holder right;
+ @Workspace java.time.LocalDateTime to;
+ @Output IntervalHolder out;
+ @Inject ContextInformation contextInfo;
+
+ public void setup() {
+ java.time.ZoneId zoneId = contextInfo.getRootFragmentTimeZone();
+ java.time.ZonedDateTime zdtStart =
contextInfo.getQueryStartInstant().atZone(zoneId);
+ to =
zdtStart.truncatedTo(java.time.temporal.ChronoUnit.DAYS).toLocalDateTime();
+ }
+
+ public void eval() {
+ java.time.LocalDateTime from =
java.time.Instant.ofEpochMilli(right.value).atZone(java.time.ZoneOffset.UTC).toLocalDateTime();
Review comment:
The _query start time_ higher up is indeed a real Unix timestamp, and
converted to a LocalDateTime differently. In the excerpted lines we've got
another instance of a Drill timestamp in ms since the "local epoch" and the
same date code pattern described in my earlier comment...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
> The " age " function is not working properly.
> ---------------------------------------------
>
> Key: DRILL-7926
> URL: https://issues.apache.org/jira/browse/DRILL-7926
> Project: Apache Drill
> Issue Type: Bug
> Components: Functions - Drill
> Affects Versions: 1.17.0, 1.18.0
> Reporter: Александр Глухов
> Priority: Blocker
> Attachments: image-2021-05-13-16-17-21-154.png, screenshot-1.png,
> screenshot-2.png
>
>
> The " age " function is not working properly.
> *Playback steps*
> {code:sql}
> select extract(year from m. "years") `years` from (select age('2021-05-13',
> '2007-07-02') `years") m{code}
> *Expected result* 13.
> *Actual result* 14.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)