org.apache.cassandra.config.ColumnDefinition Java Examples

The following examples show how to use org.apache.cassandra.config.ColumnDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelectStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void updateRestrictionsForRelation(SelectStatement stmt, ColumnDefinition def, SingleColumnRelation relation, VariableSpecifications names) throws InvalidRequestException
{
    switch (def.kind)
    {
        case PARTITION_KEY:
            stmt.keyRestrictions[def.position()] = updateSingleColumnRestriction(def, stmt.keyRestrictions[def.position()], relation, names);
            break;
        case CLUSTERING_COLUMN:
            stmt.columnRestrictions[def.position()] = updateSingleColumnRestriction(def, stmt.columnRestrictions[def.position()], relation, names);
            break;
        case COMPACT_VALUE:
            throw new InvalidRequestException(String.format("Predicates on the non-primary-key column (%s) of a COMPACT table are not yet supported", def.name));
        case REGULAR:
        case STATIC:
            // We only all IN on the row key and last clustering key so far, never on non-PK columns, and this even if there's an index
            Restriction r = updateSingleColumnRestriction(def, stmt.metadataRestrictions.get(def.name), relation, names);
            if (r.isIN() && !((Restriction.IN)r).canHaveOnlyOneValue())
                // Note: for backward compatibility reason, we conside a IN of 1 value the same as a EQ, so we let that slide.
                throw new InvalidRequestException(String.format("IN predicates on non-primary-key columns (%s) is not yet supported", def.name));
            stmt.metadataRestrictions.put(def.name, r);
            break;
    }
}
 
Example #2
Source File: SelectStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static void addValue(Selection.ResultSetBuilder result, ColumnDefinition def, CQL3Row row, QueryOptions options)
{
    if (row == null)
    {
        result.add((ByteBuffer)null);
        return;
    }

    if (def.type.isMultiCell())
    {
        List<Cell> cells = row.getMultiCellColumn(def.name);
        ByteBuffer buffer = cells == null
                         ? null
                         : ((CollectionType)def.type).serializeForNativeProtocol(cells, options.getProtocolVersion());
        result.add(buffer);
        return;
    }

    result.add(row.getColumn(def.name));
}
 
Example #3
Source File: ColumnConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static boolean mapAppliesTo(ColumnCondition.CollectionBound bound, Map<ByteBuffer, ByteBuffer> conditionValues, Map<ByteBuffer, ByteBuffer> columnValues)
{
    CFMetaData cfm = CFMetaData.compile("create table foo(a int PRIMARY KEY, b map<int, int>)", "ks");
    Map<ByteBuffer, CollectionType> typeMap = new HashMap<>();
    typeMap.put(ByteBufferUtil.bytes("b"), MapType.getInstance(Int32Type.instance, Int32Type.instance, true));
    CompoundSparseCellNameType.WithCollection nameType = new CompoundSparseCellNameType.WithCollection(Collections.EMPTY_LIST, ColumnToCollectionType.getInstance(typeMap));
    ColumnDefinition definition = new ColumnDefinition(cfm, ByteBufferUtil.bytes("b"), MapType.getInstance(Int32Type.instance, Int32Type.instance, true), 0, ColumnDefinition.Kind.REGULAR);

    List<Cell> cells = new ArrayList<>(columnValues.size());
    if (columnValues != null)
    {
        for (Map.Entry<ByteBuffer, ByteBuffer> entry : columnValues.entrySet())
            cells.add(new BufferCell(nameType.create(Composites.EMPTY, definition, entry.getKey()), entry.getValue()));
    }

    return bound.mapAppliesTo(MapType.getInstance(Int32Type.instance, Int32Type.instance, true), cells.iterator(), conditionValues, bound.operator);
}
 
Example #4
Source File: RowIndex.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Override
public void validateOptions() throws ConfigurationException {
    Log.debug("Validating");
    try {
        ColumnDefinition columnDefinition = columnDefs.iterator().next();
        if (baseCfs != null) {
            new RowIndexConfig(baseCfs.metadata, columnDefinition.getIndexOptions());
            Log.debug("Index options are valid");
        } else {
            Log.debug("Validation skipped");
        }
    } catch (Exception e) {
        String message = "Error while validating index options: " + e.getMessage();
        Log.error(e, message);
        throw new ConfigurationException(message, e);
    }
}
 
