in metadata.go [322:396]
func compileMetadata(
protoVersion int,
keyspace *KeyspaceMetadata,
tables []TableMetadata,
columns []ColumnMetadata,
functions []FunctionMetadata,
aggregates []AggregateMetadata,
uTypes []UserTypeMetadata,
materializedViews []MaterializedViewMetadata,
logger StdLogger,
) {
keyspace.Tables = make(map[string]*TableMetadata)
for i := range tables {
tables[i].Columns = make(map[string]*ColumnMetadata)
keyspace.Tables[tables[i].Name] = &tables[i]
}
keyspace.Functions = make(map[string]*FunctionMetadata, len(functions))
for i := range functions {
keyspace.Functions[functions[i].Name] = &functions[i]
}
keyspace.Aggregates = make(map[string]*AggregateMetadata, len(aggregates))
for i, _ := range aggregates {
aggregates[i].FinalFunc = *keyspace.Functions[aggregates[i].finalFunc]
aggregates[i].StateFunc = *keyspace.Functions[aggregates[i].stateFunc]
keyspace.Aggregates[aggregates[i].Name] = &aggregates[i]
}
keyspace.UserTypes = make(map[string]*UserTypeMetadata, len(uTypes))
for i := range uTypes {
keyspace.UserTypes[uTypes[i].Name] = &uTypes[i]
}
keyspace.MaterializedViews = make(map[string]*MaterializedViewMetadata, len(materializedViews))
for i, _ := range materializedViews {
materializedViews[i].BaseTable = keyspace.Tables[materializedViews[i].baseTableName]
keyspace.MaterializedViews[materializedViews[i].Name] = &materializedViews[i]
}
// add columns from the schema data
for i := range columns {
col := &columns[i]
// decode the validator for TypeInfo and order
if col.ClusteringOrder != "" { // Cassandra 3.x+
col.Type = getCassandraType(col.Validator, byte(protoVersion), logger)
col.Order = ASC
if col.ClusteringOrder == "desc" {
col.Order = DESC
}
} else {
validatorParsed := parseType(col.Validator, byte(protoVersion), logger)
col.Type = validatorParsed.types[0]
col.Order = ASC
if validatorParsed.reversed[0] {
col.Order = DESC
}
}
table, ok := keyspace.Tables[col.Table]
if !ok {
// if the schema is being updated we will race between seeing
// the metadata be complete. Potentially we should check for
// schema versions before and after reading the metadata and
// if they dont match try again.
continue
}
table.Columns[col.Name] = col
table.OrderedColumns = append(table.OrderedColumns, col.Name)
}
if protoVersion == protoVersion1 {
compileV1Metadata(tables, protoVersion, logger)
} else {
compileV2Metadata(tables, protoVersion, logger)
}
}