arina-ielchiieva commented on a change in pull request #1680: Drill-7077: Add 
Function to Facilitate Time Series Analysis
URL: https://github.com/apache/drill/pull/1680#discussion_r263478933
 
 

 ##########
 File path: 
contrib/udfs/src/main/java/org/apache/drill/exec/udfs/NearestDateUtils.java
 ##########
 @@ -46,81 +55,88 @@
     int hour = d.getHour();
     int minute = d.getMinute();
     int second = d.getSecond();
-    switch (timeInterval.valueOf(interval.toUpperCase())) {
-      case YEAR:
-        newDate = java.time.LocalDateTime.of(year, 1, 1, 0, 0, 0);
-        break;
-      case QUARTER:
-        newDate = java.time.LocalDateTime.of(year, (month / 3) * 3 + 1, 1, 0, 
0, 0);
-        break;
-      case MONTH:
-        newDate = java.time.LocalDateTime.of(year, month, 1, 0, 0, 0);
-        break;
-      case WEEK_SUNDAY:
-        newDate = 
newDate.with(java.time.temporal.TemporalAdjusters.previousOrSame(java.time.DayOfWeek.SUNDAY))
-                .truncatedTo(ChronoUnit.DAYS);
-        break;
-      case WEEK_MONDAY:
-        newDate = 
newDate.with(java.time.temporal.TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY))
-                .truncatedTo(ChronoUnit.DAYS);
-        break;
-      case DAY:
-        newDate = java.time.LocalDateTime.of(year, month, day, 0, 0, 0);
-        break;
-      case HOUR:
-        newDate = java.time.LocalDateTime.of(year, month, day, hour, 0, 0);
-        break;
-      case HALF_HOUR:
-        if (minute >= 30) {
-          minute = 30;
-        } else {
-          minute = 0;
-        }
-        newDate = java.time.LocalDateTime.of(year, month, day, hour, minute, 
0);
-        break;
-      case QUARTER_HOUR:
-        if (minute >= 45) {
-          minute = 45;
-        } else if (minute >= 30) {
-          minute = 30;
-        } else if (minute >= 15) {
-          minute = 15;
-        } else {
-          minute = 0;
-        }
-        newDate = java.time.LocalDateTime.of(year, month, day, hour, minute, 
0);
-        break;
-      case MINUTE:
-        newDate = java.time.LocalDateTime.of(year, month, day, hour, minute, 
0);
-        break;
-      case HALF_MINUTE:
-        if (second >= 30) {
-          second = 30;
-        } else {
-          second = 0;
-        }
-        newDate = java.time.LocalDateTime.of(year, month, day, hour, minute, 
second);
-        break;
-      case QUARTER_MINUTE:
-        if (second >= 45) {
-          second = 45;
-        } else if (second >= 30) {
-          second = 30;
-        } else if (second >= 15) {
-          second = 15;
-        } else {
-          second = 0;
-        }
-        newDate = java.time.LocalDateTime.of(year, month, day, hour, minute, 
second);
-        break;
-      case SECOND:
-        newDate = java.time.LocalDateTime.of(year, month, day, hour, minute, 
second);
-        break;
-      default:
-        newDate = d;
-        break;
-    }
 
+    try {
+      switch (TimeInterval.valueOf(interval.toUpperCase())) {
 
 Review comment:
   You can try to convert string into TimeInterval before entering switch case 
and wrap only that line into try / catch which will be more readable, plus as I 
have mentioned before enumerating possible enum values would improve error 
message.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to