Search in sources :

Example 1 with ColumnIdentifier

use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.

the class PartitionImplementationTest method makeRow.

Row makeRow(Clustering clustering, String colValue) {
    ColumnMetadata defCol = metadata.getColumn(new ColumnIdentifier("col", true));
    Row.Builder row = BTreeRow.unsortedBuilder(TIMESTAMP);
    row.newRow(clustering);
    row.addCell(BufferCell.live(defCol, TIMESTAMP, ByteBufferUtil.bytes(colValue)));
    return row.build();
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier)

Example 2 with ColumnIdentifier

use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.

the class SchemaLoader method compositeMultipleIndexCFMD.

public static TableMetadata.Builder compositeMultipleIndexCFMD(String ksName, String cfName) throws ConfigurationException {
    TableMetadata.Builder builder = TableMetadata.builder(ksName, cfName).addPartitionKeyColumn("key", AsciiType.instance).addClusteringColumn("c1", AsciiType.instance).addRegularColumn("birthdate", LongType.instance).addRegularColumn("notbirthdate", LongType.instance).compression(getCompressionParameters());
    Indexes.Builder indexes = Indexes.builder();
    indexes.add(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("birthdate", true), IndexTarget.Type.VALUES)), "birthdate_key_index", IndexMetadata.Kind.COMPOSITES, Collections.EMPTY_MAP));
    indexes.add(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("notbirthdate", true), IndexTarget.Type.VALUES)), "notbirthdate_key_index", IndexMetadata.Kind.COMPOSITES, Collections.EMPTY_MAP));
    return builder.indexes(indexes.build());
}
Also used : IndexTarget(org.apache.cassandra.cql3.statements.schema.IndexTarget) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier)

Example 3 with ColumnIdentifier

use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.

the class SchemaLoader method keysIndexCFMD.

public static TableMetadata.Builder keysIndexCFMD(String ksName, String cfName, boolean withIndex) {
    TableMetadata.Builder builder = TableMetadata.builder(ksName, cfName).addPartitionKeyColumn("key", AsciiType.instance).addClusteringColumn("c1", AsciiType.instance).addStaticColumn("birthdate", LongType.instance).addStaticColumn("notbirthdate", LongType.instance).addRegularColumn("value", LongType.instance).compression(getCompressionParameters());
    if (withIndex) {
        IndexMetadata index = IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("birthdate", true), IndexTarget.Type.VALUES)), cfName + "_birthdate_composite_index", IndexMetadata.Kind.KEYS, Collections.EMPTY_MAP);
        builder.indexes(Indexes.builder().add(index).build());
    }
    return builder;
}
Also used : IndexTarget(org.apache.cassandra.cql3.statements.schema.IndexTarget) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier)

Example 4 with ColumnIdentifier

use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.

the class CreateIndexStatement method apply.

