4
我的问题涉及Cassandra 0.8和Pelops。我发现Pelops使用相同的Thrift命令来读取一列的计数列。然后,它遍历Thrift ColumnOrSuperColumn对象的检索集合,断言column(或counter_column)字段不为null。似乎很明显,对于混合列系列,执行这两种方法都会失败。我是否需要为计数器列创建特殊的列族?
那么,Cassandra是否要求列族中的所有列都是相同类型的?
以下代码是Pelops的Selector类的一个片段。
private List<Column> getColumnsFromRow(final ColumnParent colParent, final Bytes rowKey, final SlicePredicate colPredicate, final ConsistencyLevel cLevel) throws PelopsException {
IOperation<List<Column>> operation = new IOperation<List<Column>>() {
@Override
public List<Column> execute(IPooledConnection conn) throws Exception {
List<ColumnOrSuperColumn> apiResult = conn.getAPI().get_slice(safeGetRowKey(rowKey), colParent, colPredicate, cLevel);
return toColumnList(apiResult);
}
};
return tryOperation(operation);
}
private List<CounterColumn> getCounterColumnsFromRow(final ColumnParent colParent, final Bytes rowKey, final SlicePredicate colPredicate, final ConsistencyLevel cLevel) throws PelopsException {
IOperation<List<CounterColumn>> operation = new IOperation<List<CounterColumn>>() {
@Override
public List<CounterColumn> execute(IPooledConnection conn) throws Exception {
List<ColumnOrSuperColumn> apiResult = conn.getAPI().get_slice(safeGetRowKey(rowKey), colParent, colPredicate, cLevel);
return toCounterColumnList(apiResult);
}
};
return tryOperation(operation);
}
private static List<Column> toColumnList(List<ColumnOrSuperColumn> coscList) {
List<Column> columns = new ArrayList<Column>(coscList.size());
for (ColumnOrSuperColumn cosc : coscList) {
assert cosc.column != null : "The column should not be null";
columns.add(cosc.column);
}
return columns;
}
private static List<CounterColumn> toCounterColumnList(List<ColumnOrSuperColumn> coscList) {
List<CounterColumn> columns = new ArrayList<CounterColumn>(coscList.size());
for (ColumnOrSuperColumn cosc : coscList) {
assert cosc.counter_column != null : "The column should not be null";
columns.add(cosc.counter_column);
}
return columns;
}