private static CFMetaData indexCFMD(String ksName, String cfName, final Boolean withIdxType) throws ConfigurationException { return standardCFMD(ksName, cfName) .columnMetadata(new HashMap<ByteBuffer, ColumnDefinition>() {{ ByteBuffer cName = ByteBuffer.wrap("birthyear".getBytes(Charsets.UTF_8)); IndexType keys = withIdxType ? IndexType.KEYS : null; //TODO: that last null is for composites. Need to understand that better, but null is reasonable ColumnDefinition def = new org.apache.cassandra.config.ColumnDefinition(cName,LongType.instance,IndexType.KEYS,null,"birthyear_index",null, Type.REGULAR); put (cName,def); }}).rebuild(); }
public BufferCell(ColumnDefinition column, long timestamp, int ttl, int localDeletionTime, ByteBuffer value, CellPath path) { super(column); assert !column.isPrimaryKeyColumn(); assert column.isComplex() == (path != null); this.timestamp = timestamp; this.ttl = ttl; this.localDeletionTime = localDeletionTime; this.value = value; this.path = path; }
public boolean apply(ColumnDefinition def) { return def.isStatic(); } };
/** * Returns a "fake" ColumnDefinition corresponding to the dropped column {@code name} * of {@code null} if there is no such dropped column. * * @param name - the column name * @param isStatic - whether the column was a static column, if known */ public ColumnDefinition getDroppedColumnDefinition(ByteBuffer name, boolean isStatic) { DroppedColumn dropped = droppedColumns.get(name); if (dropped == null) return null; // We need the type for deserialization purpose. If we don't have the type however, // it means that it's a dropped column from before 3.0, and in that case using // BytesType is fine for what we'll be using it for, even if that's a hack. AbstractType<?> type = dropped.type == null ? BytesType.instance : dropped.type; return isStatic ? ColumnDefinition.staticDef(this, name, type) : ColumnDefinition.regularDef(this, name, type); }
? ColumnDefinition.staticDef(cfm, columnName.bytes, type, componentIndex) : ColumnDefinition.regularDef(cfm, columnName.bytes, type, componentIndex)); break; if (!validatorType.isValueCompatibleWith(oldTypes.get(def.position()))) throw new ConfigurationException(String.format("Cannot change %s from type %s to type %s: types are incompatible.", columnName, oldTypes.get(def.position()).asCQL3Type(), validator)); newTypes.set(def.position(), validatorType); cfm.keyValidator(CompositeType.getInstance(newTypes)); throw new InvalidRequestException(String.format("Cannot alter clustering column %s in a non-CQL3 table", columnName)); AbstractType<?> oldType = cfm.comparator.subtype(def.position()); validator)); cfm.comparator = cfm.comparator.setSubtype(def.position(), validatorType); break; case COMPACT_VALUE: cfm.addOrReplaceColumnDefinition(def.withNewType(validatorType)); break;
/** * Find a SuperColumn value column if it's available (for example, when it was renamed) or create one with a default name. */ public static ColumnDefinition getSuperCfValueColumn(CFMetaData cfm, PartitionColumns partitionColumns, ColumnDefinition superCfKeyColumn, CompactTables.DefaultNames defaultNames) { assert cfm.isDense(); MapType mapType = (MapType) cfm.compactValueColumn().type; for (ColumnDefinition def: partitionColumns.regulars) { if (!def.name.bytes.equals(SUPER_COLUMN_MAP_COLUMN) && def.type.equals(mapType.getValuesType()) && !def.equals(superCfKeyColumn)) return def; } ColumnIdentifier identifier = ColumnIdentifier.getInterned(defaultNames.defaultCompactValueName(), true); return new ColumnDefinition(cfm.ksName, cfm.cfName, identifier, mapType.getValuesType(), ColumnDefinition.NO_POSITION, ColumnDefinition.Kind.REGULAR); }
private ColumnDefinition getColumn(String columnName) { ColumnDefinition column = metadata.getColumnDefinition(new ColumnIdentifier(columnName, true)); assert column != null : "Cannot find column " + columnName; assert !column.isPrimaryKeyColumn(); assert !column.isStatic() || builder.clustering() == Clustering.STATIC_CLUSTERING : "Cannot add non-static column to static-row"; return column; }
@Override public boolean equals(Object other) { if (this == other) return true; if(!(other instanceof ComplexColumnData)) return false; ComplexColumnData that = (ComplexColumnData)other; return this.column().equals(that.column()) && this.complexDeletion().equals(that.complexDeletion) && BTree.equals(this.cells, that.cells); }
void setValue(CellPath path, ByteBuffer value) { Cell current = (Cell) BTree.<Object>find(cells, column.asymmetricCellPathComparator(), path); BTree.replaceInSitu(cells, column.cellComparator(), current, current.withUpdatedValue(value)); }
private void addRestriction(Restriction restriction) { ColumnDefinition def = restriction.getFirstColumn(); if (def.isPartitionKey()) partitionKeyRestrictions = partitionKeyRestrictions.mergeWith(restriction); else if (def.isClusteringColumn()) clusteringColumnsRestrictions = clusteringColumnsRestrictions.mergeWith(restriction); else nonPrimaryKeyRestrictions = nonPrimaryKeyRestrictions.addRestriction((SingleRestriction) restriction); }
/** * Checks if this selection contains only static columns. * @return <code>true</code> if this selection contains only static columns, <code>false</code> otherwise; */ public boolean containsOnlyStaticColumns() { if (!containsStaticColumns()) return false; if (isWildcard()) return false; for (ColumnDefinition def : getColumns()) { if (!def.isPartitionKey() && !def.isStatic()) return false; } return true; }
private static ColumnDefinition makeDefinition(CFMetaData cfm, IndexMetadata index) { // Similarly to how we handle non-defined columns in thift, we create a fake column definition to // represent the target index. This is definitely something that can be improved though. return ColumnDefinition.regularDef(cfm, ByteBuffer.wrap(index.name.getBytes()), BytesType.instance); }
private static List<ColumnDefinition> copy(List<ColumnDefinition> l) { List<ColumnDefinition> copied = new ArrayList<>(l.size()); for (ColumnDefinition cd : l) copied.add(cd.copy()); return copied; }
public void addCell(Cell cell) { assert cell.column().isStatic() == (clustering == Clustering.STATIC_CLUSTERING) : "Column is " + cell.column() + ", clustering = " + clustering; // In practice, only unsorted builder have to deal with shadowed cells, but it doesn't cost us much to deal with it unconditionally in this case if (deletion.deletes(cell)) return; getCells().add(cell); hasComplex |= cell.column.isComplex(); }
private boolean isPrimaryKeyIndex() { return indexedColumn.isPrimaryKeyColumn(); }
public boolean removeColumnDefinition(ColumnDefinition def) { assert !def.isPartitionKey(); boolean removed = columnMetadata.remove(def.name.bytes) != null; if (removed) partitionColumns = partitionColumns.without(def); return removed; }
public Cell getCell(CellPath path) { return (Cell) BTree.<Object>find(cells, column.asymmetricCellPathComparator(), path); }
/** * Returns a "fake" ColumnDefinition corresponding to the dropped column {@code name} * of {@code null} if there is no such dropped column. * * @param name - the column name * @param isStatic - whether the column was a static column, if known */ public ColumnDefinition getDroppedColumnDefinition(ByteBuffer name, boolean isStatic) { DroppedColumn dropped = droppedColumns.get(name); if (dropped == null) return null; // We need the type for deserialization purpose. If we don't have the type however, // it means that it's a dropped column from before 3.0, and in that case using // BytesType is fine for what we'll be using it for, even if that's a hack. AbstractType<?> type = dropped.type == null ? BytesType.instance : dropped.type; return isStatic ? ColumnDefinition.staticDef(this, name, type) : ColumnDefinition.regularDef(this, name, type); }
/** * Find a SuperColumn value column if it's available (for example, when it was renamed) or create one with a default name. */ public static ColumnDefinition getSuperCfValueColumn(CFMetaData cfm, PartitionColumns partitionColumns, ColumnDefinition superCfKeyColumn, CompactTables.DefaultNames defaultNames) { assert cfm.isDense(); MapType mapType = (MapType) cfm.compactValueColumn().type; for (ColumnDefinition def: partitionColumns.regulars) { if (!def.name.bytes.equals(SUPER_COLUMN_MAP_COLUMN) && def.type.equals(mapType.getValuesType()) && !def.equals(superCfKeyColumn)) return def; } ColumnIdentifier identifier = ColumnIdentifier.getInterned(defaultNames.defaultCompactValueName(), true); return new ColumnDefinition(cfm.ksName, cfm.cfName, identifier, mapType.getValuesType(), ColumnDefinition.NO_POSITION, ColumnDefinition.Kind.REGULAR); }