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);
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class CollectionEntryIndex method isStale.
public boolean isStale(Row data, ByteBuffer indexValue, int nowInSec) {
ByteBuffer[] components = ((CompositeType) functions.getIndexedValueType(indexedColumn)).split(indexValue);
ByteBuffer mapKey = components[0];
ByteBuffer mapValue = components[1];
ColumnMetadata columnDef = indexedColumn;
Cell cell = data.getCell(columnDef, CellPath.create(mapKey));
if (cell == null || !cell.isLive(nowInSec))
return true;
AbstractType<?> valueComparator = ((CollectionType) columnDef.type).valueComparator();
return valueComparator.compare(mapValue, cell.value()) != 0;
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class CollectionValueIndex method isStale.
public boolean isStale(Row data, ByteBuffer indexValue, int nowInSec) {
ColumnMetadata columnDef = indexedColumn;
ComplexColumnData complexData = data.getComplexColumnData(columnDef);
if (complexData == null)
return true;
for (Cell cell : complexData) {
if (cell.isLive(nowInSec) && ((CollectionType) columnDef.type).valueComparator().compare(indexValue, cell.value()) == 0)
return false;
}
return true;
}
Aggregations