accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject svn commit: r1407157 - in /accumulo/branches/1.4: conf/ src/core/src/main/java/org/apache/accumulo/core/iterators/user/ src/core/src/test/java/org/apache/accumulo/core/iterators/user/
Date Thu, 08 Nov 2012 16:30:11 GMT
Author: billie
Date: Thu Nov  8 16:30:11 2012
New Revision: 1407157

URL: http://svn.apache.org/viewvc?rev=1407157&view=rev
Log:
ACCUMULO-776 made timestamp filter support longs greater than max date

Modified:
    accumulo/branches/1.4/conf/   (props changed)
    accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java
    accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
    accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/RegExFilterTest.java

Propchange: accumulo/branches/1.4/conf/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Nov  8 16:30:11 2012
@@ -8,3 +8,6 @@ monitor
 accumulo-env.sh
 accumulo-site.xml
 accumulo_user_manual.pdf
+generic_logger.xml
+log4j.properties
+monitor_logger.xml

Modified: accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java?rev=1407157&r1=1407156&r2=1407157&view=diff
==============================================================================
--- accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java
(original)
+++ accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java
Thu Nov  8 16:30:11 2012
@@ -17,8 +17,8 @@
 package org.apache.accumulo.core.iterators.user;
 
 import java.io.IOException;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.Map;
 import java.util.TimeZone;
 
