mirror of https://github.com/apache/cassandra
extract thriftifyColumnFamily and apply to getSlice and get_slice_range. patch by jbellis; reviewed by Jonathan Hseu for CASSANDRA-649
git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/branches/cassandra-0.5@893907 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a2772e50e3
commit
174919be92
|
|
@ -1,5 +1,6 @@
|
|||
0.5.0 RC2
|
||||
* fix bugs in converting get_slice_range results to Thrift (CASSANDRA-647)
|
||||
* fix bugs in converting get_slice_range results to Thrift
|
||||
(CASSANDRA-647, CASSANDRA-649)
|
||||
|
||||
|
||||
0.5.0 RC1
|
||||
|
|
|
|||
|
|
@ -169,39 +169,38 @@ public class CassandraServer implements Cassandra.Iface
|
|||
private Map<String, List<ColumnOrSuperColumn>> getSlice(List<ReadCommand> commands, int consistency_level)
|
||||
throws InvalidRequestException, UnavailableException, TimedOutException
|
||||
{
|
||||
Map<String, ColumnFamily> cfamilies = readColumnFamily(commands, consistency_level);
|
||||
Map<String, ColumnFamily> columnFamilies = readColumnFamily(commands, consistency_level);
|
||||
Map<String, List<ColumnOrSuperColumn>> columnFamiliesMap = new HashMap<String, List<ColumnOrSuperColumn>>();
|
||||
for (ReadCommand command: commands)
|
||||
{
|
||||
ColumnFamily cfamily = cfamilies.get(command.key);
|
||||
ColumnFamily cf = columnFamilies.get(command.key);
|
||||
boolean reverseOrder = command instanceof SliceFromReadCommand && ((SliceFromReadCommand)command).reversed;
|
||||
|
||||
if (cfamily == null || cfamily.getColumnsMap().size() == 0)
|
||||
{
|
||||
columnFamiliesMap.put(command.key, EMPTY_COLUMNS);
|
||||
continue;
|
||||
}
|
||||
if (command.queryPath.superColumnName != null)
|
||||
{
|
||||
IColumn column = cfamily.getColumnsMap().values().iterator().next();
|
||||
Collection<IColumn> subcolumns = column.getSubColumns();
|
||||
if (subcolumns == null || subcolumns.isEmpty())
|
||||
{
|
||||
columnFamiliesMap.put(command.key, EMPTY_COLUMNS);
|
||||
continue;
|
||||
}
|
||||
columnFamiliesMap.put(command.key, thriftifyColumns(subcolumns, reverseOrder));
|
||||
continue;
|
||||
}
|
||||
if (cfamily.isSuper())
|
||||
columnFamiliesMap.put(command.key, thriftifySuperColumns(cfamily.getSortedColumns(), reverseOrder));
|
||||
else
|
||||
columnFamiliesMap.put(command.key, thriftifyColumns(cfamily.getSortedColumns(), reverseOrder));
|
||||
List<ColumnOrSuperColumn> thriftifiedColumns = thriftifyColumnFamily(cf, command.queryPath.superColumnName != null, reverseOrder);
|
||||
columnFamiliesMap.put(command.key, thriftifiedColumns);
|
||||
}
|
||||
|
||||
return columnFamiliesMap;
|
||||
}
|
||||
|
||||
private List<ColumnOrSuperColumn> thriftifyColumnFamily(ColumnFamily cf, boolean subcolumnsOnly, boolean reverseOrder)
|
||||
{
|
||||
if (cf == null || cf.getColumnsMap().size() == 0)
|
||||
return EMPTY_COLUMNS;
|
||||
if (subcolumnsOnly)
|
||||
{
|
||||
IColumn column = cf.getColumnsMap().values().iterator().next();
|
||||
Collection<IColumn> subcolumns = column.getSubColumns();
|
||||
if (subcolumns == null || subcolumns.isEmpty())
|
||||
return EMPTY_COLUMNS;
|
||||
else
|
||||
return thriftifyColumns(subcolumns, reverseOrder);
|
||||
}
|
||||
if (cf.isSuper())
|
||||
return thriftifySuperColumns(cf.getSortedColumns(), reverseOrder);
|
||||
else
|
||||
return thriftifyColumns(cf.getSortedColumns(), reverseOrder);
|
||||
}
|
||||
|
||||
public List<ColumnOrSuperColumn> get_slice(String keyspace, String key, ColumnParent column_parent, SlicePredicate predicate, int consistency_level)
|
||||
throws InvalidRequestException, UnavailableException, TimedOutException
|
||||
{
|
||||
|
|
@ -566,7 +565,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
throw new InvalidRequestException("maxRows must be positive");
|
||||
}
|
||||
|
||||
List<Pair<String,Collection<IColumn>>> rows;
|
||||
List<Pair<String, ColumnFamily>> rows;
|
||||
try
|
||||
{
|
||||
DecoratedKey startKey = StorageService.getPartitioner().decorateKey(start_key);
|
||||
|
|
@ -581,14 +580,9 @@ public class CassandraServer implements Cassandra.Iface
|
|||
|
||||
List<KeySlice> keySlices = new ArrayList<KeySlice>(rows.size());
|
||||
boolean reversed = predicate.slice_range != null && predicate.slice_range.reversed;
|
||||
for (Pair<String, Collection<IColumn>> row : rows)
|
||||
for (Pair<String, ColumnFamily> row : rows)
|
||||
{
|
||||
Collection<IColumn> columns = row.right;
|
||||
List<ColumnOrSuperColumn> thriftifiedColumns;
|
||||
if (DatabaseDescriptor.getColumnFamilyType(keyspace, column_parent.column_family).equals("Standard"))
|
||||
thriftifiedColumns = thriftifyColumns(columns, reversed);
|
||||
else
|
||||
thriftifiedColumns = thriftifySuperColumns(columns, reversed);
|
||||
List<ColumnOrSuperColumn> thriftifiedColumns = thriftifyColumnFamily(row.right, column_parent.super_column != null, reversed);
|
||||
keySlices.add(new KeySlice(row.left, thriftifiedColumns));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -512,7 +512,7 @@ public class StorageProxy implements StorageProxyMBean
|
|||
return rows;
|
||||
}
|
||||
|
||||
static List<Pair<String, Collection<IColumn>>> getRangeSlice(RangeSliceCommand command, int consistency_level) throws IOException, UnavailableException, TimedOutException
|
||||
static List<Pair<String, ColumnFamily>> getRangeSlice(RangeSliceCommand command, int consistency_level) throws IOException, UnavailableException, TimedOutException
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
TokenMetadata tokenMetadata = StorageService.instance().getTokenMetadata();
|
||||
|
|
@ -577,18 +577,17 @@ public class StorageProxy implements StorageProxyMBean
|
|||
}
|
||||
while (!endPoint.equals(startEndpoint));
|
||||
|
||||
List<Pair<String, Collection<IColumn>>> results = new ArrayList<Pair<String, Collection<IColumn>>>(rows.size());
|
||||
List<Pair<String, ColumnFamily>> results = new ArrayList<Pair<String, ColumnFamily>>(rows.size());
|
||||
for (Map.Entry<String, ColumnFamily> entry : rows.entrySet())
|
||||
{
|
||||
ColumnFamily cf = entry.getValue();
|
||||
Collection<IColumn> columns = (cf == null) ? Collections.<IColumn>emptyList() : cf.getSortedColumns();
|
||||
results.add(new Pair<String, Collection<IColumn>>(entry.getKey(), columns));
|
||||
results.add(new Pair<String, ColumnFamily>(entry.getKey(), cf));
|
||||
}
|
||||
Collections.sort(results, new Comparator<Pair<String, Collection<IColumn>>>()
|
||||
Collections.sort(results, new Comparator<Pair<String, ColumnFamily>>()
|
||||
{
|
||||
public int compare(Pair<String, Collection<IColumn>> o1, Pair<String, Collection<IColumn>> o2)
|
||||
public int compare(Pair<String, ColumnFamily> o1, Pair<String, ColumnFamily> o2)
|
||||
{
|
||||
return keyComparator.compare(o1.left, o2.left);
|
||||
return keyComparator.compare(o1.left, o2.left);
|
||||
}
|
||||
});
|
||||
rangeStats.add(System.currentTimeMillis() - startTime);
|
||||
|
|
|
|||
|
|
@ -533,9 +533,8 @@ class TestMutations(CassandraTester):
|
|||
cp = ColumnParent('Super3', 'sc1')
|
||||
result = client.get_range_slice("Keyspace2", cp, SlicePredicate(column_names=['col1', 'col3']), 'key2', 'key4', 5, ConsistencyLevel.ONE)
|
||||
assert len(result) == 3
|
||||
sc = result[0].columns[0].super_column
|
||||
assert sc.columns[0].name == 'col1'
|
||||
assert sc.columns[1].name == 'col3'
|
||||
assert result[0].columns[0].column.name == 'col1'
|
||||
assert result[0].columns[1].column.name == 'col3'
|
||||
|
||||
cp = ColumnParent('Super3')
|
||||
result = client.get_range_slice("Keyspace2", cp, SlicePredicate(column_names=['sc1']), 'key2', 'key4', 5, ConsistencyLevel.ONE)
|
||||
|
|
|
|||
Loading…
Reference in New Issue