public Keyspaces apply(Keyspaces schema) {
    attrs.validate();
    if (attrs.isCustom && attrs.customClass.equals(SASIIndex.class.getName()) && !DatabaseDescriptor.getSASIIndexesEnabled())
        throw new InvalidRequestException("SASI indexes are disabled. Enable in cassandra.yaml to use.");
    KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
    if (null == keyspace)
        throw ire("Keyspace '%s' doesn't exist", keyspaceName);
    TableMetadata table = keyspace.getTableOrViewNullable(tableName);
    if (null == table)
        throw ire("Table '%s' doesn't exist", tableName);
    if (null != indexName && keyspace.hasIndex(indexName)) {
        if (ifNotExists)
            return schema;
        throw ire("Index '%s' already exists", indexName);
    }
    if (table.isCounter())
        throw ire("Secondary indexes on counter tables aren't supported");
    if (table.isView())
        throw ire("Secondary indexes on materialized views aren't supported");
    if (Keyspace.open(table.keyspace).getReplicationStrategy().hasTransientReplicas())
        throw new InvalidRequestException("Secondary indexes are not supported on transiently replicated keyspaces");
    // guardrails to limit number of secondary indexes per table.
    Guardrails.secondaryIndexesPerTable.guard(table.indexes.size() + 1, Strings.isNullOrEmpty(indexName) ? String.format("on table %s", table.name) : String.format("%s on table %s", indexName, table.name), state);
    List<IndexTarget> indexTargets = Lists.newArrayList(transform(rawIndexTargets, t -> t.prepare(table)));
    if (indexTargets.isEmpty() && !attrs.isCustom)
        throw ire("Only CUSTOM indexes can be created without specifying a target column");
    if (indexTargets.size() > 1) {
        if (!attrs.isCustom)
            throw ire("Only CUSTOM indexes support multiple columns");
        Set<ColumnIdentifier> columns = new HashSet<>();
        for (IndexTarget target : indexTargets) if (!columns.add(target.column))
            throw ire("Duplicate column '%s' in index target list", target.column);
    }
    indexTargets.forEach(t -> validateIndexTarget(table, t));
    String name = null == indexName ? generateIndexName(keyspace, indexTargets) : indexName;
    IndexMetadata.Kind kind = attrs.isCustom ? IndexMetadata.Kind.CUSTOM : IndexMetadata.Kind.COMPOSITES;
    Map<String, String> options = attrs.isCustom ? attrs.getOptions() : Collections.emptyMap();
    IndexMetadata index = IndexMetadata.fromIndexTargets(indexTargets, name, kind, options);
    // check to disallow creation of an index which duplicates an existing one in all but name
    IndexMetadata equalIndex = tryFind(table.indexes, i -> i.equalsWithoutName(index)).orNull();
    if (null != equalIndex) {
        if (ifNotExists)
            return schema;
        throw ire("Index %s is a duplicate of existing index %s", index.name, equalIndex.name);
    }
    TableMetadata newTable = table.withSwapped(table.indexes.with(index));
    newTable.validate();
    return schema.withAddedOrUpdated(keyspace.withSwapped(keyspace.tables.withSwapped(newTable)));
}
Also used : AuditLogContext(org.apache.cassandra.audit.AuditLogContext) Change(org.apache.cassandra.transport.Event.SchemaChange.Change) java.util(java.util) Iterables.transform(com.google.common.collect.Iterables.transform) Iterables.tryFind(com.google.common.collect.Iterables.tryFind) Permission(org.apache.cassandra.auth.Permission) CQLStatement(org.apache.cassandra.cql3.CQLStatement) QualifiedName(org.apache.cassandra.cql3.QualifiedName) Strings(com.google.common.base.Strings) Guardrails(org.apache.cassandra.db.guardrails.Guardrails) Lists(com.google.common.collect.Lists) KeyspacesDiff(org.apache.cassandra.schema.Keyspaces.KeyspacesDiff) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) Keyspace(org.apache.cassandra.db.Keyspace) SASIIndex(org.apache.cassandra.index.sasi.SASIIndex) Type(org.apache.cassandra.cql3.statements.schema.IndexTarget.Type) ImmutableSet(com.google.common.collect.ImmutableSet) SchemaChange(org.apache.cassandra.transport.Event.SchemaChange) ClientState(org.apache.cassandra.service.ClientState) AuditLogEntryType(org.apache.cassandra.audit.AuditLogEntryType) MapType(org.apache.cassandra.db.marshal.MapType) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) Target(org.apache.cassandra.transport.Event.SchemaChange.Target) org.apache.cassandra.schema(org.apache.cassandra.schema) SASIIndex(org.apache.cassandra.index.sasi.SASIIndex) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier)

Example 5 with ColumnIdentifier

use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.

the class RowTest method testResolve.

@Test
public void testResolve() {
    ColumnMetadata defA = metadata.getColumn(new ColumnIdentifier("a", true));
    ColumnMetadata defB = metadata.getColumn(new ColumnIdentifier("b", true));
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(metadata.comparator.make("c1"));
    writeSimpleCellValue(builder, defA, "a1", 0);
    writeSimpleCellValue(builder, defA, "a2", 1);
    writeSimpleCellValue(builder, defB, "b1", 1);
    Row row = builder.build();
    PartitionUpdate update = PartitionUpdate.singleRowUpdate(metadata, dk, row);
    Unfiltered unfiltered = update.unfilteredIterator().next();
    assertTrue(unfiltered.kind() == Unfiltered.Kind.ROW);
    row = (Row) unfiltered;
    assertEquals("a2", defA.cellValueType().getString(row.getCell(defA).buffer()));
    assertEquals("b1", defB.cellValueType().getString(row.getCell(defB).buffer()));
    assertEquals(2, row.columns().size());
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Aggregations

ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)55 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)24 Test (org.junit.Test)15 ByteBuffer (java.nio.ByteBuffer)12 TableMetadata (org.apache.cassandra.schema.TableMetadata)12 IdentifierExpression (org.hypertrace.core.documentstore.expression.impl.IdentifierExpression)12 ColumnIdentifier (org.hypertrace.entity.query.service.v1.ColumnIdentifier)12 Test (org.junit.jupiter.api.Test)12 Row (org.apache.cassandra.db.rows.Row)10 Expression (org.hypertrace.entity.query.service.v1.Expression)8 ArrayList (java.util.ArrayList)7 IndexTarget (org.apache.cassandra.cql3.statements.schema.IndexTarget)7 ConstantExpression (org.hypertrace.core.documentstore.expression.impl.ConstantExpression)6 IdentifierConverter (org.hypertrace.entity.query.service.converter.identifier.IdentifierConverter)6 CQLStatement (org.apache.cassandra.cql3.CQLStatement)5 VariableSpecifications (org.apache.cassandra.cql3.VariableSpecifications)5 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)4 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)4 RowIterator (org.apache.cassandra.db.rows.RowIterator)4 RelationalOperator (org.hypertrace.core.documentstore.expression.operators.RelationalOperator)4