Example #5
Source File: ColumnConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static boolean setAppliesTo(ColumnCondition.CollectionBound bound, Set<ByteBuffer> conditionValues, List<ByteBuffer> columnValues)
{
    CFMetaData cfm = CFMetaData.compile("create table foo(a int PRIMARY KEY, b int, c set<int>)", "ks");
    Map<ByteBuffer, CollectionType> typeMap = new HashMap<>();
    typeMap.put(ByteBufferUtil.bytes("c"), SetType.getInstance(Int32Type.instance, true));
    CompoundSparseCellNameType.WithCollection nameType = new CompoundSparseCellNameType.WithCollection(Collections.EMPTY_LIST, ColumnToCollectionType.getInstance(typeMap));
    ColumnDefinition definition = new ColumnDefinition(cfm, ByteBufferUtil.bytes("c"), SetType.getInstance(Int32Type.instance, true), 0, ColumnDefinition.Kind.REGULAR);

    List<Cell> cells = new ArrayList<>(columnValues.size());
    if (columnValues != null)
    {
        for (int i = 0; i < columnValues.size(); i++)
        {
            ByteBuffer key = columnValues.get(i);
            cells.add(new BufferCell(nameType.create(Composites.EMPTY, definition, key), ByteBufferUtil.EMPTY_BYTE_BUFFER));
        };
    }

    return bound.setAppliesTo(SetType.getInstance(Int32Type.instance, true), cells == null ? null : cells.iterator(), conditionValues, bound.operator);
}
 
Example #6
Source File: Mapping.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if this is consistent with the specified column family metadata.
 *
 * @param metadata A column family metadata.
 */
public void validate(CFMetaData metadata) {
    for (Map.Entry<String, ColumnMapper> entry : columnMappers.entrySet()) {

        String name = entry.getKey();
        ColumnMapper columnMapper = entry.getValue();
        ByteBuffer columnName = UTF8Type.instance.decompose(name);

        ColumnDefinition columnDefinition = metadata.getColumnDefinition(columnName);
        if (columnDefinition == null) {
            throw new RuntimeException("No column definition for mapper " + name);
        }

        if (columnDefinition.isStatic()) {
            throw new RuntimeException("Lucene indexes are not allowed on static columns as " + name);
        }

        AbstractType<?> type = columnDefinition.type;
        if (!columnMapper.supports(type)) {
            throw new RuntimeException(String.format("Type '%s' is not supported by mapper '%s'", type, name));
        }
    }
}
 
Example #7
Source File: ColumnIdentifier.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public ColumnIdentifier prepare(CFMetaData cfm)
{
    AbstractType<?> comparator = cfm.comparator.asAbstractType();
    if (cfm.getIsDense() || comparator instanceof CompositeType || comparator instanceof UTF8Type)
        return new ColumnIdentifier(text, true);

    // We have a Thrift-created table with a non-text comparator.  We need to parse column names with the comparator
    // to get the correct ByteBuffer representation.  However, this doesn't apply to key aliases, so we need to
    // make a special check for those and treat them normally.  See CASSANDRA-8178.
    ByteBuffer bufferName = ByteBufferUtil.bytes(text);
    for (ColumnDefinition def : cfm.partitionKeyColumns())
    {
        if (def.name.bytes.equals(bufferName))
            return new ColumnIdentifier(text, true);
    }
    return new ColumnIdentifier(comparator.fromString(rawText), text);
}
 
Example #8
Source File: SelectStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void processOrderingClause(SelectStatement stmt, CFMetaData cfm) throws InvalidRequestException
{
    verifyOrderingIsAllowed(stmt);

    // If we order post-query (see orderResults), the sorted column needs to be in the ResultSet for sorting, even if we don't
    // ultimately ship them to the client (CASSANDRA-4911).
    if (stmt.keyIsInRelation)
    {
        stmt.orderingIndexes = new HashMap<>();
        for (ColumnIdentifier.Raw rawColumn : stmt.parameters.orderings.keySet())
        {
            ColumnIdentifier column = rawColumn.prepare(cfm);
            final ColumnDefinition def = cfm.getColumnDefinition(column);
            if (def == null)
                handleUnrecognizedOrderingColumn(column);

            int index = indexOf(def, stmt.selection);
            if (index < 0)
                index = stmt.selection.addColumnForOrdering(def);
            stmt.orderingIndexes.put(def.name, index);
        }
    }
    stmt.isReversed = isReversed(stmt, cfm);
}
 