@@ -33,6 +33,7 @@ import org.apache.accumulo.core.iterator
  * A Filter that matches entries whose timestamps fall within a range.
  */
 public class TimestampFilter extends Filter {
+  private static final String LONG_PREFIX = "LONG";
   private final SimpleDateFormat dateParser = initDateParser();
   
   private static SimpleDateFormat initDateParser() {
@@ -86,10 +87,20 @@ public class TimestampFilter extends Fil
       throw new IllegalArgumentException("must have either start or end for " + TimestampFilter.class.getName());
     
     try {
-      if (hasStart)
-        start = dateParser.parse(options.get(START)).getTime();
-      if (hasEnd)
-        end = dateParser.parse(options.get(END)).getTime();
+      if (hasStart) {
+        String s = options.get(START);
+        if (s.startsWith(LONG_PREFIX))
+          start = Long.valueOf(s.substring(LONG_PREFIX.length()));
+        else
+          start = dateParser.parse(s).getTime();
+      }
+      if (hasEnd) {
+        String s = options.get(END);
+        if (s.startsWith(LONG_PREFIX))
+          end = Long.valueOf(s.substring(LONG_PREFIX.length()));
+        else
+          end = dateParser.parse(s).getTime();
+      }
     } catch (Exception e) {
       throw new IllegalArgumentException(e);
     }
@@ -116,8 +127,8 @@ public class TimestampFilter extends Fil
     IteratorOptions io = super.describeOptions();
     io.setName("tsfilter");
     io.setDescription("TimestampFilter displays entries with timestamps between specified
values");
-    io.addNamedOption("start", "start timestamp (yyyyMMddHHmmssz)");
-    io.addNamedOption("end", "end timestamp (yyyyMMddHHmmssz)");
+    io.addNamedOption("start", "start timestamp (yyyyMMddHHmmssz or LONG<longstring>)");
+    io.addNamedOption("end", "end timestamp (yyyyMMddHHmmssz or LONG<longstring>)");
     io.addNamedOption("startInclusive", "true or false");
     io.addNamedOption("endInclusive", "true or false");
     return io;
@@ -126,11 +137,27 @@ public class TimestampFilter extends Fil
   @Override
   public boolean validateOptions(Map<String,String> options) {
     super.validateOptions(options);
+    boolean hasStart = false;
+    boolean hasEnd = false;
     try {
-      if (options.containsKey(START))
-        dateParser.parse(options.get(START));
-      if (options.containsKey(END))
-        dateParser.parse(options.get(END));
+      if (options.containsKey(START)) {
+        hasStart = true;
+        String s = options.get(START);
+        if (s.startsWith(LONG_PREFIX))
+          Long.valueOf(s.substring(LONG_PREFIX.length()));
+        else
+          dateParser.parse(s);
+      }
+      if (options.containsKey(END)) {
+        hasEnd = true;
+        String s = options.get(END);
+        if (s.startsWith(LONG_PREFIX))
+          Long.valueOf(s.substring(LONG_PREFIX.length()));
+        else
+          dateParser.parse(s);
+      }
+      if (!hasStart && !hasEnd)
+        return false;
       if (options.get(START_INCL) != null)
         Boolean.parseBoolean(options.get(START_INCL));
       if (options.get(END_INCL) != null)
@@ -185,8 +212,13 @@ public class TimestampFilter extends Fil
    *          boolean indicating whether the start is inclusive
    */
   public static void setStart(IteratorSetting is, String start, boolean startInclusive) {
-    is.addOption(START, start);
-    is.addOption(START_INCL, Boolean.toString(startInclusive));
+    SimpleDateFormat dateParser = initDateParser();
+    try {
+      long startTS = dateParser.parse(start).getTime();
+      setStart(is, startTS, startInclusive);
+    } catch (ParseException e) {
+      throw new IllegalArgumentException("couldn't parse " + start);
+    }
   }
   
   /**
@@ -200,8 +232,13 @@ public class TimestampFilter extends Fil
    *          boolean indicating whether the end is inclusive
    */
   public static void setEnd(IteratorSetting is, String end, boolean endInclusive) {
-    is.addOption(END, end);
-    is.addOption(END_INCL, Boolean.toString(endInclusive));
+    SimpleDateFormat dateParser = initDateParser();
+    try {
+      long endTS = dateParser.parse(end).getTime();
+      setEnd(is, endTS, endInclusive);
+    } catch (ParseException e) {
+      throw new IllegalArgumentException("couldn't parse " + end);
+    }
   }
   
   /**
@@ -248,8 +285,7 @@ public class TimestampFilter extends Fil
    *          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, LONG_PREFIX + Long.toString(start));
     is.addOption(START_INCL, Boolean.toString(startInclusive));
   }
   
@@ -264,8 +300,7 @@ public class TimestampFilter extends Fil
    *          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, LONG_PREFIX + Long.toString(end));
     is.addOption(END_INCL, Boolean.toString(endInclusive));
   }
 }

Modified: accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java?rev=1407157&r1=1407156&r2=1407157&view=diff
==============================================================================
--- accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
(original)
+++ accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
Thu Nov  8 16:30:11 2012
@@ -17,6 +17,7 @@
 package org.apache.accumulo.core.iterators.user;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
@@ -197,6 +198,8 @@ public class FilterTest {
     AgeOffFilter.setTTL(is, 101l);
     AgeOffFilter.setCurrentTime(is, 1001l);
     AgeOffFilter.setNegate(is, true);
+    assertTrue(((AgeOffFilter) a).validateOptions(is.getOptions()));
+    assertFalse(((AgeOffFilter) a).validateOptions(EMPTY_OPTS));
     a.init(new SortedMapIterator(tm), is.getOptions(), null);
     a = a.deepCopy(null);
     SortedKeyValueIterator<Key,Value> copy = a.deepCopy(null);
@@ -223,6 +226,7 @@ public class FilterTest {
     assertTrue(tm.size() == 1000);
     
     ColumnAgeOffFilter a = new ColumnAgeOffFilter();
+    assertTrue(a.validateOptions(is.getOptions()));
     a.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
     a.overrideCurrentTime(ts);
     a.seek(new Range(), EMPTY_COL_FAMS, false);
@@ -429,6 +433,7 @@ public class FilterTest {
     assertEquals(size(a), 89);
     
     TimestampFilter.setStart(is, "19990101000011GMT", false);
+    assertTrue(a.validateOptions(is.getOptions()));
     a.init(new SortedMapIterator(tm), is.getOptions(), null);
     a.seek(new Range(), EMPTY_COL_FAMS, false);
     assertEquals(size(a), 88);
@@ -440,9 +445,29 @@ public class FilterTest {
     assertEquals(size(a), 32);
     
     TimestampFilter.setEnd(is, "19990101000031GMT", false);
+    assertTrue(a.validateOptions(is.getOptions()));
     a.init(new SortedMapIterator(tm), is.getOptions(), null);
     a.seek(new Range(), EMPTY_COL_FAMS, false);
     assertEquals(size(a), 31);
+    
+    TimestampFilter.setEnd(is, 253402300800001l, true);
+    a.init(new SortedMapIterator(tm), is.getOptions(), null);
+    
+    is.clearOptions();
+    is.addOption(TimestampFilter.START, "19990101000011GMT");
+    assertTrue(a.validateOptions(is.getOptions()));
+    a.init(new SortedMapIterator(tm), is.getOptions(), null);
+    a.seek(new Range(), EMPTY_COL_FAMS, false);
+    assertEquals(size(a), 89);
+    
+    is.clearOptions();
+    is.addOption(TimestampFilter.END, "19990101000031GMT");
+    assertTrue(a.validateOptions(is.getOptions()));
+    a.init(new SortedMapIterator(tm), is.getOptions(), null);
+    a.seek(new Range(), EMPTY_COL_FAMS, false);
+    assertEquals(size(a), 32);
+    
+    assertFalse(a.validateOptions(EMPTY_OPTS));
   }
   
   @Test

Modified: accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/RegExFilterTest.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/RegExFilterTest.java?rev=1407157&r1=1407156&r2=1407157&view=diff
==============================================================================
--- accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/RegExFilterTest.java
(original)
+++ accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/RegExFilterTest.java
Thu Nov  8 16:30:11 2012
@@ -59,7 +59,7 @@ public class RegExFilterTest extends Tes
     IteratorSetting is = new IteratorSetting(1, RegExFilter.class);
     RegExFilter.setRegexs(is, ".*2", null, null, null, false);
     
-    rei.validateOptions(is.getOptions());
+    assertTrue(rei.validateOptions(is.getOptions()));
     rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
     rei.seek(new Range(), EMPTY_COL_FAMS, false);
     
@@ -72,7 +72,7 @@ public class RegExFilterTest extends Tes
     is.clearOptions();
     
     RegExFilter.setRegexs(is, null, "ya.*", null, null, false);
-    rei.validateOptions(is.getOptions());
+    assertTrue(rei.validateOptions(is.getOptions()));
     rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
     rei.seek(new Range(), EMPTY_COL_FAMS, false);
     
@@ -85,7 +85,7 @@ public class RegExFilterTest extends Tes
     is.clearOptions();
     
     RegExFilter.setRegexs(is, null, null, ".*01", null, false);
-    rei.validateOptions(is.getOptions());
+    assertTrue(rei.validateOptions(is.getOptions()));
     rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
     rei.seek(new Range(), EMPTY_COL_FAMS, false);
     
@@ -98,7 +98,7 @@ public class RegExFilterTest extends Tes
     is.clearOptions();
     
     RegExFilter.setRegexs(is, null, null, null, ".*at", false);
-    rei.validateOptions(is.getOptions());
+    assertTrue(rei.validateOptions(is.getOptions()));
     rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
     rei.seek(new Range(), EMPTY_COL_FAMS, false);
     



Mime
View raw message