in cassandra-four-zero/src/main/java/org/apache/cassandra/spark/reader/SchemaBuilder.java [340:389]
private static void setupTableAndUdt(Schema schema,
String keyspaceName,
TableMetadata tableMetadata,
Types userTypes)
{
String tableName = tableMetadata.name;
KeyspaceMetadata keyspaceMetadata = schema.getKeyspaceMetadata(keyspaceName);
if (keyspaceMetadata == null)
{
LOGGER.error("Keyspace metadata does not exist. keyspace={}", keyspaceName);
throw new IllegalStateException("Keyspace metadata null for '" + keyspaceName
+ "' when it should have been initialized already");
}
if (!tableMetadataExists(schema, keyspaceName, tableName))
{
LOGGER.info("Setting up table metadata in schema keyspace={} table={} partitioner={}",
keyspaceName, tableName, tableMetadata.partitioner.getClass().getName());
keyspaceMetadata = keyspaceMetadata.withSwapped(keyspaceMetadata.tables.with(tableMetadata));
schema.load(keyspaceMetadata);
}
// The metadata of the table might not be the input tableMetadata. Fetch the current to be safe.
TableMetadata currentTable = schema.getTableMetadata(keyspaceName, tableName);
if (!tableInstanceExists(schema, keyspaceName, tableName))
{
LOGGER.info("Setting up table instance in schema keyspace={} table={} partitioner={}",
keyspaceName, tableName, tableMetadata.partitioner.getClass().getName());
if (keyspaceInstanceExists(schema, keyspaceName))
{
// initCf (cfs) in the opened keyspace
schema.getKeyspaceInstance(keyspaceName)
.initCf(TableMetadataRef.forOfflineTools(currentTable), false);
}
else
{
// The keyspace has not yet opened, create/open keyspace instance and also initCf (cfs) for the table
Keyspace.openWithoutSSTables(keyspaceName);
}
}
if (!userTypes.equals(Types.none()))
{
LOGGER.info("Setting up user types in schema keyspace={} types={}",
keyspaceName, userTypes);
// Update Schema instance with any user-defined types built
keyspaceMetadata = keyspaceMetadata.withSwapped(userTypes);
schema.load(keyspaceMetadata);
}
}