Example #9
Source File: SelectStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/** Returns a pair of (hasQueriableIndex, hasQueriableClusteringColumnIndex) */
private boolean[] processRelationEntity(SelectStatement stmt,
                                        SecondaryIndexManager indexManager,
                                        Relation relation,
                                        ColumnIdentifier entity,
                                        ColumnDefinition def) throws InvalidRequestException
{
    if (def == null)
        handleUnrecognizedEntity(entity, relation);

    SecondaryIndex index = indexManager.getIndexForColumn(def.name.bytes);
    if (index != null && index.supportsOperator(relation.operator()))
    {
        stmt.restrictedColumns.put(def, Boolean.TRUE);
        return new boolean[]{true, def.kind == ColumnDefinition.Kind.CLUSTERING_COLUMN};
    }

    stmt.restrictedColumns.put(def, Boolean.FALSE);
    return new boolean[]{false, false};
}
 
Example #10
Source File: ExtendedFilter.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private ByteBuffer extractDataValue(ColumnDefinition def, ByteBuffer rowKey, ColumnFamily data, Composite prefix)
{
    switch (def.kind)
    {
        case PARTITION_KEY:
            return def.isOnAllComponents()
                 ? rowKey
                 : ((CompositeType)data.metadata().getKeyValidator()).split(rowKey)[def.position()];
        case CLUSTERING_COLUMN:
            return prefix.get(def.position());
        case REGULAR:
            CellName cname = prefix == null
                           ? data.getComparator().cellFromByteBuffer(def.name.bytes)
                           : data.getComparator().create(prefix, def);

            Cell cell = data.getColumn(cname);
            return cell == null ? null : cell.value();
        case COMPACT_VALUE:
            assert data.getColumnCount() == 1;
            return data.getSortedColumns().iterator().next().value();
    }
    throw new AssertionError();
}
 
Example #11
Source File: SSTableReader.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static SSTableReader open(Descriptor descriptor) throws IOException
{
    CFMetaData metadata;
    if (descriptor.cfname.contains(SECONDARY_INDEX_NAME_SEPARATOR))
    {
        int i = descriptor.cfname.indexOf(SECONDARY_INDEX_NAME_SEPARATOR);
        String parentName = descriptor.cfname.substring(0, i);
        CFMetaData parent = Schema.instance.getCFMetaData(descriptor.ksname, parentName);
        ColumnDefinition def = parent.getColumnDefinitionForIndex(descriptor.cfname.substring(i + 1));
        metadata = CFMetaData.newIndexMetadata(parent, def, SecondaryIndex.getIndexComparator(parent, def));
    }
    else
    {
        metadata = Schema.instance.getCFMetaData(descriptor.ksname, descriptor.cfname);
    }
    return open(descriptor, metadata);
}
 
Example #12
Source File: SecondaryIndexManager.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Drops and adds new indexes associated with the underlying CF
 */
public void reload()
{
    // figure out what needs to be added and dropped.
    // future: if/when we have modifiable settings for secondary indexes,
    // they'll need to be handled here.
    Collection<ByteBuffer> indexedColumnNames = indexesByColumn.keySet();
    for (ByteBuffer indexedColumn : indexedColumnNames)
    {
        ColumnDefinition def = baseCfs.metadata.getColumnDefinition(indexedColumn);
        if (def == null || def.getIndexType() == null)
            removeIndexedColumn(indexedColumn);
    }

    // TODO: allow all ColumnDefinition type
    for (ColumnDefinition cdef : baseCfs.metadata.allColumns())
        if (cdef.getIndexType() != null && !indexedColumnNames.contains(cdef.name.bytes))
            addIndexedColumn(cdef);

    for (SecondaryIndex index : allIndexes)
        index.reload();
}
 
