@SuppressWarnings("rawtypes")
public Columns columns(Row row)
{
ColumnFamily columnFamily = row.cf;
Columns columns = new Columns();
// Get row's columns iterator skipping clustering column
Iterator<Cell> cellIterator = columnFamily.iterator();
cellIterator.next();
// Stuff for grouping collection columns (sets, lists and maps)
String name;
CollectionType collectionType;
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
CellName cellName = cell.name();
ColumnDefinition columnDefinition = metadata.getColumnDefinition(cellName);
if (columnDefinition == null)
{
continue;
}
AbstractType<?> valueType = columnDefinition.type;
ByteBuffer cellValue = cell.value();
name = cellName.cql3ColumnName(metadata).toString();
if (valueType.isCollection())
{
collectionType = (CollectionType<?>) valueType;
switch (collectionType.kind)
{
case SET:
{
AbstractType<?> type = collectionType.nameComparator();
ByteBuffer value = cellName.collectionElement();
columns.add(ColumnMapper.column(name, value, type));
break;
}
case LIST:
{
AbstractType<?> type = collectionType.valueComparator();
columns.add(ColumnMapper.column(name, cellValue, type));
break;
}
case MAP:
{
AbstractType<?> type = collectionType.valueComparator();
ByteBuffer keyValue = cellName.collectionElement();
AbstractType<?> keyType = collectionType.nameComparator();
String nameSufix = keyType.compose(keyValue).toString();
columns.add(ColumnMapper.column(name, nameSufix, cellValue, type));
break;
}
}
}
else
{
columns.add(ColumnMapper.column(name, cellValue, valueType));
}
}
return columns;
}