accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [1/4] accumulo git commit: ACCUMULO-3385 Fix broken DateLexicoder ordering
Date Fri, 05 Dec 2014 22:24:50 GMT
Repository: accumulo
Updated Branches:
  refs/heads/1.6 1d288cfe5 -> a3267d3e7
  refs/heads/master 2f788f482 -> 856496138


ACCUMULO-3385 Fix broken DateLexicoder ordering

  Corrects the ordering so that dates before 1970 actually sort before dates
  after it. This changes the internal serialization, so please see the release
  notes for a workaround if you have data written with the buggy form.


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

Branch: refs/heads/1.6
Commit: a3267d3e75ca55b6444cd294c78e55e19e252b43
Parents: 1d288cf
Author: Christopher Tubbs <ctubbsii@apache.org>
Authored: Fri Dec 5 17:09:13 2014 -0500
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Fri Dec 5 17:09:13 2014 -0500

----------------------------------------------------------------------
 .../core/client/lexicoder/DateLexicoder.java    | 11 +++++----
 .../client/lexicoder/ReverseLexicoderTest.java  | 24 ++++++++++++--------
 2 files changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/a3267d3e/core/src/main/java/org/apache/accumulo/core/client/lexicoder/DateLexicoder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/lexicoder/DateLexicoder.java
b/core/src/main/java/org/apache/accumulo/core/client/lexicoder/DateLexicoder.java
index c93ba70..8533bfe 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/lexicoder/DateLexicoder.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/lexicoder/DateLexicoder.java
@@ -20,20 +20,21 @@ import java.util.Date;
 
 /**
  * A lexicoder for date objects. It preserves the native Java sort order for Date.
+ *
  * @since 1.6.0
  */
 public class DateLexicoder implements Lexicoder<Date> {
-  
-  private ULongLexicoder longEncoder = new ULongLexicoder();
-  
+
+  private LongLexicoder longEncoder = new LongLexicoder();
+
   @Override
   public byte[] encode(Date data) {
     return longEncoder.encode(data.getTime());
   }
-  
+
   @Override
   public Date decode(byte[] data) {
     return new Date(longEncoder.decode(data));
   }
-  
+
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/a3267d3e/core/src/test/java/org/apache/accumulo/core/client/lexicoder/ReverseLexicoderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/lexicoder/ReverseLexicoderTest.java
b/core/src/test/java/org/apache/accumulo/core/client/lexicoder/ReverseLexicoderTest.java
index e6bfca8..3077645 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/lexicoder/ReverseLexicoderTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/lexicoder/ReverseLexicoderTest.java
@@ -17,6 +17,7 @@
 package org.apache.accumulo.core.client.lexicoder;
 
 import java.io.UnsupportedEncodingException;
+import java.util.Calendar;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
@@ -29,32 +30,35 @@ public class ReverseLexicoderTest extends LexicoderTest {
     assertSortOrder(new ReverseLexicoder<Long>(new LongLexicoder()), comp, Long.MIN_VALUE,
0xff1234567890abcdl, 0xffff1234567890abl, 0xffffff567890abcdl,
         0xffffffff7890abcdl, 0xffffffffff90abcdl, 0xffffffffffffabcdl, 0xffffffffffffffcdl,
-1l, 0l, 0x01l, 0x1234l, 0x123456l, 0x12345678l, 0x1234567890l,
         0x1234567890abl, 0x1234567890abcdl, 0x1234567890abcdefl, Long.MAX_VALUE);
-    
+
     Comparator<String> comp2 = Collections.reverseOrder();
     assertSortOrder(new ReverseLexicoder<String>(new StringLexicoder()), comp2, "a",
"aa", "ab", "b", "aab");
-    
+
   }
-  
+
   /**
    * Just a simple test verifying reverse indexed dates
    */
   @Test
   public void testReverseSortDates() throws UnsupportedEncodingException {
-    
+
     ReverseLexicoder<Date> revLex = new ReverseLexicoder<Date>(new DateLexicoder());
-    
+
+    Calendar cal = Calendar.getInstance();
+    cal.set(1920, 1, 2, 3, 4, 5); // create an instance prior to 1970 for ACCUMULO-3385
+    Date date0 = new Date(cal.getTimeInMillis());
     Date date1 = new Date();
     Date date2 = new Date(System.currentTimeMillis() + 10000);
     Date date3 = new Date(System.currentTimeMillis() + 500);
-    
+
     Comparator<Date> comparator = Collections.reverseOrder();
-    assertSortOrder(revLex, comparator, date1, date2, date3);
-    
+    assertSortOrder(revLex, comparator, date0, date1, date2, date3);
+
     // truncate date to hours
     long time = System.currentTimeMillis() - (System.currentTimeMillis() % 3600000);
     Date date = new Date(time);
-    
+
     System.out.println(date);
-    
+
   }
 }


Mime
View raw message