Example #13
Source File: DeleteStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
protected void validateWhereClauseForConditions() throws InvalidRequestException
{
    Iterator<ColumnDefinition> iterator = Iterators.concat(cfm.partitionKeyColumns().iterator(), cfm.clusteringColumns().iterator());
    while (iterator.hasNext())
    {
        ColumnDefinition def = iterator.next();
        Restriction restriction = processedKeys.get(def.name);
        if (restriction == null || !(restriction.isEQ() || restriction.isIN()))
        {
            throw new InvalidRequestException(
                    String.format("DELETE statements must restrict all PRIMARY KEY columns with equality relations in order " +
                                  "to use IF conditions, but column '%s' is not restricted", def.name));
        }
    }

}
 
Example #14
Source File: SelectStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private int indexOf(final ColumnDefinition def, Iterator<ColumnDefinition> defs)
{
    return Iterators.indexOf(defs, new Predicate<ColumnDefinition>()
                                   {
                                       public boolean apply(ColumnDefinition n)
                                       {
                                           return def.name.equals(n.name);
                                       }
                                   });
}
 
Example #15
Source File: UpdateStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
protected ModificationStatement prepareInternal(CFMetaData cfm, VariableSpecifications boundNames, Attributes attrs) throws InvalidRequestException
{
    UpdateStatement stmt = new UpdateStatement(ModificationStatement.StatementType.UPDATE, boundNames.size(), cfm, attrs);

    for (Pair<ColumnIdentifier.Raw, Operation.RawUpdate> entry : updates)
    {
        ColumnDefinition def = cfm.getColumnDefinition(entry.left.prepare(cfm));
        if (def == null)
            throw new InvalidRequestException(String.format("Unknown identifier %s", entry.left));

        Operation operation = entry.right.prepare(keyspace(), def);
        operation.collectMarkerSpecification(boundNames);

        switch (def.kind)
        {
            case PARTITION_KEY:
            case CLUSTERING_COLUMN:
                throw new InvalidRequestException(String.format("PRIMARY KEY part %s found in SET part", entry.left));
            default:
                stmt.addOperation(operation);
                break;
        }
    }

    stmt.processWhereClause(whereClause, boundNames);
    return stmt;
}
 
Example #16
Source File: CompositesIndexOnRegular.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static CellNameType buildIndexComparator(CFMetaData baseMetadata, ColumnDefinition columnDef)
{
    int prefixSize = columnDef.position();
    List<AbstractType<?>> types = new ArrayList<AbstractType<?>>(prefixSize + 1);
    types.add(SecondaryIndex.keyComparator);
    for (int i = 0; i < prefixSize; i++)
        types.add(baseMetadata.comparator.subtype(i));
    return new CompoundDenseCellNameType(types);
}
 
Example #17
Source File: Selection.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
protected Selection(List<ColumnDefinition> columns, List<ColumnSpecification> metadata, boolean collectTimestamps, boolean collectTTLs)
{
    this.columns = columns;
    this.metadata = new ResultSet.Metadata(metadata);
    this.collectTimestamps = collectTimestamps;
    this.collectTTLs = collectTTLs;
}
 
Example #18
Source File: Selection.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public SimpleSelection(List<ColumnDefinition> columns, List<ColumnSpecification> metadata, boolean isWildcard)
{
    /*
     * In theory, even a simple selection could have multiple time the same column, so we
     * could filter those duplicate out of columns. But since we're very unlikely to
     * get much duplicate in practice, it's more efficient not to bother.
     */
    super(columns, metadata, false, false);
    this.isWildcard = isWildcard;
}
 
Example #19
Source File: Selection.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Override
public int addColumnForOrdering(ColumnDefinition c)
{
    int index = super.addColumnForOrdering(c);
    selectors.add(new SimpleSelector(c.name.toString(), index, c.type));
    return index;
}
 
Example #20
Source File: RowService.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new {@link RowService} for the specified {@link ColumnFamilyStore} and {@link ColumnDefinition}.
 *
 * @param baseCfs          The {@link ColumnFamilyStore} associated to the managed index.
 * @param columnDefinition The {@link ColumnDefinition} of the indexed column.
 * @return A new {@link RowService} for the specified {@link ColumnFamilyStore} and {@link ColumnDefinition}.
 */
