【发布时间】:2011-06-10 06:24:59
【问题描述】:
我的问题涉及 Cassandra 0.8 和 Pelops。我发现 Pelops 使用相同的 Thrift 命令来读取列切片和计数器列切片。然后,它遍历检索到的 Thrift ColumnOrSuperColumn 对象集合,断言该列(或 counter_column)字段不为空。似乎很明显,对于混合列族,执行这些方法中的任何一个都会失败。
那么,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;
}
【问题讨论】: