Search in sources :

Example 26 with KeyspaceMetadata

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

the class CreateTypeStatement method announceMigration.

public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws InvalidRequestException, ConfigurationException {
    KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(name.getKeyspace());
    // should haven't validate otherwise
    assert ksm != null;
    // Can happen with ifNotExists
    if (ksm.types.get(name.getUserTypeName()).isPresent())
        return null;
    UserType type = createType();
    checkForDuplicateNames(type);
    MigrationManager.announceNewType(type, isLocalOnly);
    return new Event.SchemaChange(Event.SchemaChange.Change.CREATED, Event.SchemaChange.Target.TYPE, keyspace(), name.getStringTypeName());
}
Also used : KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) UserType(org.apache.cassandra.db.marshal.UserType)

Example 27 with KeyspaceMetadata

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

the class DropTypeStatement method announceMigration.

public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws InvalidRequestException, ConfigurationException {
    KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(name.getKeyspace());
    if (ksm == null)
        // do not assert (otherwise IF EXISTS case fails)
        return null;
    UserType toDrop = ksm.types.getNullable(name.getUserTypeName());
    // Can be null with ifExists
    if (toDrop == null)
        return null;
    MigrationManager.announceTypeDrop(toDrop, isLocalOnly);
    return new Event.SchemaChange(Event.SchemaChange.Change.DROPPED, Event.SchemaChange.Target.TYPE, keyspace(), name.getStringTypeName());
}
Also used : KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata)

Example 28 with KeyspaceMetadata

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

the class StorageService method getNaturalEndpoints.

/**
     * This method returns the N endpoints that are responsible for storing the
     * specified key i.e for replication.
     *
     * @param keyspaceName keyspace name also known as keyspace
     * @param cf Column family name
     * @param key key for which we need to find the endpoint
     * @return the endpoint responsible for this key
     */
public List<InetAddress> getNaturalEndpoints(String keyspaceName, String cf, String key) {
    KeyspaceMetadata ksMetaData = Schema.instance.getKeyspaceMetadata(keyspaceName);
    if (ksMetaData == null)
        throw new IllegalArgumentException("Unknown keyspace '" + keyspaceName + "'");
    TableMetadata metadata = ksMetaData.getTableOrViewNullable(cf);
    if (metadata == null)
        throw new IllegalArgumentException("Unknown table '" + cf + "' in keyspace '" + keyspaceName + "'");
    return getNaturalEndpoints(keyspaceName, tokenMetadata.partitioner.getToken(metadata.partitionKeyType.fromString(key)));
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata)

Example 29 with KeyspaceMetadata

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

the class MutationBench method setup.

@Setup
public void setup() throws IOException {
    Schema.instance.load(KeyspaceMetadata.create(keyspace, KeyspaceParams.simple(1)));
    KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace);
    TableMetadata metadata = CreateTableStatement.parse("CREATE TABLE userpics " + "( userid bigint," + "picid bigint," + "commentid bigint, " + "PRIMARY KEY(userid, picid))", keyspace).build();
    Schema.instance.load(ksm.withSwapped(ksm.tables.with(metadata)));
    mutation = (Mutation) UpdateBuilder.create(metadata, 1L).newRow(1L).add("commentid", 32L).makeMutation();
    messageOut = mutation.createMessage();
    buffer = ByteBuffer.allocate(messageOut.serializedSize(MessagingService.current_version));
    outputBuffer = new DataOutputBufferFixed(buffer);
    inputBuffer = new DataInputBuffer(buffer, false);
    messageOut.serialize(outputBuffer, MessagingService.current_version);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) DataOutputBufferFixed(org.apache.cassandra.io.util.DataOutputBufferFixed)

Example 30 with KeyspaceMetadata

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

the class AggregationTest method testBrokenAggregate.

@Test
public void testBrokenAggregate() throws Throwable {
    createTable("CREATE TABLE %s (key int primary key, val int)");
    execute("INSERT INTO %s (key, val) VALUES (?, ?)", 1, 1);
    String fState = createFunction(KEYSPACE, "int, int", "CREATE FUNCTION %s(a int, b int) " + "CALLED ON NULL INPUT " + "RETURNS int " + "LANGUAGE javascript " + "AS 'a + b;'");
    String a = createAggregate(KEYSPACE, "int", "CREATE AGGREGATE %s(int) " + "SFUNC " + shortFunctionName(fState) + " " + "STYPE int ");
    KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace());
    UDAggregate f = (UDAggregate) ksm.functions.get(parseFunctionName(a)).iterator().next();
    UDAggregate broken = UDAggregate.createBroken(f.name(), f.argTypes(), f.returnType(), null, new InvalidRequestException("foo bar is broken"));
    Schema.instance.load(ksm.withSwapped(ksm.functions.without(f.name(), f.argTypes()).with(broken)));
    assertInvalidThrowMessage("foo bar is broken", InvalidRequestException.class, "SELECT " + a + "(val) FROM %s");
}
Also used : UDAggregate(org.apache.cassandra.cql3.functions.UDAggregate) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) Test(org.junit.Test)

Aggregations

KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)30 Test (org.junit.Test)17 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)12 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)11 Range (org.apache.cassandra.dht.Range)8 TableMetadata (org.apache.cassandra.schema.TableMetadata)8 InetAddress (java.net.InetAddress)6 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)6 Token (org.apache.cassandra.dht.Token)6 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)4 HashMap (java.util.HashMap)3 UserType (org.apache.cassandra.db.marshal.UserType)3 NetworkTopologyStrategy (org.apache.cassandra.locator.NetworkTopologyStrategy)3 TriggerMetadata (org.apache.cassandra.schema.TriggerMetadata)3 JavaBasedUDFunction (org.apache.cassandra.cql3.functions.JavaBasedUDFunction)1 UDAggregate (org.apache.cassandra.cql3.functions.UDAggregate)1 UDFunction (org.apache.cassandra.cql3.functions.UDFunction)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)1 DataOutputBufferFixed (org.apache.cassandra.io.util.DataOutputBufferFixed)1