public static RowService build(ColumnFamilyStore baseCfs, ColumnDefinition columnDefinition) {
    int clusteringPosition = baseCfs.metadata.clusteringColumns().size();
    if (clusteringPosition > 0) {
        return new RowServiceWide(baseCfs, columnDefinition);
    } else {
        return new RowServiceSkinny(baseCfs, columnDefinition);
    }
}
 
Example #21
Source File: CreateTableStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private List<ColumnDefinition> getColumns(CFMetaData cfm)
{
    List<ColumnDefinition> columnDefs = new ArrayList<>(columns.size());
    Integer componentIndex = comparator.isCompound() ? comparator.clusteringPrefixSize() : null;
    for (Map.Entry<ColumnIdentifier, AbstractType> col : columns.entrySet())
    {
        ColumnIdentifier id = col.getKey();
        columnDefs.add(staticColumns.contains(id)
                       ? ColumnDefinition.staticDef(cfm, col.getKey().bytes, col.getValue(), componentIndex)
                       : ColumnDefinition.regularDef(cfm, col.getKey().bytes, col.getValue(), componentIndex));
    }

    return columnDefs;
}
 
Example #22
Source File: SecondaryIndex.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index comparator for index backed by CFS, or null.
 *
 * Note: it would be cleaner to have this be a member method. However we need this when opening indexes
 * sstables, but by then the CFS won't be fully initiated, so the SecondaryIndex object won't be accessible.
 */
public static CellNameType getIndexComparator(CFMetaData baseMetadata, ColumnDefinition cdef)
{
    switch (cdef.getIndexType())
    {
        case KEYS:
            return new SimpleDenseCellNameType(keyComparator);
        case COMPOSITES:
            return CompositesIndex.getIndexComparator(baseMetadata, cdef);
        case CUSTOM:
            return null;
    }
    throw new AssertionError();
}
 
Example #23
Source File: DropIndexStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private ColumnDefinition findIndexedColumn(CFMetaData cfm)
{
    for (ColumnDefinition column : cfm.allColumns())
    {
        if (column.getIndexType() != null && column.getIndexName() != null && column.getIndexName().equals(indexName))
            return column;
    }
    return null;
}
 
Example #24
Source File: AbstractNativeCell.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static ColumnIdentifier getIdentifier(CFMetaData cfMetaData, ByteBuffer name)
{
    ColumnDefinition def = cfMetaData.getColumnDefinition(name);
    if (def != null)
    {
        return def.name;
    }
    else
    {
        // it's safe to simply grab based on clusteringPrefixSize() as we are only called if not a dense type
        AbstractType<?> type = cfMetaData.comparator.subtype(cfMetaData.comparator.clusteringPrefixSize());
        return new ColumnIdentifier(HeapAllocator.instance.clone(name), type);
    }
}
 
Example #25
Source File: ModificationStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static ResultSet buildCasResultSet(String ksName, ByteBuffer key, String cfName, ColumnFamily cf, Iterable<ColumnDefinition> columnsWithConditions, boolean isBatch, QueryOptions options)
throws InvalidRequestException
{
    boolean success = cf == null;

    ColumnSpecification spec = new ColumnSpecification(ksName, cfName, CAS_RESULT_COLUMN, BooleanType.instance);
    ResultSet.Metadata metadata = new ResultSet.Metadata(Collections.singletonList(spec));
    List<List<ByteBuffer>> rows = Collections.singletonList(Collections.singletonList(BooleanType.instance.decompose(success)));

    ResultSet rs = new ResultSet(metadata, rows);
    return success ? rs : merge(rs, buildCasFailureResultSet(key, cf, columnsWithConditions, isBatch, options));
}
 
Example #26
Source File: ColumnCondition.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private ColumnCondition(ColumnDefinition column, Term collectionElement, Term value, List<Term> inValues, Operator op)
{
    this.column = column;
    this.collectionElement = collectionElement;
    this.value = value;
    this.inValues = inValues;
    this.operator = op;

    if (!operator.equals(Operator.IN))
        assert this.inValues == null;
}
 
