incubator-accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject svn commit: r1208736 - in /incubator/accumulo/trunk: ./ src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
Date Wed, 30 Nov 2011 19:53:26 GMT
Author: billie
Date: Wed Nov 30 19:53:25 2011
New Revision: 1208736

URL: http://svn.apache.org/viewvc?rev=1208736&view=rev
Log:
ACCUMULO-167 merged to trunk

Modified:
    incubator/accumulo/trunk/   (props changed)
    incubator/accumulo/trunk/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java
    incubator/accumulo/trunk/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java

Propchange: incubator/accumulo/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Nov 30 19:53:25 2011
@@ -1,2 +1,2 @@
 /incubator/accumulo/branches/1.3:1190280,1190413,1190420,1190427,1190500,1195622,1195625,1195629,1195635,1196044,1196054,1196057,1196071-1196072,1196106,1197066,1198935,1199383,1203683,1204625,1205547,1205880,1206169,1208031
-/incubator/accumulo/branches/1.4:1201902-1208706
+/incubator/accumulo/branches/1.4:1201902-1208733

Modified: incubator/accumulo/trunk/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/trunk/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java?rev=1208736&r1=1208735&r2=1208736&view=diff
==============================================================================
--- incubator/accumulo/trunk/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java
(original)
+++ incubator/accumulo/trunk/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java
Wed Nov 30 19:53:25 2011
@@ -18,7 +18,9 @@ package org.apache.accumulo.core.iterato
 
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Map;
+import java.util.TimeZone;
 
 import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.data.Key;
@@ -31,7 +33,13 @@ import org.apache.accumulo.core.iterator
  * A Filter that matches entries whose timestamps fall within a range.
  */
 public class TimestampFilter extends Filter {
-  private final SimpleDateFormat dateParser = new SimpleDateFormat("yyyyMMddHHmmssz");
+  private final SimpleDateFormat dateParser = initDateParser();
+  
+  private static SimpleDateFormat initDateParser() {
+    SimpleDateFormat dateParser = new SimpleDateFormat("yyyyMMddHHmmssz");
+    dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
+    return dateParser;
+  }
   
   public static final String START = "start";
   public static final String START_INCL = "startInclusive";
@@ -87,7 +95,7 @@ public class TimestampFilter extends Fil
       hasEnd = true;
     if (!hasStart && !hasEnd)
       throw new IllegalArgumentException("must have either start or end for " + TimestampFilter.class.getName());
-
+    
     try {
       if (hasStart)
         start = dateParser.parse(options.get(START)).getTime();
@@ -199,4 +207,69 @@ public class TimestampFilter extends Fil
     is.addOption(END, end);
     is.addOption(END_INCL, Boolean.toString(endInclusive));
   }
+  
+  /**
+   * A convenience method for setting the range of timestamps accepted by the timestamp filter.
+   * 
+   * @param is
+   *          the iterator setting object to configure
+   * @param start
+   *          the start timestamp, inclusive
+   * @param end
+   *          the end timestamp, inclusive
+   */
+  public static void setRange(IteratorSetting is, long start, long end) {
+    setRange(is, start, true, end, true);
+  }
+  
+  /**
+   * A convenience method for setting the range of timestamps accepted by the timestamp filter.
+   * 
+   * @param is
+   *          the iterator setting object to configure
+   * @param start
+   *          the start timestamp
+   * @param startInclusive
+   *          boolean indicating whether the start is inclusive
+   * @param end
+   *          the end timestamp
+   * @param endInclusive
+   *          boolean indicating whether the end is inclusive
+   */
+  public static void setRange(IteratorSetting is, long start, boolean startInclusive, long
end, boolean endInclusive) {
+    setStart(is, start, startInclusive);
+    setEnd(is, end, endInclusive);
+  }
+  
+  /**
+   * A convenience method for setting the start timestamp accepted by the timestamp filter.
+   * 
+   * @param is
+   *          the iterator setting object to configure
+   * @param start
+   *          the start timestamp
+   * @param startInclusive
+   *          boolean indicating whether the start is inclusive
+   */
+  public static void setStart(IteratorSetting is, long start, boolean startInclusive) {
+    SimpleDateFormat dateParser = initDateParser();
+    is.addOption(START, dateParser.format(new Date(start)));
+    is.addOption(START_INCL, Boolean.toString(startInclusive));
+  }
+  
+  /**
+   * A convenience method for setting the end timestamp accepted by the timestamp filter.
+   * 
+   * @param is
+   *          the iterator setting object to configure
+   * @param end
+   *          the end timestamp
+   * @param endInclusive
+   *          boolean indicating whether the end is inclusive
+   */
+  public static void setEnd(IteratorSetting is, long end, boolean endInclusive) {
+    SimpleDateFormat dateParser = initDateParser();
+    is.addOption(END, dateParser.format(new Date(end)));
+    is.addOption(END_INCL, Boolean.toString(endInclusive));
+  }
 }

Modified: incubator/accumulo/trunk/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/trunk/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java?rev=1208736&r1=1208735&r2=1208736&view=diff
==============================================================================
--- incubator/accumulo/trunk/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
(original)
+++ incubator/accumulo/trunk/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
Wed Nov 30 19:53:25 2011
@@ -147,7 +147,7 @@ public class FilterTest extends TestCase
     size = size(filter2);
     assertTrue("size = " + size, size == 100);
   }
-
+  
   public void test2() throws IOException {
     Text colf = new Text("a");
     Text colq = new Text("b");
@@ -354,7 +354,11 @@ public class FilterTest extends TestCase
     assertTrue(tm.size() == 100);
     TimestampFilter a = new TimestampFilter();
     IteratorSetting is = new IteratorSetting(1, TimestampFilter.class);
-    TimestampFilter.setRange(is, "19990101000011GMT", "19990101000031GMT");
+    TimestampFilter.setRange(is, "19990101010011GMT+01:00", "19990101010031GMT+01:00");
+    a.init(new SortedMapIterator(tm), is.getProperties(), null);
+    a.seek(new Range(), EMPTY_COL_FAMS, false);
+    assertEquals(size(a), 21);
+    TimestampFilter.setRange(is, baseTime + 11000, baseTime + 31000);
     a.init(new SortedMapIterator(tm), is.getProperties(), null);
     a.seek(new Range(), EMPTY_COL_FAMS, false);
     assertEquals(size(a), 21);



Mime
View raw message