public boolean countCQL3Rows(CellNameType comparator) { // If comparator is dense a cell == a CQL3 rows so we're always counting CQL3 rows // in particular. Otherwise, we do so only if we group the cells into CQL rows. return comparator.isDense() || compositesToGroup >= 0; }
public Composite buildWith(ByteBuffer value) { if (this.value != null) throw new IllegalStateException(); if (value == null || !value.hasRemaining()) return Composites.EMPTY; // If we're building a dense cell name, then we can directly allocate the // CellName object as it's complete. if (type instanceof CellNameType && ((CellNameType)type).isDense()) return new SimpleDenseCellName(value); return new SimpleComposite(value); }
public Composite build() { if (value == null || !value.hasRemaining()) return Composites.EMPTY; // If we're building a dense cell name, then we can directly allocate the // CellName object as it's complete. if (type instanceof CellNameType && ((CellNameType)type).isDense()) return new SimpleDenseCellName(value); return new SimpleComposite(value); }
public Composite buildWith(ByteBuffer value) { ByteBuffer[] newValues = Arrays.copyOf(values, values.length); newValues[size] = value; // Same as above if (size+1 == newValues.length && type instanceof CellNameType && ((CellNameType)type).isDense()) return new CompoundDenseCellName(newValues); return new CompoundComposite(newValues, size+1, false); }
public Composite buildWith(List<ByteBuffer> newValues) { ByteBuffer[] buffers = Arrays.copyOf(values, values.length); int newSize = size; for (ByteBuffer value : newValues) buffers[newSize++] = value; if (newSize == buffers.length && type instanceof CellNameType && ((CellNameType)type).isDense()) return new CompoundDenseCellName(buffers); return new CompoundComposite(buffers, newSize, false); } }
public boolean isCQL3Table() { return !isSuper() && !comparator.isDense() && comparator.isCompound(); }
public Composite build() { if (size == 0) return Composites.EMPTY; // We don't allow to add more element to a builder that has been built so // that we don't have to copy values. built = true; // If the builder is full and we're building a dense cell name, then we can // directly allocate the CellName object as it's complete. if (size == values.length && type instanceof CellNameType && ((CellNameType)type).isDense()) return new CompoundDenseCellName(values); return new CompoundComposite(values, size, false); }
private boolean isColumnRange() { // Due to CASSANDRA-5762, we always do a slice for CQL3 tables (not dense, composite). // Static CF (non dense but non composite) never entails a column slice however if (!cfm.comparator.isDense()) return cfm.comparator.isCompound(); // Otherwise (i.e. for compact table where we don't have a row marker anyway and thus don't care about CASSANDRA-5762), // it is a range query if it has at least one the column alias for which no relation is defined or is not EQ. for (Restriction r : columnRestrictions) { if (r == null || r.isSlice()) return true; } return false; }
public IDiskAtomFilter readFilter() { assert !conditions.isEmpty(); ColumnSlice[] slices = new ColumnSlice[conditions.size()]; int i = 0; // We always read CQL rows entirely as on CAS failure we want to be able to distinguish between "row exists // but all values for which there were conditions are null" and "row doesn't exists", and we can't rely on the // row marker for that (see #6623) for (Composite prefix : conditions.keySet()) slices[i++] = prefix.slice(); int toGroup = cfm.comparator.isDense() ? -1 : cfm.clusteringColumns().size(); slices = ColumnSlice.deoverlapSlices(slices, cfm.comparator); assert ColumnSlice.validateSlices(slices, cfm.comparator, false); return new SliceQueryFilter(slices, false, slices.length, toGroup); }
private static float calculateResultRowsUsingEstimatedKeys(ColumnFamilyStore cfs) { if (cfs.metadata.comparator.isDense()) { // one storage row per result row, so use key estimate directly return cfs.estimateKeys(); } else { float resultRowsPerStorageRow = ((float) cfs.getMeanColumns()) / cfs.metadata.regularColumns().size(); return resultRowsPerStorageRow * (cfs.estimateKeys()); } }
private ColumnDefinition addDefaultValueAlias(ColumnDefinition compactValueDef) { if (comparator.isDense()) { if (compactValueDef != null) return compactValueDef; ColumnDefinition newDef = ColumnDefinition.compactValueDef(this, ByteBufferUtil.bytes(DEFAULT_VALUE_ALIAS), defaultValidator); addOrReplaceColumnDefinition(newDef); return newDef; } else { assert compactValueDef == null; return null; } }
public int liveCQL3RowCount(long now) { ColumnCounter counter = getComparator().isDense() ? new ColumnCounter(now) : new ColumnCounter.GroupByPrefix(now, getComparator(), metadata.clusteringColumns().size()); return counter.countAll(this).live(); }
private Composite createClusteringPrefixBuilderInternal(QueryOptions options) throws InvalidRequestException { CBuilder builder = cfm.comparator.prefixBuilder(); ColumnDefinition firstEmptyKey = null; for (ColumnDefinition def : cfm.clusteringColumns()) { Restriction r = processedKeys.get(def.name); if (r == null) { firstEmptyKey = def; if (requireFullClusteringKey() && !cfm.comparator.isDense() && cfm.comparator.isCompound()) throw new InvalidRequestException(String.format("Missing mandatory PRIMARY KEY part %s", def.name)); } else if (firstEmptyKey != null) { throw new InvalidRequestException(String.format("Missing PRIMARY KEY part %s since %s is set", firstEmptyKey.name, def.name)); } else { List<ByteBuffer> values = r.values(options); assert values.size() == 1; // We only allow IN for row keys so far ByteBuffer val = values.get(0); if (val == null) throw new InvalidRequestException(String.format("Invalid null value for clustering key part %s", def.name)); builder.add(val); } } return builder.build(); }
private SortedSet<CellName> addSelectedColumns(Composite prefix) if (cfm.comparator.isDense())
if (cfm.comparator.isDense() && !cfm.comparator.isCompound())
private IDiskAtomFilter makeFilter(QueryOptions options, int limit) throws InvalidRequestException int toGroup = cfm.comparator.isDense() ? -1 : cfm.clusteringColumns().size(); if (parameters.isDistinct)
if (cfm.comparator.isDense())
private boolean updateDefinition(CFMetaData cfm, ColumnDefinition def, String keyspace, ByteBuffer toReplace, UserType updated) { AbstractType<?> t = updateWith(def.type, keyspace, toReplace, updated); if (t == null) return false; // We need to update this validator ... cfm.addOrReplaceColumnDefinition(def.withNewType(t)); // ... but if it's part of the comparator or key validator, we need to go update those too. switch (def.kind) { case PARTITION_KEY: cfm.keyValidator(updateWith(cfm.getKeyValidator(), keyspace, toReplace, updated)); break; case CLUSTERING_COLUMN: cfm.comparator = CellNames.fromAbstractType(updateWith(cfm.comparator.asAbstractType(), keyspace, toReplace, updated), cfm.comparator.isDense()); break; default: // If it's a collection, we still want to modify the comparator because the collection is aliased in it if (def.type instanceof CollectionType && def.type.isMultiCell()) { t = updateWith(cfm.comparator.asAbstractType(), keyspace, toReplace, updated); // If t == null, all relevant comparators were updated via updateWith, which reaches into types and // collections if (t != null) cfm.comparator = CellNames.fromAbstractType(t, cfm.comparator.isDense()); } break; } return true; }
public void addUpdateForKey(ColumnFamily cf, ByteBuffer key, Composite prefix, UpdateParameters params) throws InvalidRequestException { List<Operation> deletions = getOperations(); if (deletions.isEmpty()) { // We delete the slice selected by the prefix. // However, for performance reasons, we distinguish 2 cases: // - It's a full internal row delete // - It's a full cell name (i.e it's a dense layout and the prefix is full) if (prefix.isEmpty()) { // No columns specified, delete the row cf.delete(new DeletionInfo(params.timestamp, params.localDeletionTime)); } else if (cfm.comparator.isDense() && prefix.size() == cfm.clusteringColumns().size()) { cf.addAtom(params.makeTombstone(cfm.comparator.create(prefix, null))); } else { cf.addAtom(params.makeRangeTombstone(prefix.slice())); } } else { for (Operation op : deletions) op.execute(key, cf, prefix, params); } }
if ((cfm.comparator.isDense() || !cfm.comparator.isCompound()) && cd.isPrimaryKeyColumn()) throw new InvalidRequestException("Secondary indexes are not supported on PRIMARY KEY columns in COMPACT STORAGE tables");