From 480650b8264162fa9ee18584c00f78609266d602 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Tue, 11 Aug 2009 02:09:33 +0000 Subject: [PATCH] fix typo breaking CompareSubcolumnsWith. fix timeuuid compare with byte[0]. patch by jbellis; reviewed by Evan Weaver for CASSANDRA-357 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@802977 13f79535-47bb-0310-9956-ffa450edef68 --- conf/log4j.properties | 2 +- .../cassandra/config/DatabaseDescriptor.java | 2 +- .../cassandra/db/marshal/TimeUUIDType.java | 9 +++++++++ test/conf/storage-conf.xml | 1 + test/system/test_server.py | 19 +++++++++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/conf/log4j.properties b/conf/log4j.properties index b95353b1f9..738929393f 100644 --- a/conf/log4j.properties +++ b/conf/log4j.properties @@ -18,7 +18,7 @@ # and the pattern to %c instead of %l. (%l is slower.) # output messages into a rolling log file as well as stdout -log4j.rootLogger=INFO,stdout,R +log4j.rootLogger=DEBUG,stdout,R # stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index 4071b17206..b576733017 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -906,7 +906,7 @@ public class DatabaseDescriptor public static AbstractType getSubComparator(String tableName, String cfName) { assert tableName != null; - return getCFMetaData(tableName, cfName).comparator; + return getCFMetaData(tableName, cfName).subcolumnComparator; } public static Map> getTableToColumnFamilyMap() diff --git a/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java b/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java index 6b3d16f5b8..b32ea9ef9c 100644 --- a/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java +++ b/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java @@ -6,6 +6,15 @@ public class TimeUUIDType extends AbstractType { public int compare(byte[] o1, byte[] o2) { + if (o1.length == 0) + { + return o2.length == 0 ? 0 : -1; + } + if (o2.length == 0) + { + return 1; + } + long t1 = LexicalUUIDType.getUUID(o1).timestamp(); long t2 = LexicalUUIDType.getUUID(o2).timestamp(); return t1 < t2 ? -1 : (t1 > t2 ? 1 : 0); diff --git a/test/conf/storage-conf.xml b/test/conf/storage-conf.xml index 2478068bab..6783091590 100644 --- a/test/conf/storage-conf.xml +++ b/test/conf/storage-conf.xml @@ -55,6 +55,7 @@ + diff --git a/test/system/test_server.py b/test/system/test_server.py index 444b1821d7..a49160bcab 100644 --- a/test/system/test_server.py +++ b/test/system/test_server.py @@ -179,7 +179,26 @@ class TestMutations(CassandraTester): for result in client.get_slice('Keyspace1', 'key1', column_parent, p, ConsistencyLevel.ONE)] assert slice == [Column(_i64(6), 'value6', 0)], slice + def test_time_uuid(self): + import uuid + L = [] + # 100 isn't enough to fail reliably if the comparator is borked + for i in xrange(500): + L.append(uuid.uuid1()) + client.insert('Keyspace2', 'key1', ColumnPath('Super4', 'sc1', L[-1].bytes), 'value%s' % i, i, ConsistencyLevel.ONE) + slice = _big_slice('Keyspace2', 'key1', ColumnParent('Super4', 'sc1')) + assert len(slice) == 500 + for i in xrange(500): + u = slice[i].column + assert u.value == 'value%s' % i + assert u.name == L[i].bytes + p = SlicePredicate(slice_range=SliceRange('', '', False, 1)) + column_parent = ColumnParent('Super4', 'sc1') + slice = [result.column + for result in client.get_slice('Keyspace2', 'key1', column_parent, p, ConsistencyLevel.ONE)] + assert slice == [Column(L[-1].bytes, 'value499', 499)], slice + def test_batch_insert(self): _insert_batch(False) time.sleep(0.1)