Example #27
Source File: ModificationStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public Composite createClusteringPrefix(QueryOptions options)
throws InvalidRequestException
{
    // If the only updated/deleted columns are static, then we don't need clustering columns.
    // And in fact, unless it is an INSERT, we reject if clustering colums are provided as that
    // suggest something unintended. For instance, given:
    //   CREATE TABLE t (k int, v int, s int static, PRIMARY KEY (k, v))
    // it can make sense to do:
    //   INSERT INTO t(k, v, s) VALUES (0, 1, 2)
    // but both
    //   UPDATE t SET s = 3 WHERE k = 0 AND v = 1
    //   DELETE v FROM t WHERE k = 0 AND v = 1
    // sounds like you don't really understand what your are doing.
    if (setsStaticColumns && !setsRegularColumns)
    {
        // If we set no non-static columns, then it's fine not to have clustering columns
        if (hasNoClusteringColumns)
            return cfm.comparator.staticPrefix();

        // If we do have clustering columns however, then either it's an INSERT and the query is valid
        // but we still need to build a proper prefix, or it's not an INSERT, and then we want to reject
        // (see above)
        if (type != StatementType.INSERT)
        {
            for (ColumnDefinition def : cfm.clusteringColumns())
                if (processedKeys.get(def.name) != null)
                    throw new InvalidRequestException(String.format("Invalid restriction on clustering column %s since the %s statement modifies only static columns", def.name, type));
            // we should get there as it contradicts hasNoClusteringColumns == false
            throw new AssertionError();
        }
    }

    return createClusteringPrefixBuilderInternal(options);
}
 
Example #28
Source File: CommitLogReadHandlerImpl.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
private void populateClusteringColumns(RowData after, Row row, PartitionUpdate pu) {
    for (ColumnDefinition cd : pu.metadata().clusteringColumns()) {
        String name = cd.name.toString();
        try {
            Object value = CassandraTypeDeserializer.deserialize(cd.type, row.clustering().get(cd.position()));
            CellData cellData = new CellData(name, value, null, CellData.ColumnType.CLUSTERING);
            after.addCell(cellData);
        }
        catch (Exception e) {
            LOGGER.debug("Failed to deserialize Column {} with Type {} in Table {} and KeySpace {}.",
                    cd.name.toString(), cd.type, cd.cfName, cd.ksName);
            throw e;
        }
    }
}
 
Example #29
Source File: CompositesIndexOnPartitionKey.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static CellNameType buildIndexComparator(CFMetaData baseMetadata, ColumnDefinition columnDef)
{
    int ckCount = baseMetadata.clusteringColumns().size();
    List<AbstractType<?>> types = new ArrayList<AbstractType<?>>(ckCount + 1);
    types.add(SecondaryIndex.keyComparator);
    for (int i = 0; i < ckCount; i++)
        types.add(baseMetadata.comparator.subtype(i));
    return new CompoundDenseCellNameType(types);
}
 
Example #30
Source File: CompositesIndex.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static CellNameType getIndexComparator(CFMetaData baseMetadata, ColumnDefinition cfDef)
{
    if (cfDef.type.isCollection() && cfDef.type.isMultiCell())
    {
        switch (((CollectionType)cfDef.type).kind)
        {
            case LIST:
                return CompositesIndexOnCollectionValue.buildIndexComparator(baseMetadata, cfDef);
            case SET:
                return CompositesIndexOnCollectionKey.buildIndexComparator(baseMetadata, cfDef);
            case MAP:
                return cfDef.hasIndexOption(SecondaryIndex.INDEX_KEYS_OPTION_NAME)
                     ? CompositesIndexOnCollectionKey.buildIndexComparator(baseMetadata, cfDef)
                     : CompositesIndexOnCollectionValue.buildIndexComparator(baseMetadata, cfDef);
        }
    }

    switch (cfDef.kind)
    {
        case CLUSTERING_COLUMN:
            return CompositesIndexOnClusteringKey.buildIndexComparator(baseMetadata, cfDef);
        case REGULAR:
            return CompositesIndexOnRegular.buildIndexComparator(baseMetadata, cfDef);
        case PARTITION_KEY:
            return CompositesIndexOnPartitionKey.buildIndexComparator(baseMetadata, cfDef);
        //case COMPACT_VALUE:
        //    return CompositesIndexOnCompactValue.buildIndexComparator(baseMetadata, cfDef);
    }
    throw new AssertionError();
}