Search in sources :

Example 11 with ColumnSpecification

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);
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Example 12 with ColumnSpecification

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);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) SingleColumnRestriction(org.apache.cassandra.cql3.restrictions.SingleColumnRestriction)

Example 13 with ColumnSpecification

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);
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Random(java.util.Random) ResultSet(org.apache.cassandra.cql3.ResultSet) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with ColumnSpecification

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));
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ByteBuffer(java.nio.ByteBuffer)

Example 15 with ColumnSpecification

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;
    });
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ColumnSpecification (org.apache.cassandra.cql3.ColumnSpecification)21 ByteBuffer (java.nio.ByteBuffer)11 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)3 AuditEntry (com.ericsson.bss.cassandra.ecaudit.entry.AuditEntry)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 AssignmentTestable (org.apache.cassandra.cql3.AssignmentTestable)2 QueryOptions (org.apache.cassandra.cql3.QueryOptions)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)1 ResultSet (com.datastax.driver.core.ResultSet)1 Session (com.datastax.driver.core.Session)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 UUID (java.util.UUID)1 Parameters (junitparams.Parameters)1 CQLStatement (org.apache.cassandra.cql3.CQLStatement)1