in metadata.go [403:507]
func compileV1Metadata(tables []TableMetadata, protoVer int, logger StdLogger) {
for i := range tables {
table := &tables[i]
// decode the key validator
keyValidatorParsed := parseType(table.KeyValidator, byte(protoVer), logger)
// decode the comparator
comparatorParsed := parseType(table.Comparator, byte(protoVer), logger)
// the partition key length is the same as the number of types in the
// key validator
table.PartitionKey = make([]*ColumnMetadata, len(keyValidatorParsed.types))
// V1 protocol only returns "regular" columns from
// system.schema_columns (there is no type field for columns)
// so the alias information is used to
// create the partition key and clustering columns
// construct the partition key from the alias
for i := range table.PartitionKey {
var alias string
if len(table.KeyAliases) > i {
alias = table.KeyAliases[i]
} else if i == 0 {
alias = DEFAULT_KEY_ALIAS
} else {
alias = DEFAULT_KEY_ALIAS + strconv.Itoa(i+1)
}
column := &ColumnMetadata{
Keyspace: table.Keyspace,
Table: table.Name,
Name: alias,
Type: keyValidatorParsed.types[i],
Kind: ColumnPartitionKey,
ComponentIndex: i,
}
table.PartitionKey[i] = column
table.Columns[alias] = column
}
// determine the number of clustering columns
size := len(comparatorParsed.types)
if comparatorParsed.isComposite {
if len(comparatorParsed.collections) != 0 ||
(len(table.ColumnAliases) == size-1 &&
comparatorParsed.types[size-1].Type() == TypeVarchar) {
size = size - 1
}
} else {
if !(len(table.ColumnAliases) != 0 || len(table.Columns) == 0) {
size = 0
}
}
table.ClusteringColumns = make([]*ColumnMetadata, size)
for i := range table.ClusteringColumns {
var alias string
if len(table.ColumnAliases) > i {
alias = table.ColumnAliases[i]
} else if i == 0 {
alias = DEFAULT_COLUMN_ALIAS
} else {
alias = DEFAULT_COLUMN_ALIAS + strconv.Itoa(i+1)
}
order := ASC
if comparatorParsed.reversed[i] {
order = DESC
}
column := &ColumnMetadata{
Keyspace: table.Keyspace,
Table: table.Name,
Name: alias,
Type: comparatorParsed.types[i],
Order: order,
Kind: ColumnClusteringKey,
ComponentIndex: i,
}
table.ClusteringColumns[i] = column
table.Columns[alias] = column
}
if size != len(comparatorParsed.types)-1 {
alias := DEFAULT_VALUE_ALIAS
if len(table.ValueAlias) > 0 {
alias = table.ValueAlias
}
// decode the default validator
defaultValidatorParsed := parseType(table.DefaultValidator, byte(protoVer), logger)
column := &ColumnMetadata{
Keyspace: table.Keyspace,
Table: table.Name,
Name: alias,
Type: defaultValidatorParsed.types[0],
Kind: ColumnRegular,
}
table.Columns[alias] = column
}
}
}