Search in sources :

Example 6 with IndexTarget

use of org.apache.cassandra.cql3.statements.IndexTarget in project cassandra by apache.

the class SchemaLoader method compositeIndexCFMD.

public static TableMetadata.Builder compositeIndexCFMD(String ksName, String cfName, boolean withRegularIndex, boolean withStaticIndex) throws ConfigurationException {
    // the withIndex flag exists to allow tests index creation
    // on existing columns
    TableMetadata.Builder builder = TableMetadata.builder(ksName, cfName).addPartitionKeyColumn("key", AsciiType.instance).addClusteringColumn("c1", AsciiType.instance).addRegularColumn("birthdate", LongType.instance).addRegularColumn("notbirthdate", LongType.instance).addStaticColumn("static", LongType.instance).compression(getCompressionParameters());
    Indexes.Builder indexes = Indexes.builder();
    if (withRegularIndex) {
        indexes.add(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("birthdate", true), IndexTarget.Type.VALUES)), cfName + "_birthdate_key_index", IndexMetadata.Kind.COMPOSITES, Collections.EMPTY_MAP));
    }
    if (withStaticIndex) {
        indexes.add(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("static", true), IndexTarget.Type.VALUES)), cfName + "_static_index", IndexMetadata.Kind.COMPOSITES, Collections.EMPTY_MAP));
    }
    return builder.indexes(indexes.build());
}
Also used : IndexTarget(org.apache.cassandra.cql3.statements.IndexTarget) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier)

Example 7 with IndexTarget

use of org.apache.cassandra.cql3.statements.IndexTarget in project cassandra by apache.

the class SchemaLoader method customIndexCFMD.

public static TableMetadata.Builder customIndexCFMD(String ksName, String cfName) {
    TableMetadata.Builder builder = TableMetadata.builder(ksName, cfName).isCompound(false).isDense(true).addPartitionKeyColumn("key", AsciiType.instance).addClusteringColumn("c1", AsciiType.instance).addRegularColumn("value", LongType.instance).compression(getCompressionParameters());
    IndexMetadata index = IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("value", true), IndexTarget.Type.VALUES)), cfName + "_value_index", IndexMetadata.Kind.CUSTOM, Collections.singletonMap(IndexTarget.CUSTOM_INDEX_OPTION_NAME, StubIndex.class.getName()));
    builder.indexes(Indexes.of(index));
    return builder;
}
Also used : IndexTarget(org.apache.cassandra.cql3.statements.IndexTarget) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier)

Aggregations

IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)7 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)4 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 Test (org.junit.Test)4 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)3 ByteBuffer (java.nio.ByteBuffer)2 Future (java.util.concurrent.Future)2 StubIndex (org.apache.cassandra.index.StubIndex)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterators (com.google.common.collect.Iterators)1 File (java.io.File)1 java.util (java.util)1 ExecutionException (java.util.concurrent.ExecutionException)1 SchemaLoader (org.apache.cassandra.SchemaLoader)1 SchemaLoader.standardCFMD (org.apache.cassandra.SchemaLoader.standardCFMD)1 UpdateBuilder (org.apache.cassandra.UpdateBuilder)1 Util (org.apache.cassandra.Util)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 CompactionManager (org.apache.cassandra.db.compaction.CompactionManager)1