public Column get_column(String table, String key, ColumnPath column_path, int consistency_level) throws InvalidRequestException, NotFoundException { if (logger.isDebugEnabled()) logger.debug("get_column"); ThriftValidation.validateColumnPath(table, column_path); QueryPath path = new QueryPath(column_path.column_family, column_path.super_column); ColumnFamily cfamily = readColumnFamily( new SliceByNamesReadCommand(table, key, path, Arrays.asList(column_path.column)), consistency_level); // TODO can we leverage getSlice here and just check that it returns one column? if (cfamily == null) { throw new NotFoundException(); } Collection<IColumn> columns = null; if (column_path.super_column != null) { IColumn column = cfamily.getColumn(column_path.super_column); if (column != null) { columns = column.getSubColumns(); } } else { columns = cfamily.getSortedColumns(); } if (columns == null || columns.size() == 0) { throw new NotFoundException(); } assert columns.size() == 1; IColumn column = columns.iterator().next(); if (column.isMarkedForDelete()) { throw new NotFoundException(); } return new Column(column.name(), column.value(), column.timestamp()); }
// Don't playa hate, avronate. public GenericArray<Column> avronateSubColumns(Collection<IColumn> columns) { if (columns == null || columns.isEmpty()) return EMPTY_SUBCOLUMNS; GenericData.Array<Column> avroColumns = new GenericData.Array<Column>(columns.size(), Column.SCHEMA$); for (IColumn column : columns) { if (column.isMarkedForDelete()) continue; Column avroColumn = newColumn(column.name(), column.value(), column.timestamp()); avroColumns.add(avroColumn); } return avroColumns; }
private Map<String, ColumnOrSuperColumn> multigetInternal( String keyspace, List<String> keys, ColumnPath cp, ConsistencyLevel level) throws InvalidRequestException, UnavailableException, TimedOutException { AvroValidation.validateColumnPath(keyspace, cp); // FIXME: This is repetitive. byte[] column, super_column; column = cp.column == null ? null : cp.column.array(); super_column = cp.super_column == null ? null : cp.super_column.array(); QueryPath path = new QueryPath(cp.column_family.toString(), column == null ? null : super_column); List<byte[]> nameAsList = Arrays.asList(column == null ? super_column : column); List<ReadCommand> commands = new ArrayList<ReadCommand>(); for (String key : keys) { AvroValidation.validateKey(key); commands.add(new SliceByNamesReadCommand(keyspace, key, path, nameAsList)); } Map<String, ColumnOrSuperColumn> columnFamiliesMap = new HashMap<String, ColumnOrSuperColumn>(); Map<String, Collection<IColumn>> columnsMap = multigetColumns(commands, level); for (ReadCommand command : commands) { ColumnOrSuperColumn columnorsupercolumn; Collection<IColumn> columns = columnsMap.get(command.key); if (columns == null) { columnorsupercolumn = new ColumnOrSuperColumn(); } else { assert columns.size() == 1; IColumn col = columns.iterator().next(); if (col.isMarkedForDelete()) { columnorsupercolumn = new ColumnOrSuperColumn(); } else { columnorsupercolumn = col instanceof org.apache.cassandra.db.Column ? newColumnOrSuperColumn(newColumn(col.name(), col.value(), col.timestamp())) : newColumnOrSuperColumn( newSuperColumn(col.name(), avronateSubColumns(col.getSubColumns()))); } } columnFamiliesMap.put(command.key, columnorsupercolumn); } return columnFamiliesMap; }
public List<Column> thriftifyColumns(Collection<IColumn> columns, boolean reverseOrder) { if (columns == null || columns.isEmpty()) { return EMPTY_COLUMNS; } ArrayList<Column> thriftColumns = new ArrayList<Column>(columns.size()); for (IColumn column : columns) { if (column.isMarkedForDelete()) { continue; } Column thrift_column = new Column(column.name(), column.value(), column.timestamp()); thriftColumns.add(thrift_column); } // we have to do the reversing here, since internally we pass results around in ColumnFamily // objects, which always sort their columns in the "natural" order if (reverseOrder) Collections.reverse(thriftColumns); return thriftColumns; }