use of org.apache.cassandra.cql3.ColumnSpecification in project cassandra by apache.
the class CQLSSTableWriter method rawAddRow.
/**
* Adds a new row to the writer given already serialized values.
* <p>
* This is equivalent to the other rawAddRow methods, but takes a map whose
* keys are the names of the columns to add instead of taking a list of the
* values in the order of the insert statement used during construction of
* this write.
*
* @param values a map of colum name to column values representing the new
* row to add. Note that if a column is not part of the map, it's value will
* be {@code null}. If the map contains keys that does not correspond to one
* of the column of the insert statement used when creating this writer, the
* the corresponding value is ignored.
* @return this writer.
*/
public CQLSSTableWriter rawAddRow(Map<String, ByteBuffer> values) throws InvalidRequestException, IOException {
int size = Math.min(values.size(), boundNames.size());
List<ByteBuffer> rawValues = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
ColumnSpecification spec = boundNames.get(i);
rawValues.add(values.get(spec.name.toString()));
}
return rawAddRow(rawValues);
}
use of org.apache.cassandra.cql3.ColumnSpecification in project cassandra by apache.
the class SingleColumnRelation method newINRestriction.
@Override
protected Restriction newINRestriction(TableMetadata table, VariableSpecifications boundNames) {
ColumnMetadata columnDef = table.getExistingColumn(entity);
List<? extends ColumnSpecification> receivers = toReceivers(columnDef);
List<Term> terms = toTerms(receivers, inValues, table.keyspace, boundNames);
if (terms == null) {
Term term = toTerm(receivers, value, table.keyspace, boundNames);
return new SingleColumnRestriction.InRestrictionWithMarker(columnDef, (Lists.Marker) term);
}
// An IN restrictions with only one element is the same than an EQ restriction
if (terms.size() == 1)
return new SingleColumnRestriction.EQRestriction(columnDef, terms.get(0));
return new SingleColumnRestriction.InRestrictionWithValues(columnDef, terms);
}
use of org.apache.cassandra.cql3.ColumnSpecification in project cassandra by apache.
the class BurnTestUtil method generateRows.
public static ResultMessage.Rows generateRows(int idx, SizeCaps sizeCaps) {
Random rnd = new Random(idx);
List<ColumnSpecification> columns = new ArrayList<>();
for (int i = 0; i < sizeCaps.columnCountCap; i++) {
columns.add(new ColumnSpecification("ks", "cf", new ColumnIdentifier(bytes(rnd, 5, 10), BytesType.instance), BytesType.instance));
}
List<List<ByteBuffer>> rows = new ArrayList<>();
int count = rnd.nextInt(sizeCaps.rowsCountCap);
for (int i = 0; i < count; i++) {
List<ByteBuffer> row = new ArrayList<>();
for (int j = 0; j < sizeCaps.columnCountCap; j++) row.add(bytes(rnd, sizeCaps.valueMinSize, sizeCaps.valueMaxSize));
rows.add(row);
}
ResultSet resultSet = new ResultSet(new ResultSet.ResultMetadata(columns), rows);
return new ResultMessage.Rows(resultSet);
}
use of org.apache.cassandra.cql3.ColumnSpecification in project cassandra by apache.
the class RowUtil method toIter.
public static Iterator<Object[]> toIter(List<ColumnSpecification> columnSpecs, Iterator<UntypedResultSet.Row> rs) {
Iterator<List<ByteBuffer>> iter = Iterators.transform(rs, (row) -> {
List<ByteBuffer> bbs = new ArrayList<>(columnSpecs.size());
for (int i = 0; i < columnSpecs.size(); i++) {
ColumnSpecification columnSpec = columnSpecs.get(i);
bbs.add(row.getBytes(columnSpec.name.toString()));
}
return bbs;
});
return toIterInternal(columnSpecs, Lists.newArrayList(iter));
}
use of org.apache.cassandra.cql3.ColumnSpecification in project cassandra by apache.
the class RowUtil method toIterInternal.
private static Iterator<Object[]> toIterInternal(List<ColumnSpecification> columnSpecs, List<List<ByteBuffer>> rs) {
return Iterators.transform(rs.iterator(), (row) -> {
Object[] objectRow = new Object[columnSpecs.size()];
for (int i = 0; i < columnSpecs.size(); i++) {
ColumnSpecification columnSpec = columnSpecs.get(i);
ByteBuffer bb = row.get(i);
if (bb != null)
objectRow[i] = columnSpec.type.getSerializer().deserialize(bb);
}
return objectRow;
});
}
Aggregations