jnturton commented on code in PR #2689:
URL: https://github.com/apache/drill/pull/2689#discussion_r1002900480


##########
contrib/udfs/src/main/java/org/apache/drill/exec/udfs/DateFunctions.java:
##########
@@ -140,8 +143,77 @@ public void eval() {
       java.time.format.DateTimeFormatter formatter = 
java.time.format.DateTimeFormatter.ofPattern(format);
       java.time.LocalDateTime dateTime = 
java.time.LocalDateTime.parse(inputDate, formatter);
 
-      java.time.LocalDateTime td = 
org.apache.drill.exec.udfs.NearestDateUtils.getDate(dateTime, intervalString);
+      java.time.LocalDateTime td = DateConversionUtils.getDate(dateTime, 
intervalString);
       out.value = 
td.atZone(java.time.ZoneId.of("UTC")).toInstant().toEpochMilli();
     }
   }
+
+  @FunctionTemplate(names = {"yearweek","year_week"},
+    scope = FunctionTemplate.FunctionScope.SIMPLE,
+    nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class YearWeekFunction implements DrillSimpleFunc {
+    @Param
+    VarCharHolder inputHolder;
+
+    @Output
+    IntHolder out;
+
+    @Override
+    public void setup() {
+      // noop
+    }
+
+    @Override
+    public void eval() {
+      String input = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputHolder.start,
 inputHolder.end, inputHolder.buffer);
+      java.time.LocalDateTime dt = 
org.apache.drill.exec.udfs.DateUtilFunctions.getTimestampFromString(input);
+      int week = dt.get(java.time.temporal.IsoFields.WEEK_OF_WEEK_BASED_YEAR);
+      int year = dt.getYear();
+      out.value = (year * 100) + week;
+    }
+  }
+
+  @FunctionTemplate(names = {"yearweek","year_week"},
+    scope = FunctionTemplate.FunctionScope.SIMPLE,
+    nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class YearWeekFromDateFunction implements DrillSimpleFunc {
+    @Param
+    DateHolder inputHolder;
+
+    @Output
+    IntHolder out;
+
+    @Override
+    public void setup() {
+      // noop
+    }
+
+    @Override
+    public void eval() {
+      out.value = 
org.apache.drill.exec.udfs.DateUtilFunctions.getYearWeek(inputHolder.value);
+    }
+  }
+
+  @FunctionTemplate(names = {"time_stamp", "timestamp"},

Review Comment:
   > I was modeling the function names after MySQL which has a timestamp and 
date functions which take a string as input and return the respective data 
converted into a temporal format. This way a user of MySQL wouldn't have to 
look up new function names.
   
   Yes I do see, and support, the intent but only up to the point that the 
names chosen by the system inspiring the functions plug harmoniously into what 
we have. `time_stamp` is a spelling that is foreign to Drill (and to ANSI SQL) 
and Drill already does something else with `timestamp` today:
   
   ```
   apache drill> select `timestamp`('1970-01-01');
   EXPR$0  1970-01-01 00:00:00.0
   
   1 row selected (1.969 seconds)
   ```
   
   Like you say, if `to_timestamp(date_str, 'auto')` doesn't turn that 
implementation into a monstrosity then maybe that's going to be the nicest 
option here. Hopefully your Util class could be used to prevent the eval method 
from growing very long...



-- 
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: dev-unsubscr...@drill.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to