private static CellNameType subType(CellNameType type) { return new SimpleDenseCellNameType(type.subtype(1)); }
public static CellNameType scNameType(CellNameType type) { return new SimpleDenseCellNameType(type.subtype(0)); }
private static int compare(List<ByteBuffer> columnNames1, List<ByteBuffer> columnNames2, CellNameType comparator) { for (int i = 0; i < Math.min(columnNames1.size(), columnNames2.size()); i++) { int cmp = comparator.subtype(i).compare(columnNames1.get(i), columnNames2.get(i)); if (cmp != 0) return cmp; } return 0; } }
public AbstractType<?> getComponentComparator(Integer componentIndex, ColumnDefinition.Kind kind) { switch (kind) { case REGULAR: if (componentIndex == null) return comparator.asAbstractType(); AbstractType<?> t = comparator.subtype(componentIndex); assert t != null : "Non-sensical component index"; return t; default: // CQL3 column names are UTF8 return UTF8Type.instance; } }
public static CellNameType buildIndexComparator(CFMetaData baseMetadata, ColumnDefinition columnDef) { int ckCount = baseMetadata.clusteringColumns().size(); List<AbstractType<?>> types = new ArrayList<AbstractType<?>>(ckCount + 1); types.add(SecondaryIndex.keyComparator); for (int i = 0; i < ckCount; i++) types.add(baseMetadata.comparator.subtype(i)); return new CompoundDenseCellNameType(types); }
public static CellNameType buildIndexComparator(CFMetaData baseMetadata, ColumnDefinition columnDef) { int count = 1 + baseMetadata.clusteringColumns().size(); // row key + clustering prefix List<AbstractType<?>> types = new ArrayList<AbstractType<?>>(count); types.add(SecondaryIndex.keyComparator); for (int i = 0; i < count - 1; i++) types.add(baseMetadata.comparator.subtype(i)); return new CompoundDenseCellNameType(types); }
public static CellNameType buildIndexComparator(CFMetaData baseMetadata, ColumnDefinition columnDef) { int prefixSize = columnDef.position(); List<AbstractType<?>> types = new ArrayList<AbstractType<?>>(prefixSize + 1); types.add(SecondaryIndex.keyComparator); for (int i = 0; i < prefixSize; i++) types.add(baseMetadata.comparator.subtype(i)); return new CompoundDenseCellNameType(types); }
public static CellNameType buildIndexComparator(CFMetaData baseMetadata, ColumnDefinition columnDef) { int prefixSize = columnDef.position(); List<AbstractType<?>> types = new ArrayList<>(prefixSize + 2); types.add(SecondaryIndex.keyComparator); for (int i = 0; i < prefixSize; i++) types.add(baseMetadata.comparator.subtype(i)); types.add(((CollectionType)columnDef.type).nameComparator()); // collection key return new CompoundDenseCellNameType(types); }
public static AbstractType<?> getComparatorFor(CFMetaData metadata, boolean subColumn) { return metadata.isSuper() ? metadata.comparator.subtype(subColumn ? 1 : 0) : metadata.comparator.asAbstractType(); }
/** * Merge 2 lists of max cell name components. * * @param maxColumnNames lhs * @param candidates rhs * @param comparator comparator to use * @return a list with biggest column names according to (sub)comparator */ public static List<ByteBuffer> mergeMax(List<ByteBuffer> maxColumnNames, List<ByteBuffer> candidates, CellNameType comparator) { if (maxColumnNames.isEmpty()) return minimalBuffersFor(candidates); if (candidates.isEmpty()) return maxColumnNames; List<ByteBuffer> biggest = maxColumnNames.size() > candidates.size() ? maxColumnNames : candidates; List<ByteBuffer> smallest = maxColumnNames.size() > candidates.size() ? candidates : maxColumnNames; // We want to always copy the smallest list, and maybeGrow does it only if it's actually smaller List<ByteBuffer> retList = smallest.size() == biggest.size() ? new ArrayList<>(smallest) : maybeGrow(smallest, biggest.size()); for (int i = 0; i < biggest.size(); i++) retList.set(i, minimalBufferFor(max(retList.get(i), biggest.get(i), comparator.subtype(i)))); return retList; }
/** * Merge 2 lists of min cell name components. * * @param minColumnNames lhs * @param candidates rhs * @param comparator comparator to use * @return a list with smallest column names according to (sub)comparator */ public static List<ByteBuffer> mergeMin(List<ByteBuffer> minColumnNames, List<ByteBuffer> candidates, CellNameType comparator) { if (minColumnNames.isEmpty()) return minimalBuffersFor(candidates); if (candidates.isEmpty()) return minColumnNames; List<ByteBuffer> biggest = minColumnNames.size() > candidates.size() ? minColumnNames : candidates; List<ByteBuffer> smallest = minColumnNames.size() > candidates.size() ? candidates : minColumnNames; // We want to always copy the smallest list, and maybeGrow does it only if it's actually smaller List<ByteBuffer> retList = smallest.size() == biggest.size() ? new ArrayList<>(smallest) : maybeGrow(smallest, biggest.size()); for (int i = 0; i < biggest.size(); i++) retList.set(i, minimalBufferFor(min(retList.get(i), biggest.get(i), comparator.subtype(i)))); return retList; }
/** * finds the min cell name component(s) * * Note that this method *can modify maxSeen*. * * @param minSeen the max columns seen so far * @param candidate the candidate column(s) * @param comparator the comparator to use * @return a list with the min column(s) */ public static List<ByteBuffer> minComponents(List<ByteBuffer> minSeen, Composite candidate, CellNameType comparator) { // For a cell name, no reason to look more than the clustering prefix // (and comparing the collection element would actually crash) int size = Math.min(candidate.size(), comparator.clusteringPrefixSize()); if (minSeen.isEmpty()) return getComponents(candidate, size); // In most case maxSeen is big enough to hold the result so update it in place in those cases minSeen = maybeGrow(minSeen, size); for (int i = 0; i < size; i++) minSeen.set(i, min(minSeen.get(i), candidate.get(i), comparator.subtype(i))); return minSeen; }
private List<ColumnDefinition> addDefaultColumnAliases(List<ColumnDefinition> ckCols) { for (int i = 0; i < ckCols.size(); i++) { if (ckCols.get(i) == null) { Integer idx; AbstractType<?> type; if (comparator.isCompound()) { idx = i; type = comparator.subtype(i); } else { idx = null; type = comparator.asAbstractType(); } ByteBuffer name = ByteBufferUtil.bytes(DEFAULT_COLUMN_ALIAS + (i + 1)); ColumnDefinition newDef = ColumnDefinition.clusteringKeyDef(this, name, type, idx); addOrReplaceColumnDefinition(newDef); ckCols.set(i, newDef); } } return ckCols; }
/** * finds the max cell name component(s) * * Note that this method *can modify maxSeen*. * * @param maxSeen the max columns seen so far * @param candidate the candidate column(s) * @param comparator the comparator to use * @return a list with the max column(s) */ public static List<ByteBuffer> maxComponents(List<ByteBuffer> maxSeen, Composite candidate, CellNameType comparator) { // For a cell name, no reason to look more than the clustering prefix // (and comparing the collection element would actually crash) int size = Math.min(candidate.size(), comparator.clusteringPrefixSize()); if (maxSeen.isEmpty()) return getComponents(candidate, size); // In most case maxSeen is big enough to hold the result so update it in place in those cases maxSeen = maybeGrow(maxSeen, size); for (int i = 0; i < size; i++) maxSeen.set(i, max(maxSeen.get(i), candidate.get(i), comparator.subtype(i))); return maxSeen; }
private static ColumnIdentifier getIdentifier(CFMetaData cfMetaData, ByteBuffer name) { ColumnDefinition def = cfMetaData.getColumnDefinition(name); if (def != null) { return def.name; } else { // it's safe to simply grab based on clusteringPrefixSize() as we are only called if not a dense type AbstractType<?> type = cfMetaData.comparator.subtype(cfMetaData.comparator.clusteringPrefixSize()); return new ColumnIdentifier(HeapAllocator.instance.clone(name), type); } }
private IDiskAtomFilter toInternalFilter(CFMetaData metadata, ColumnParent parent, SlicePredicate predicate) { IDiskAtomFilter filter; if (predicate.column_names != null) { if (metadata.isSuper()) { CellNameType columnType = new SimpleDenseCellNameType(metadata.comparator.subtype(parent.isSetSuper_column() ? 1 : 0)); SortedSet<CellName> s = new TreeSet<>(columnType); for (ByteBuffer bb : predicate.column_names) s.add(columnType.cellFromByteBuffer(bb)); filter = SuperColumns.fromSCNamesFilter(metadata.comparator, parent.bufferForSuper_column(), new NamesQueryFilter(s)); } else { SortedSet<CellName> s = new TreeSet<CellName>(metadata.comparator); for (ByteBuffer bb : predicate.column_names) s.add(metadata.comparator.cellFromByteBuffer(bb)); filter = new NamesQueryFilter(s); } } else { filter = toInternalFilter(metadata, parent, predicate.slice_range); } return filter; }
public boolean isSameCQL3RowAs(CellNameType type, CellName other) { if (clusteringSize() != other.clusteringSize() || other.isStatic() != isStatic()) return false; for (int i = 0; i < clusteringSize(); i++) { if (type.subtype(i).compare(elements[i], other.get(i)) != 0) return false; } return true; }
public boolean intersects(List<ByteBuffer> minCellNames, List<ByteBuffer> maxCellNames, CellNameType comparator, boolean reversed) { Composite sStart = reversed ? finish : start; Composite sEnd = reversed ? start : finish; if (compare(sStart, maxCellNames, comparator, true) > 0 || compare(sEnd, minCellNames, comparator, false) < 0) return false; // We could safely return true here, but there's a minor optimization: if the first component is restricted // to a single value, we can check that the second component falls within the min/max for that component // (and repeat for all components). for (int i = 0; i < minCellNames.size() && i < maxCellNames.size(); i++) { AbstractType<?> t = comparator.subtype(i); ByteBuffer s = i < sStart.size() ? sStart.get(i) : ByteBufferUtil.EMPTY_BYTE_BUFFER; ByteBuffer f = i < sEnd.size() ? sEnd.get(i) : ByteBufferUtil.EMPTY_BYTE_BUFFER; // we already know the first component falls within its min/max range (otherwise we wouldn't get here) if (i > 0 && (i < sEnd.size() && t.compare(f, minCellNames.get(i)) < 0 || i < sStart.size() && t.compare(s, maxCellNames.get(i)) > 0)) return false; // if this component isn't equal in the start and finish, we don't need to check any more if (i >= sStart.size() || i >= sEnd.size() || t.compare(s, f) != 0) break; } return true; }
public boolean isSameCQL3RowAs(CellNameType type, CellName other) { switch (nametype()) { case SIMPLE_DENSE: case COMPOUND_DENSE: return type.compare(this, other) == 0; case COMPOUND_SPARSE_STATIC: case COMPOUND_SPARSE: int clusteringSize = clusteringSize(); if (clusteringSize != other.clusteringSize() || other.isStatic() != isStatic()) return false; for (int i = 0; i < clusteringSize; i++) if (type.subtype(i).compare(get(i), other.get(i)) != 0) return false; return true; case SIMPLE_SPARSE: return true; default: throw new AssertionError(); } }
private SliceQueryFilter toInternalFilter(CFMetaData metadata, ColumnParent parent, SliceRange range) { if (metadata.isSuper()) { CellNameType columnType = new SimpleDenseCellNameType(metadata.comparator.subtype(parent.isSetSuper_column() ? 1 : 0)); Composite start = columnType.fromByteBuffer(range.start); Composite finish = columnType.fromByteBuffer(range.finish); SliceQueryFilter filter = new SliceQueryFilter(start, finish, range.reversed, range.count); return SuperColumns.fromSCSliceFilter(metadata.comparator, parent.bufferForSuper_column(), filter); } Composite start = metadata.comparator.fromByteBuffer(range.start); Composite finish = metadata.comparator.fromByteBuffer(range.finish); return new SliceQueryFilter(start, finish, range.reversed, range.count); }