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());
}
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());
}
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)));
}
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);
}
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");
}
Aggregations