use of org.apache.cassandra.thrift.ColumnOrSuperColumn in project logprocessing by cloudian.
the class CassandraClient method insert.
/** Inserts columns into a column family in a given row. */
public void insert(byte[] key, String columnFamily, Column[] columns, ConsistencyLevel consistencyLevel) throws IOException {
List<Mutation> mutationList = new ArrayList<Mutation>();
for (int i = 0; i < columns.length; i++) {
Mutation mutation = new Mutation();
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
cosc.column = columns[i];
mutation.setColumn_or_supercolumn(cosc);
mutationList.add(mutation);
}
Map<String, List<Mutation>> innerMutationMap = new HashMap<String, List<Mutation>>();
innerMutationMap.put(columnFamily, mutationList);
//Map<byte[], Map<String, List<Mutation>>> mutationMap = new HashMap<byte[], Map<String, List<Mutation>>>();
//balaji
Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
mutationMap.put(ByteBuffer.wrap(key), innerMutationMap);
batchMutate(mutationMap, consistencyLevel);
}
use of org.apache.cassandra.thrift.ColumnOrSuperColumn in project brisk by riptano.
the class CassandraStorage method putNext.
public void putNext(Tuple t) throws ExecException, IOException {
ByteBuffer key = objToBB(t.get(0));
DefaultDataBag pairs = (DefaultDataBag) t.get(1);
ArrayList<Mutation> mutationList = new ArrayList<Mutation>();
CfDef cfDef = getCfDef();
List<AbstractType> marshallers = getDefaultMarshallers(cfDef);
Map<ByteBuffer, AbstractType> validators = getValidatorMap(cfDef);
try {
for (Tuple pair : pairs) {
Mutation mutation = new Mutation();
if (// supercolumn
DataType.findType(pair.get(1)) == DataType.BAG) {
org.apache.cassandra.thrift.SuperColumn sc = new org.apache.cassandra.thrift.SuperColumn();
sc.name = objToBB(pair.get(0));
ArrayList<org.apache.cassandra.thrift.Column> columns = new ArrayList<org.apache.cassandra.thrift.Column>();
for (Tuple subcol : (DefaultDataBag) pair.get(1)) {
org.apache.cassandra.thrift.Column column = new org.apache.cassandra.thrift.Column();
column.name = objToBB(subcol.get(0));
column.value = objToBB(subcol.get(1));
column.setTimestamp(System.currentTimeMillis() * 1000);
columns.add(column);
}
if (// a deletion
columns.isEmpty()) {
mutation.deletion = new Deletion();
mutation.deletion.super_column = objToBB(pair.get(0));
mutation.deletion.setTimestamp(System.currentTimeMillis() * 1000);
} else {
sc.columns = columns;
mutation.column_or_supercolumn = new ColumnOrSuperColumn();
mutation.column_or_supercolumn.super_column = sc;
}
} else // assume column since it couldn't be anything else
{
if (pair.get(1) == null) {
mutation.deletion = new Deletion();
mutation.deletion.predicate = new org.apache.cassandra.thrift.SlicePredicate();
mutation.deletion.predicate.column_names = Arrays.asList(objToBB(pair.get(0)));
mutation.deletion.setTimestamp(System.currentTimeMillis() * 1000);
} else {
org.apache.cassandra.thrift.Column column = new org.apache.cassandra.thrift.Column();
column.name = marshallers.get(0).decompose((pair.get(0)));
if (validators.get(column.name) == null)
// Have to special case BytesType to convert DataByteArray into ByteBuffer
if (marshallers.get(1) instanceof BytesType)
column.value = objToBB(pair.get(1));
else
column.value = marshallers.get(1).decompose(pair.get(1));
else
column.value = validators.get(column.name).decompose(pair.get(1));
column.setTimestamp(System.currentTimeMillis() * 1000);
mutation.column_or_supercolumn = new ColumnOrSuperColumn();
mutation.column_or_supercolumn.column = column;
}
}
mutationList.add(mutation);
}
} catch (ClassCastException e) {
throw new IOException(e + " Output must be (key, {(column,value)...}) for ColumnFamily or (key, {supercolumn:{(column,value)...}...}) for SuperColumnFamily");
}
try {
writer.write(key, mutationList);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
use of org.apache.cassandra.thrift.ColumnOrSuperColumn in project scale7-pelops by s7.
the class Mutator method writeColumnInternal.
private void writeColumnInternal(String colFamily, Bytes rowKey, Column column) {
safeGetRowKey(rowKey);
validateColumn(column);
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
cosc.setColumn(column);
Mutation mutation = new Mutation();
mutation.setColumn_or_supercolumn(cosc);
getMutationList(colFamily, rowKey).add(mutation);
}
use of org.apache.cassandra.thrift.ColumnOrSuperColumn in project scale7-pelops by s7.
the class Mutator method writeSubColumnsInternal.
/**
* Writes multiple sub-column values to a super column.
*
* @param colFamily The column family
* @param rowKey The key of the row to modify
* @param colName The name of the super column
* @param subColumns A list of the sub-columns to write
*/
private void writeSubColumnsInternal(String colFamily, Bytes rowKey, Bytes colName, List<Column> subColumns) {
safeGetRowKey(rowKey);
validateColumnName(colName);
validateColumns(subColumns);
SuperColumn scol = new SuperColumn(nullSafeGet(colName), subColumns);
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
cosc.setSuper_column(scol);
Mutation mutation = new Mutation();
mutation.setColumn_or_supercolumn(cosc);
getMutationList(colFamily, rowKey).add(mutation);
}
use of org.apache.cassandra.thrift.ColumnOrSuperColumn in project scale7-pelops by s7.
the class Mutator method writeSubCounterColumns.
/**
* Writes multiple sub-counter-column values to a super column.
*
* @param colFamily The column family
* @param rowKey The key of the row to modify
* @param colName The name of the super column
* @param subColumns A list of the sub-counter-columns to write
*/
public Mutator writeSubCounterColumns(String colFamily, Bytes rowKey, Bytes colName, List<CounterColumn> subColumns) {
safeGetRowKey(rowKey);
validateColumnName(colName);
validateCounterColumns(subColumns);
CounterSuperColumn scol = new CounterSuperColumn(nullSafeGet(colName), subColumns);
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
cosc.setCounter_super_column(scol);
Mutation mutation = new Mutation();
mutation.setColumn_or_supercolumn(cosc);
getMutationList(colFamily, rowKey).add(mutation);
return this;
}
Aggregations