falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shweth...@apache.org
Subject git commit: FALCON-577 Extend time functions added in Falcon 0.6 to support current & last week are giving UnsupportedOperationException. Contributed by Srikanth Sundarrajan
Date Mon, 11 Aug 2014 06:40:01 GMT
Repository: incubator-falcon
Updated Branches:
  refs/heads/master 6bcefc3a4 -> 30b83d21a


FALCON-577 Extend time functions added in Falcon 0.6 to support current & last week are
giving UnsupportedOperationException. Contributed by Srikanth Sundarrajan


Project: http://git-wip-us.apache.org/repos/asf/incubator-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-falcon/commit/30b83d21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-falcon/tree/30b83d21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-falcon/diff/30b83d21

Branch: refs/heads/master
Commit: 30b83d21a2726641435d9290320d5f54f47b3b95
Parents: 6bcefc3
Author: Shwetha GS <shwetha.gs@inmobi.com>
Authored: Mon Aug 11 12:08:25 2014 +0530
Committer: Shwetha GS <shwetha.gs@inmobi.com>
Committed: Mon Aug 11 12:09:40 2014 +0530

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 +++
 .../falcon/expression/ExpressionHelper.java     | 26 ++++++++++++++++++++
 .../oozie/extensions/OozieELExtensions.java     |  9 +++++--
 webapp/src/test/resources/process-template.xml  |  1 +
 4 files changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/30b83d21/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1bca803..8ee08e8 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -47,6 +47,9 @@ Trunk (Unreleased)
   OPTIMIZATIONS
 
   BUG FIXES
+   FALCON-577 Extend time functions added in Falcon 0.6 to support current & last week

+   are giving UnsupportedOperationException. (Srikanth Sundarrajan via Shwetha GS)
+
    FALCON-578 Table import & table export failing during hcat table replication
    (Suhas Vasu)
    

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/30b83d21/common/src/main/java/org/apache/falcon/expression/ExpressionHelper.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/falcon/expression/ExpressionHelper.java b/common/src/main/java/org/apache/falcon/expression/ExpressionHelper.java
index 189fdd4..79d6e2d 100644
--- a/common/src/main/java/org/apache/falcon/expression/ExpressionHelper.java
+++ b/common/src/main/java/org/apache/falcon/expression/ExpressionHelper.java
@@ -52,6 +52,10 @@ public final class ExpressionHelper implements FunctionMapper, VariableResolver
         return INSTANCE;
     }
 
+    private enum DayOfWeek {
+        SUN, MON, TUE, WED, THU, FRI, SAT
+    }
+
     private ExpressionHelper() {
     }
 
@@ -93,6 +97,18 @@ public final class ExpressionHelper implements FunctionMapper, VariableResolver
         referenceDate.set(date);
     }
 
+    private static int getDayOffset(String weekDayName) {
+        int day;
+        Calendar nominalTime = Calendar.getInstance();
+        int currentWeekDay = nominalTime.get(Calendar.DAY_OF_WEEK);
+        int weekDay = DayOfWeek.valueOf(weekDayName).ordinal() + 1; //to map to Calendar.SUNDAY
...
+        day = weekDay - currentWeekDay;
+        if (weekDay > currentWeekDay) {
+            day = day - 7;
+        }
+        return day;
+    }
+
     @edu.umd.cs.findbugs.annotations.SuppressWarnings({"SF_SWITCH_FALLTHROUGH"})
     private static Date getRelative(Date date, int boundary, int month, int day, int hour,
int minute) {
         Calendar dsInstanceCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -143,6 +159,16 @@ public final class ExpressionHelper implements FunctionMapper, VariableResolver
         return getRelative(referenceDate.get(), Calendar.MONTH, -1, day, hour, minute);
     }
 
+    public static Date currentWeek(String weekDay, int hour, int minute) {
+        int day = getDayOffset(weekDay);
+        return getRelative(referenceDate.get(), Calendar.MONTH, 0, day, hour, minute);
+    }
+
+    public static Date lastWeek(String weekDay, int hour, int minute) {
+        int day = getDayOffset(weekDay);
+        return getRelative(referenceDate.get(), Calendar.MONTH, -1, day, hour, minute);
+    }
+
     public static Date currentYear(int month, int day, int hour, int minute) {
         return getRelative(referenceDate.get(), Calendar.YEAR, month, day, hour, minute);
     }

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/30b83d21/oozie-el-extensions/src/main/java/org/apache/oozie/extensions/OozieELExtensions.java
----------------------------------------------------------------------
diff --git a/oozie-el-extensions/src/main/java/org/apache/oozie/extensions/OozieELExtensions.java
b/oozie-el-extensions/src/main/java/org/apache/oozie/extensions/OozieELExtensions.java
index 66385a9..f3533b8 100644
--- a/oozie-el-extensions/src/main/java/org/apache/oozie/extensions/OozieELExtensions.java
+++ b/oozie-el-extensions/src/main/java/org/apache/oozie/extensions/OozieELExtensions.java
@@ -365,8 +365,13 @@ public final class OozieELExtensions {
 
     private static int getDayOffset(String weekDayName) {
         int day;
-        Calendar nominalTime = CoordELFunctions.getEffectiveNominalTime();
-        int currentWeekDay = nominalTime.get(Calendar.DAY_OF_WEEK);
+        Calendar effectiveTime;
+        if (isDatasetContext()) {
+            effectiveTime = CoordELFunctions.getEffectiveNominalTime();
+        } else {
+            effectiveTime = getEffectiveTime(TruncateBoundary.DAY, 0, 0, 0, 0, 0);
+        }
+        int currentWeekDay = effectiveTime.get(Calendar.DAY_OF_WEEK);
         int weekDay = DayOfWeek.valueOf(weekDayName).ordinal() + 1; //to map to Calendar.SUNDAY
...
         day = weekDay - currentWeekDay;
         if (weekDay > currentWeekDay) {

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/30b83d21/webapp/src/test/resources/process-template.xml
----------------------------------------------------------------------
diff --git a/webapp/src/test/resources/process-template.xml b/webapp/src/test/resources/process-template.xml
index 716a458..8015da2 100644
--- a/webapp/src/test/resources/process-template.xml
+++ b/webapp/src/test/resources/process-template.xml
@@ -39,6 +39,7 @@
         <property name="fileTime" value="${formatTime(dateOffset(instanceTime(), 1, 'DAY'),
'yyyy-MMM-dd')}"/>
         <property name="user" value="${user()}"/>
         <property name="baseTime" value="${today(0,0)}"/>
+        <property name="sundayThisWeek" value="${currentWeek('SUN', 0, 0)}"/>
     </properties>
     <workflow engine="oozie" path="/falcon/test/workflow"/>
     <retry policy="periodic" delay="minutes(10)" attempts="3"/>


Mime
View raw message