cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r798273 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/db/marshal/ src/java/org/apache/cassandra/io/ test/unit/org/apache/cassandra/db/marshal/
Date Mon, 27 Jul 2009 20:19:54 GMT
Author: jbellis
Date: Mon Jul 27 20:19:53 2009
New Revision: 798273

URL: http://svn.apache.org/viewvc?rev=798273&view=rev
Log:
fix bug in comparing-to-empty-array; realize that we need compare-to-empty-array to specify
start/finish of slices.
patch by jbellis; reviewed by Stu Hood for CASSANDRA-119

Added:
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/UTF8TypeTest.java
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/AsciiTypeTest.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java?rev=798273&r1=798272&r2=798273&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java Mon
Jul 27 20:19:53 2009
@@ -4,8 +4,15 @@
 import java.util.Collection;
 
 import org.apache.cassandra.db.IColumn;
-import org.apache.cassandra.db.SuperColumn;
 
+/**
+ * Specifies a Comparator for a specific type of byte[].
+ *
+ * Note that empty byte[] are used to represent "start at the beginning"
+ * or "stop at the end" arguments to get_slice, so the Comparator
+ * should always handle those values even if they normally do not
+ * represent a valid byte[] for the type being compared.
+ */
 public abstract class AbstractType implements Comparator<byte[]>
 {
     /** get a string representation of the bytes suitable for log messages */

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java?rev=798273&r1=798272&r2=798273&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java Mon Jul
27 20:19:53 2009
@@ -7,14 +7,13 @@
 {
     public int compare(byte[] o1, byte[] o2)
     {
-        // TODO rm hack to support the "i'm going to pretend [] is an index entry if I didn't
actually index anything" hack
         if (o1.length == 0)
         {
             return o2.length == 0 ? 0 : -1;
         }
         if (o2.length == 0)
         {
-            return -1;
+            return 1;
         }
 
         long L1 = ByteBuffer.wrap(o1).order(ByteOrder.LITTLE_ENDIAN).getLong();

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UTF8Type.java?rev=798273&r1=798272&r2=798273&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UTF8Type.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UTF8Type.java Mon Jul
27 20:19:53 2009
@@ -6,16 +6,6 @@
 {
     public int compare(byte[] o1, byte[] o2)
     {
-        // TODO rm hack to support the "i'm going to pretend [] is an index entry if I didn't
actually index anything" hack
-        if (o1.length == 0)
-        {
-            return o2.length == 0 ? 0 : -1;
-        }
-        if (o2.length == 0)
-        {
-            return -1;
-        }
-
         try
         {
             return new String(o1, "UTF-8").compareTo(new String(o2, "UTF-8"));

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java?rev=798273&r1=798272&r2=798273&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java Mon Jul
27 20:19:53 2009
@@ -13,14 +13,13 @@
 
     public int compare(byte[] o1, byte[] o2)
     {
-        // TODO rm hack to support the "i'm going to pretend [] is an index entry if I didn't
actually index anything" hack
         if (o1.length == 0)
         {
             return o2.length == 0 ? 0 : -1;
         }
         if (o2.length == 0)
         {
-            return -1;
+            return 1;
         }
 
         return getUUID(o1).compareTo(getUUID(o2));

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java?rev=798273&r1=798272&r2=798273&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java Mon Jul 27
20:19:53 2009
@@ -258,7 +258,6 @@
             if (columnIndexList.size() == 0)
             {
                 /* if there is no column index, add an index entry that covers the full space.
*/
-                // TODO can we remove this?  it causes a lot of ugliness in everything that
touches Marshal
                 return Arrays.asList(new IndexHelper.ColumnIndexInfo(ArrayUtils.EMPTY_BYTE_ARRAY,
0, totalNumCols, comparator_));
             }
 

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/AsciiTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/AsciiTypeTest.java?rev=798273&r1=798272&r2=798273&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/AsciiTypeTest.java
(original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/AsciiTypeTest.java
Mon Jul 27 20:19:53 2009
@@ -4,8 +4,6 @@
 
 import org.junit.Test;
 
-import junit.framework.TestCase;
-
 public class AsciiTypeTest
 {
     @Test
@@ -13,7 +11,10 @@
     {
         AsciiType comparator = new AsciiType();
         assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, "asdf".getBytes()) < 0;
+        assert comparator.compare("asdf".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY) > 0;
+        assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY)
== 0;
         assert comparator.compare("z".getBytes(), "a".getBytes()) > 0;
+        assert comparator.compare("a".getBytes(), "z".getBytes()) < 0;
         assert comparator.compare("asdf".getBytes(), "asdf".getBytes()) == 0;
         assert comparator.compare("asdz".getBytes(), "asdf".getBytes()) > 0;
     }

Added: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/UTF8TypeTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/UTF8TypeTest.java?rev=798273&view=auto
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/UTF8TypeTest.java
(added)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/UTF8TypeTest.java
Mon Jul 27 20:19:53 2009
@@ -0,0 +1,22 @@
+package org.apache.cassandra.db.marshal;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.lang.ArrayUtils;
+
+import org.junit.Test;
+
+public class UTF8TypeTest
+{
+    @Test
+    public void testCompare() throws UnsupportedEncodingException
+    {
+        UTF8Type comparator = new UTF8Type();
+        assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, "asdf".getBytes()) < 0;
+        assert comparator.compare("asdf".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY) > 0;
+        assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY)
== 0;
+        assert comparator.compare("z".getBytes("UTF-8"), "a".getBytes("UTF-8")) > 0;
+        assert comparator.compare("z".getBytes("UTF-8"), "z".getBytes("UTF-8")) == 0;
+        assert comparator.compare("a".getBytes("UTF-8"), "z".getBytes("UTF-8")) < 0;
+    }
+}



Mime
View raw message