Search in sources :

Example 51 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class TokenFct method getKeyTypes.

private static AbstractType[] getKeyTypes(TableMetadata metadata) {
    AbstractType[] types = new AbstractType[metadata.partitionKeyColumns().size()];
    int i = 0;
    for (ColumnMetadata def : metadata.partitionKeyColumns()) types[i++] = def.type;
    return types;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) AbstractType(org.apache.cassandra.db.marshal.AbstractType)

Example 52 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class RestrictionSet method mergeRestrictions.

private TreeMap<ColumnMetadata, SingleRestriction> mergeRestrictions(TreeMap<ColumnMetadata, SingleRestriction> restrictions, SingleRestriction restriction) {
    Collection<ColumnMetadata> columnDefs = restriction.getColumnDefs();
    Set<SingleRestriction> existingRestrictions = getRestrictions(columnDefs);
    if (existingRestrictions.isEmpty()) {
        for (ColumnMetadata columnDef : columnDefs) restrictions.put(columnDef, restriction);
    } else {
        for (SingleRestriction existing : existingRestrictions) {
            SingleRestriction newRestriction = mergeRestrictions(existing, restriction);
            for (ColumnMetadata columnDef : columnDefs) restrictions.put(columnDef, newRestriction);
        }
    }
    return restrictions;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 53 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class AbstractClusteringIndexFilter method appendOrderByToCQLString.

protected void appendOrderByToCQLString(TableMetadata metadata, StringBuilder sb) {
    if (reversed) {
        sb.append(" ORDER BY (");
        int i = 0;
        for (ColumnMetadata column : metadata.clusteringColumns()) sb.append(i++ == 0 ? "" : ", ").append(column.name).append(column.type instanceof ReversedType ? " ASC" : " DESC");
        sb.append(')');
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ReversedType(org.apache.cassandra.db.marshal.ReversedType)

Example 54 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class UnfilteredSerializer method serializedRowBodySize.

private long serializedRowBodySize(Row row, SerializationHeader header, long previousUnfilteredSize, int version) {
    long size = 0;
    if (header.isForSSTable())
        size += TypeSizes.sizeofUnsignedVInt(previousUnfilteredSize);
    boolean isStatic = row.isStatic();
    Columns headerColumns = header.columns(isStatic);
    LivenessInfo pkLiveness = row.primaryKeyLivenessInfo();
    Row.Deletion deletion = row.deletion();
    boolean hasComplexDeletion = row.hasComplexDeletion();
    boolean hasAllColumns = (row.size() == headerColumns.size());
    if (!pkLiveness.isEmpty())
        size += header.timestampSerializedSize(pkLiveness.timestamp());
    if (pkLiveness.isExpiring()) {
        size += header.ttlSerializedSize(pkLiveness.ttl());
        size += header.localDeletionTimeSerializedSize(pkLiveness.localExpirationTime());
    }
    if (!deletion.isLive())
        size += header.deletionTimeSerializedSize(deletion.time());
    if (!hasAllColumns)
        size += Columns.serializer.serializedSubsetSize(Collections2.transform(row, ColumnData::column), header.columns(isStatic));
    SearchIterator<ColumnMetadata, ColumnMetadata> si = headerColumns.iterator();
    for (ColumnData data : row) {
        ColumnMetadata column = si.next(data.column());
        assert column != null;
        if (data.column.isSimple())
            size += Cell.serializer.serializedSize((Cell) data, column, pkLiveness, header);
        else
            size += sizeOfComplexColumn((ComplexColumnData) data, column, hasComplexDeletion, pkLiveness, header);
    }
    return size;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) Deletion(org.apache.cassandra.db.rows.Row.Deletion)

Example 55 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class ViewUpdateGenerator method computeLivenessInfoForEntry.

private LivenessInfo computeLivenessInfoForEntry(Row baseRow) {
    // This may change, but is currently an enforced limitation
    assert view.baseNonPKColumnsInViewPK.size() <= 1;
    LivenessInfo baseLiveness = baseRow.primaryKeyLivenessInfo();
    if (view.baseNonPKColumnsInViewPK.isEmpty()) {
        int ttl = baseLiveness.ttl();
        int expirationTime = baseLiveness.localExpirationTime();
        for (Cell cell : baseRow.cells()) {
            if (cell.ttl() > ttl) {
                ttl = cell.ttl();
                expirationTime = cell.localDeletionTime();
            }
        }
        return ttl == baseLiveness.ttl() ? baseLiveness : LivenessInfo.withExpirationTime(baseLiveness.timestamp(), ttl, expirationTime);
    }
    ColumnMetadata baseColumn = view.baseNonPKColumnsInViewPK.get(0);
    Cell cell = baseRow.getCell(baseColumn);
    assert isLive(cell) : "We shouldn't have got there if the base row had no associated entry";
    long timestamp = Math.max(baseLiveness.timestamp(), cell.timestamp());
    return LivenessInfo.withExpirationTime(timestamp, cell.ttl(), cell.localDeletionTime());
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Aggregations

ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)123 Test (org.junit.Test)35 ByteBuffer (java.nio.ByteBuffer)23 Row (org.apache.cassandra.db.rows.Row)17 TableMetadata (org.apache.cassandra.schema.TableMetadata)16 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)15 AbstractType (org.apache.cassandra.db.marshal.AbstractType)8 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)5 java.util (java.util)4 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)4 CollectionType (org.apache.cassandra.db.marshal.CollectionType)4 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 ColumnFilter (org.apache.cassandra.db.filter.ColumnFilter)3 ImmutableBTreePartition (org.apache.cassandra.db.partitions.ImmutableBTreePartition)3 Cell (org.apache.cassandra.db.rows.Cell)3 RowIterator (org.apache.cassandra.db.rows.RowIterator)3 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3