[ https://issues.apache.org/jira/browse/DRILL-8340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17622343#comment-17622343 ]
ASF GitHub Bot commented on DRILL-8340: --------------------------------------- cgivre commented on code in PR #2689: URL: https://github.com/apache/drill/pull/2689#discussion_r1001961723 ########## 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: @jnturton I thought about that. I'm totally open to options for this function. Some background... I have data with inconsistent timestamp formatting... Yes in the ideal world the data would be well formed, but it isn't. 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. I do like the idea of doing the auto option for the existing `TO_TIMESTAMP` function. I'll take a look at the logic for `TO_TIMESTAMP` and see if that is a major headache to extend. > Add Additional Date Manipulation Functions (Part 1) > --------------------------------------------------- > > Key: DRILL-8340 > URL: https://issues.apache.org/jira/browse/DRILL-8340 > Project: Apache Drill > Issue Type: Improvement > Components: Functions - Drill > Affects Versions: 1.20.2 > Reporter: Charles Givre > Assignee: Charles Givre > Priority: Major > Fix For: 2.0.0 > > > This PR adds several utility functions to facilitate working with dates and > times. These are modeled after the date/time functionality in MySQL. > Specifically this adds: > * YEARWEEK(<date>): Returns an int of year week. IE (202002) > * TIME_STAMP(<date string>): Converts most anything that looks like a date > string into a timestamp. -- This message was sent by Atlassian Jira (v8.20.10#820010)