2011-06-09 23 views
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; 
} 

回答

1

那么,是否卡桑德拉要求所有的 在列族的列是 是同一类型的?

是的,就目前来说,它确实需要CF包含所有计数器或所有非计数器。然而,

  • This will change,可能只要0.8.1
  • 非柜台绝对不必须是相同的数据类型(字节,长的,UTF8等,都可以在相同的混合行)
相关问题