use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class SerializationHeader method toComponent.
public Component toComponent() {
Map<ByteBuffer, AbstractType<?>> staticColumns = new LinkedHashMap<>();
Map<ByteBuffer, AbstractType<?>> regularColumns = new LinkedHashMap<>();
for (ColumnMetadata column : columns.statics) staticColumns.put(column.name.bytes, column.type);
for (ColumnMetadata column : columns.regulars) regularColumns.put(column.name.bytes, column.type);
return new Component(keyType, clusteringTypes, staticColumns, regularColumns, stats);
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class Clustering method toCQLString.
public default default String toCQLString(TableMetadata metadata) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < size(); i++) {
ColumnMetadata c = metadata.clusteringColumns().get(i);
sb.append(i == 0 ? "" : ", ").append(c.type.getString(get(i)));
}
return sb.toString();
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class Clustering method toString.
public default default String toString(TableMetadata metadata) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < size(); i++) {
ColumnMetadata c = metadata.clusteringColumns().get(i);
sb.append(i == 0 ? "" : ", ").append(c.name).append('=').append(get(i) == null ? "null" : c.type.getString(get(i)));
}
return sb.toString();
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class TargetParser method parse.
public static Pair<ColumnMetadata, IndexTarget.Type> parse(TableMetadata metadata, String target) {
// if the regex matches then the target is in the form "keys(foo)", "entries(bar)" etc
// if not, then it must be a simple column name and implictly its type is VALUES
Matcher matcher = TARGET_REGEX.matcher(target);
String columnName;
IndexTarget.Type targetType;
if (matcher.matches()) {
targetType = IndexTarget.Type.fromString(matcher.group(1));
columnName = matcher.group(2);
} else {
columnName = target;
targetType = IndexTarget.Type.VALUES;
}
// need to un-escape any such quotes to get the actual column name
if (columnName.startsWith(QUOTE)) {
columnName = StringUtils.substring(StringUtils.substring(columnName, 1), 0, -1);
columnName = TWO_QUOTES.matcher(columnName).replaceAll(QUOTE);
}
// in that case we have to do a linear scan of the table's columns to get the matching one
if (metadata.isCQLTable())
return Pair.create(metadata.getColumn(new ColumnIdentifier(columnName, true)), targetType);
else
for (ColumnMetadata column : metadata.columns()) if (column.name.toString().equals(columnName))
return Pair.create(column, targetType);
return null;
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class CassandraIndex method indexCfsMetadata.
/**
* Construct the TableMetadata for an index table, the clustering columns in the index table
* vary dependent on the kind of the indexed value.
* @param baseCfsMetadata
* @param indexMetadata
* @return
*/
public static TableMetadata indexCfsMetadata(TableMetadata baseCfsMetadata, IndexMetadata indexMetadata) {
Pair<ColumnMetadata, IndexTarget.Type> target = TargetParser.parse(baseCfsMetadata, indexMetadata);
CassandraIndexFunctions utils = getFunctions(indexMetadata, target);
ColumnMetadata indexedColumn = target.left;
AbstractType<?> indexedValueType = utils.getIndexedValueType(indexedColumn);
TableMetadata.Builder builder = TableMetadata.builder(baseCfsMetadata.keyspace, baseCfsMetadata.indexTableName(indexMetadata), baseCfsMetadata.id).isDense(indexMetadata.isKeys()).isCompound(!indexMetadata.isKeys()).partitioner(new LocalPartitioner(indexedValueType)).addPartitionKeyColumn(indexedColumn.name, indexedColumn.type).addClusteringColumn("partition_key", baseCfsMetadata.partitioner.partitionOrdering());
if (indexMetadata.isKeys()) {
// A dense, compact table for KEYS indexes must have a compact
// value column defined, even though it is never used
CompactTables.DefaultNames names = CompactTables.defaultNameGenerator(ImmutableSet.of(indexedColumn.name.toString(), "partition_key"));
builder.addRegularColumn(names.defaultCompactValueName(), EmptyType.instance);
} else {
// The clustering columns for a table backing a COMPOSITES index are dependent
// on the specific type of index (there are specializations for indexes on collections)
utils.addIndexClusteringColumns(builder, baseCfsMetadata, indexedColumn);
}
return builder.build().updateIndexTableMetadata(baseCfsMetadata.params);
}
Aggregations