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
This commit is contained in:
Jonathan Ellis 2009-08-11 02:09:33 +00:00
parent 7f63092fed
commit 480650b826
5 changed files with 31 additions and 2 deletions

View File

@ -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

View File

@ -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<String, Map<String, CFMetaData>> getTableToColumnFamilyMap()

View File

@ -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);

View File

@ -55,6 +55,7 @@
<ColumnFamily Name="Standard1"/>
<ColumnFamily Name="Standard3"/>
<ColumnFamily ColumnType="Super" Name="Super3"/>
<ColumnFamily ColumnType="Super" CompareSubcolumnsWith="TimeUUIDType" Name="Super4"/>
</Keyspace>
</Keyspaces>
<Seeds>

View File

@ -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)