Search in sources :

Example 31 with AbstractType

use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.

the class CassandraIndex method indexCfsMetadata.

/**
 * Construct the TableMetadata for an index table, the clustering columns in the index table
 * vary dependent on the kind of the indexed value.
 * @param baseCfsMetadata
 * @param indexMetadata
 * @return
 */
public static TableMetadata indexCfsMetadata(TableMetadata baseCfsMetadata, IndexMetadata indexMetadata) {
    Pair<ColumnMetadata, IndexTarget.Type> target = TargetParser.parse(baseCfsMetadata, indexMetadata);
    CassandraIndexFunctions utils = getFunctions(indexMetadata, target);
    ColumnMetadata indexedColumn = target.left;
    AbstractType<?> indexedValueType = utils.getIndexedValueType(indexedColumn);
    TableMetadata.Builder builder = TableMetadata.builder(baseCfsMetadata.keyspace, baseCfsMetadata.indexTableName(indexMetadata), baseCfsMetadata.id).kind(TableMetadata.Kind.INDEX).partitioner(new LocalPartitioner(indexedValueType)).addPartitionKeyColumn(indexedColumn.name, indexedColumn.type).addClusteringColumn("partition_key", baseCfsMetadata.partitioner.partitionOrdering());
    // Adding clustering columns, which depends on the index type.
    builder = utils.addIndexClusteringColumns(builder, baseCfsMetadata, indexedColumn);
    return builder.build().updateIndexTableMetadata(baseCfsMetadata.params);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) AbstractType(org.apache.cassandra.db.marshal.AbstractType) CollectionType(org.apache.cassandra.db.marshal.CollectionType) LocalPartitioner(org.apache.cassandra.dht.LocalPartitioner)

Example 32 with AbstractType

use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.

the class SecondaryIndexTest method assertIndexedCount.

private void assertIndexedCount(ColumnFamilyStore cfs, ByteBuffer col, Object val, int count) {
    ColumnMetadata cdef = cfs.metadata().getColumn(col);
    ReadCommand rc = Util.cmd(cfs).filterOn(cdef.name.toString(), Operator.EQ, ((AbstractType) cdef.cellValueType()).decompose(val)).build();
    Index.Searcher searcher = rc.getIndex(cfs).searcherFor(rc);
    if (count != 0)
        assertNotNull(searcher);
    try (ReadExecutionController executionController = rc.executionController();
        PartitionIterator iter = UnfilteredPartitionIterators.filter(searcher.search(executionController), FBUtilities.nowInSeconds())) {
        assertEquals(count, Util.size(iter));
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) AbstractType(org.apache.cassandra.db.marshal.AbstractType) Index(org.apache.cassandra.index.Index)

Example 33 with AbstractType

use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.

the class SerializationHeader method toComponent.

public Component toComponent() {
    Map<ByteBuffer, AbstractType<?>> staticColumns = new LinkedHashMap<>();
    Map<ByteBuffer, AbstractType<?>> regularColumns = new LinkedHashMap<>();
    for (ColumnMetadata column : columns.statics) staticColumns.put(column.name.bytes, column.type);
    for (ColumnMetadata column : columns.regulars) regularColumns.put(column.name.bytes, column.type);
    return new Component(keyType, clusteringTypes, staticColumns, regularColumns, stats);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) AbstractType(org.apache.cassandra.db.marshal.AbstractType) MetadataComponent(org.apache.cassandra.io.sstable.metadata.MetadataComponent) ByteBuffer(java.nio.ByteBuffer)

Example 34 with AbstractType

use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.

the class SSTableHeaderFix method fixTypeInnerTuple.

private AbstractType<?> fixTypeInnerTuple(TupleType cHeader, TupleType cSchema, boolean droppedColumnMode) {
    if (cHeader.size() != cSchema.size())
        // different number of components - bummer...
        return null;
    List<AbstractType<?>> cHeaderFixed = new ArrayList<>(cHeader.size());
    boolean anyChanged = false;
    for (int i = 0; i < cHeader.size(); i++) {
        AbstractType<?> cHeaderComp = cHeader.type(i);
        AbstractType<?> cHeaderCompFixed = fixTypeInner(cHeaderComp, cSchema.type(i), droppedColumnMode);
        if (cHeaderCompFixed == null)
            // incompatible, bummer...
            return null;
        cHeaderFixed.add(cHeaderCompFixed);
        anyChanged |= cHeaderComp != cHeaderCompFixed;
    }
    if (anyChanged || cSchema.isMultiCell() != cHeader.isMultiCell())
        // TODO this should create a non-frozen tuple type for the sake of handling a dropped, non-frozen UDT
        return new TupleType(cHeaderFixed);
    return cHeader;
}
Also used : AbstractType(org.apache.cassandra.db.marshal.AbstractType) ArrayList(java.util.ArrayList) TupleType(org.apache.cassandra.db.marshal.TupleType)

Example 35 with AbstractType

use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.

the class SSTableHeaderFix method validateColumns.

private Map<ByteBuffer, AbstractType<?>> validateColumns(Descriptor desc, TableMetadata tableMetadata, Map<ByteBuffer, AbstractType<?>> columns, ColumnMetadata.Kind kind) {
    Map<ByteBuffer, AbstractType<?>> target = new LinkedHashMap<>();
    for (Map.Entry<ByteBuffer, AbstractType<?>> nameAndType : columns.entrySet()) {
        ByteBuffer name = nameAndType.getKey();
        AbstractType<?> type = nameAndType.getValue();
        AbstractType<?> fixedType = validateColumn(desc, tableMetadata, kind, name, type);
        if (fixedType == null) {
            error("sstable %s: contains column '%s' of type '%s', which could not be validated", desc, type, logColumnName(name));
            // don't use a "null" type instance
            fixedType = type;
        }
        target.put(name, fixedType);
    }
    return target;
}
Also used : AbstractType(org.apache.cassandra.db.marshal.AbstractType) ByteBuffer(java.nio.ByteBuffer) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

AbstractType (org.apache.cassandra.db.marshal.AbstractType)51 ByteBuffer (java.nio.ByteBuffer)20 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)9 TableMetadata (org.apache.cassandra.schema.TableMetadata)8 List (java.util.List)6 Map (java.util.Map)6 CollectionType (org.apache.cassandra.db.marshal.CollectionType)6 CompositeType (org.apache.cassandra.db.marshal.CompositeType)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 CQL3Type (org.apache.cassandra.cql3.CQL3Type)5 SerializationHeader (org.apache.cassandra.db.SerializationHeader)5 TupleType (org.apache.cassandra.db.marshal.TupleType)5 UserType (org.apache.cassandra.db.marshal.UserType)5 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)4 FieldIdentifier (org.apache.cassandra.cql3.FieldIdentifier)4 Test (org.junit.Test)4 AuditLogContext (org.apache.cassandra.audit.AuditLogContext)3