use of org.apache.cassandra.db.marshal.AbstractType 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.db.marshal.AbstractType in project brisk by riptano.
the class CassandraStorage method columnToTuple.
private Tuple columnToTuple(ByteBuffer name, IColumn col, CfDef cfDef) throws IOException {
Tuple pair = TupleFactory.getInstance().newTuple(2);
List<AbstractType> marshallers = getDefaultMarshallers(cfDef);
Map<ByteBuffer, AbstractType> validators = getValidatorMap(cfDef);
if (col instanceof Column) {
// standard
pair.set(0, marshallers.get(0).compose(name));
if (validators.get(name) == null)
// Have to special case BytesType because compose returns a ByteBuffer
if (marshallers.get(1) instanceof BytesType)
pair.set(1, new DataByteArray(ByteBufferUtil.getArray(col.value())));
else
pair.set(1, marshallers.get(1).compose(col.value()));
else
pair.set(1, validators.get(name).compose(col.value()));
return pair;
}
// super
ArrayList<Tuple> subcols = new ArrayList<Tuple>();
for (IColumn subcol : col.getSubColumns()) subcols.add(columnToTuple(subcol.name(), subcol, cfDef));
pair.set(1, new DefaultDataBag(subcols));
return pair;
}
use of org.apache.cassandra.db.marshal.AbstractType in project brisk by riptano.
the class CassandraStorage method getDefaultMarshallers.
private List<AbstractType> getDefaultMarshallers(CfDef cfDef) throws IOException {
ArrayList<AbstractType> marshallers = new ArrayList<AbstractType>();
AbstractType comparator = null;
AbstractType default_validator = null;
try {
comparator = TypeParser.parse(cfDef.comparator_type);
default_validator = TypeParser.parse(cfDef.default_validation_class);
} catch (ConfigurationException e) {
throw new IOException(e);
}
marshallers.add(comparator);
marshallers.add(default_validator);
return marshallers;
}
use of org.apache.cassandra.db.marshal.AbstractType in project brisk by riptano.
the class BriskServer method seekToSubColumn.
private Integer seekToSubColumn(CFMetaData metadata, FileDataInput file, ByteBuffer sblockId, List<IndexHelper.IndexInfo> indexList) throws IOException {
// column count
file.readInt();
/* get the various column ranges we have to read */
AbstractType comparator = metadata.comparator;
int index = IndexHelper.indexFor(sblockId, indexList, comparator, false);
if (index == indexList.size())
return null;
IndexHelper.IndexInfo indexInfo = indexList.get(index);
if (comparator.compare(sblockId, indexInfo.firstName) < 0)
return null;
FileMark mark = file.mark();
FileUtils.skipBytesFully(file, indexInfo.offset);
while (file.bytesPastMark(mark) < indexInfo.offset + indexInfo.width) {
Integer dataLength = isSubBlockFound(metadata, file, sblockId);
if (dataLength == null)
return null;
if (dataLength < 0)
continue;
return dataLength;
}
return null;
}
use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.
the class DropAggregateStatement method announceMigration.
public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws RequestValidationException {
Collection<Function> olds = Schema.instance.getFunctions(functionName);
if (!argsPresent && olds != null && olds.size() > 1)
throw new InvalidRequestException(String.format("'DROP AGGREGATE %s' matches multiple function definitions; " + "specify the argument types by issuing a statement like " + "'DROP AGGREGATE %s (type, type, ...)'. Hint: use cqlsh " + "'DESCRIBE AGGREGATE %s' command to find all overloads", functionName, functionName, functionName));
Function old = null;
if (argsPresent) {
if (Schema.instance.getKeyspaceMetadata(functionName.keyspace) != null) {
List<AbstractType<?>> argTypes = new ArrayList<>(argRawTypes.size());
for (CQL3Type.Raw rawType : argRawTypes) argTypes.add(prepareType("arguments", rawType));
old = Schema.instance.findFunction(functionName, argTypes).orElse(null);
}
if (old == null || !(old instanceof AggregateFunction)) {
if (ifExists)
return null;
// just build a nicer error message
StringBuilder sb = new StringBuilder();
for (CQL3Type.Raw rawType : argRawTypes) {
if (sb.length() > 0)
sb.append(", ");
sb.append(rawType);
}
throw new InvalidRequestException(String.format("Cannot drop non existing aggregate '%s(%s)'", functionName, sb));
}
} else {
if (olds == null || olds.isEmpty() || !(olds.iterator().next() instanceof AggregateFunction)) {
if (ifExists)
return null;
throw new InvalidRequestException(String.format("Cannot drop non existing aggregate '%s'", functionName));
}
old = olds.iterator().next();
}
if (old.isNative())
throw new InvalidRequestException(String.format("Cannot drop aggregate '%s' because it is a " + "native (built-in) function", functionName));
MigrationManager.announceAggregateDrop((UDAggregate) old, isLocalOnly);
return new Event.SchemaChange(Event.SchemaChange.Change.DROPPED, Event.SchemaChange.Target.AGGREGATE, old.name().keyspace, old.name().name, AbstractType.asCQLTypeStringList(old.argTypes()));
}
Aggregations