Repository: oozie
Updated Branches:
  refs/heads/branch-4.3 9e0e2568a -> 2cb1bbbbd


OOZIE-2724 coord:current resolves monthly/yearly dependencies incorrectly 
(satishsaley via shwethags)


Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/35b80500
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/35b80500
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/35b80500

Branch: refs/heads/branch-4.3
Commit: 35b805005ca0c2a9110f0544600aa17531dfd05c
Parents: 9e0e256
Author: Shwetha GS <[email protected]>
Authored: Tue Nov 15 15:22:12 2016 +0530
Committer: Shwetha GS <[email protected]>
Committed: Tue Nov 15 15:22:12 2016 +0530

----------------------------------------------------------------------
 .../apache/oozie/coord/CoordELFunctions.java    |  7 ++--
 .../oozie/coord/TestCoordELFunctions.java       | 36 ++++++++++++++++++++
 release-log.txt                                 |  1 +
 3 files changed, 40 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/35b80500/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java 
b/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java
index 22eb1c3..925a7aa 100644
--- a/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java
+++ b/core/src/main/java/org/apache/oozie/coord/CoordELFunctions.java
@@ -62,8 +62,6 @@ public class CoordELFunctions {
     public static final long MINUTE_MSEC = 60 * 1000L;
     public static final long HOUR_MSEC = 60 * MINUTE_MSEC;
     public static final long DAY_MSEC = 24 * HOUR_MSEC;
-    public static final long MONTH_MSEC = 30 * DAY_MSEC;
-    public static final long YEAR_MSEC = 365 * DAY_MSEC;
     /**
      * Used in defining the frequency in 'day' unit. <p> domain: <code> val 
&gt; 0</code> and should be integer.
      *
@@ -1401,10 +1399,11 @@ public class CoordELFunctions {
                 break;
             case MONTH:
             case END_OF_MONTH:
-                instanceCount[0] = (int) ((effectiveTime.getTime() - 
datasetInitialInstance.getTime()) / MONTH_MSEC);
+                int diffYear = calEffectiveTime.get(Calendar.YEAR) - 
current.get(Calendar.YEAR);
+                instanceCount[0] = diffYear * 12 + 
calEffectiveTime.get(Calendar.MONTH) - current.get(Calendar.MONTH);
                 break;
             case YEAR:
-                instanceCount[0] = (int) ((effectiveTime.getTime() - 
datasetInitialInstance.getTime()) / YEAR_MSEC);
+                instanceCount[0] = calEffectiveTime.get(Calendar.YEAR) - 
current.get(Calendar.YEAR);
                 break;
             default:
                 throw new IllegalArgumentException("Unhandled dataset time 
unit " + dsTimeUnit);

http://git-wip-us.apache.org/repos/asf/oozie/blob/35b80500/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java 
b/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java
index fb7e030..be60133 100644
--- a/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java
+++ b/core/src/test/java/org/apache/oozie/coord/TestCoordELFunctions.java
@@ -702,6 +702,42 @@ public class TestCoordELFunctions extends XTestCase {
 
         expr = "${coord:current(1)}";
         assertEquals("2009-06-01T07:00Z", CoordELFunctions.evalAndWrap(eval, 
expr));
+
+        // Case 8
+        ds.setEndOfDuration(TimeUnit.END_OF_MONTH);
+        ds.setFrequency(1);
+        ds.setTimeZone(DateUtils.getTimeZone("UTC"));
+        ds.setInitInstance(DateUtils.parseDateOozieTZ("2010-01-01T00:00Z"));
+        
appInst.setNominalTime(DateUtils.parseDateOozieTZ("2016-10-31T00:55Z"));
+        CoordELFunctions.configureEvaluator(eval, ds, appInst);
+
+        expr = "${coord:current(0)}";
+        assertEquals("2016-10-01T00:00Z", CoordELFunctions.evalAndWrap(eval, 
expr));
+
+        expr = "${coord:current(1)}";
+        assertEquals("2016-11-01T00:00Z", CoordELFunctions.evalAndWrap(eval, 
expr));
+
+        expr = "${coord:current(-1)}";
+        assertEquals("2016-09-01T00:00Z", CoordELFunctions.evalAndWrap(eval, 
expr));
+
+        // Test with YEAR
+        ds.setTimeUnit(TimeUnit.YEAR);
+        ds.setEndOfDuration(TimeUnit.YEAR);
+        ds.setFrequency(1);
+        ds.setTimeZone(DateUtils.getTimeZone("UTC"));
+        // Initial instance is far behind to accumulate effect of leap years
+        ds.setInitInstance(DateUtils.parseDateOozieTZ("1963-01-01T00:00Z"));
+        
appInst.setNominalTime(DateUtils.parseDateOozieTZ("2016-10-31T00:55Z"));
+        CoordELFunctions.configureEvaluator(eval, ds, appInst);
+
+        expr = "${coord:current(0)}";
+        assertEquals("2016-01-01T00:00Z", CoordELFunctions.evalAndWrap(eval, 
expr));
+
+        expr = "${coord:current(1)}";
+        assertEquals("2017-01-01T00:00Z", CoordELFunctions.evalAndWrap(eval, 
expr));
+
+        expr = "${coord:current(-1)}";
+        assertEquals("2015-01-01T00:00Z", CoordELFunctions.evalAndWrap(eval, 
expr));
     }
 
     public void testOffset() throws Exception {

http://git-wip-us.apache.org/repos/asf/oozie/blob/35b80500/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index a89b7db..7089a9d 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 4.3.0 release
 
+OOZIE-2724 coord:current resolves monthly/yearly dependencies incorrectly 
(satishsaley via shwethags)
 OOZIE-2719 Test case failure (abhishekbafna via jaydeepvishwakarma)
 OOZIE-2674 Improve oozie commads documentation (abhishekbafna via rkanter)
 OOZIE-2710 Oozie HCatalog example workflow fails (abhishekbafna via shwethags)

Reply via email to