Do I need to create a custom column family for counter columns?

My question is about Cassandra 0.8 and Pelops. I found that Pelops uses the same Thrift command to read slice columns as it does to slice counter columns. It then iterates over the extracted set of Thrift objects ColumnOrSuperColumn, asserting that the column field (or counter_column) is not null. It seems obvious that for a mixed column family, any of these methods will fail.

So, does Cassandra require all columns in a column family to be of the same type?

The following code is a fragment of the Selector class from Pelops.

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; } 
+4
source share
1 answer

So does Cassandra require all columns in a column family to be of the same type?

Yes, in the sense that it currently requires the CF to contain all counters or all non-counters. but

  • This will change , possibly as soon as 0.8.1
  • non-counters should definitely not be of the same data type (bytes, long, utf8, etc. all can be mixed on one line)
+1
source

All Articles