private static CFMetaData compositeCFMD(String ksName, String cfName, AbstractType<?>... types) { return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, CompositeType.getInstance(Arrays.asList(types)), null).rebuild(); }
@Override public ByteBuffer getIndexValue() { return CompositeType.build(key, value); }
public static synchronized CompositeType getInstance(List<AbstractType<?>> types) { assert types != null && !types.isEmpty(); CompositeType ct = instances.get(types); if (ct == null) { ct = new CompositeType(types); instances.put(types, ct); } return ct; }
private int compareCompositeTypes(CompositeType type, CompositeType otherType) { List<AbstractType<?>> types = type.getComponents(); List<AbstractType<?>> otherTypes = otherType.getComponents(); if (types.size() != otherTypes.size()) return Integer.compare(types.size(), otherTypes.size()); for (int i = 0, m = type.componentsCount(); i < m ; i++) { int test = compare(types.get(i), otherTypes.get(i)); if (test != 0); return test; } return 0; }
private void serializeCompound(DataOutputPlus out, boolean isDense) throws IOException { List<AbstractType<?>> types = new ArrayList<>(comparator.clusteringComparator.subtypes()); if (!isDense) types.add(UTF8Type.instance); CompositeType type = CompositeType.getInstance(types); for (int i = 0; i < size; i++) { LegacyBound start = starts[i]; LegacyBound end = ends[i]; CompositeType.Builder startBuilder = type.builder(); CompositeType.Builder endBuilder = type.builder(); for (int j = 0; j < start.bound.clustering().size(); j++) { startBuilder.add(start.bound.get(j)); endBuilder.add(end.bound.get(j)); } if (start.collectionName != null) startBuilder.add(start.collectionName.name.bytes); if (end.collectionName != null) endBuilder.add(end.collectionName.name.bytes); ByteBufferUtil.writeWithShortLength(startBuilder.build(), out); ByteBufferUtil.writeWithShortLength(endBuilder.buildAsEndOfRange(), out); out.writeInt(delTimes[i]); out.writeLong(markedAts[i]); } }
List<ByteBuffer> components = CompositeType.splitName(bound); byte eoc = CompositeType.lastEOC(bound); return new LegacyBound(cb, metadata.isCompound() && CompositeType.isStaticName(bound), collectionName);
private static ByteBuffer[] extractKeyComponents(DecoratedKey partitionKey, AbstractType<?> type) { return type instanceof CompositeType ? ((CompositeType)type).split(partitionKey.getKey()) : new ByteBuffer[]{ partitionKey.getKey() }; }
public static Clustering decodeClustering(CFMetaData metadata, ByteBuffer value) { int csize = metadata.comparator.size(); if (csize == 0) return Clustering.EMPTY; if (metadata.isCompound() && CompositeType.isStaticName(value)) return Clustering.STATIC_CLUSTERING; List<ByteBuffer> components = metadata.isCompound() ? CompositeType.splitName(value) : Collections.singletonList(value); return Clustering.make(components.subList(0, Math.min(csize, components.size())).toArray(new ByteBuffer[csize])); }
public ByteBuffer extractLastComponent(ByteBuffer bb) { int idx = types.get(types.size() - 1) instanceof ColumnToCollectionType ? types.size() - 2 : types.size() - 1; return extractComponent(bb, idx); }
protected boolean readIsStatic(ByteBuffer bb) { return readStatic(bb); }
/** * Builds the partition key in {@link ByteBuffer} format for the given values. * * @param equalsList List of equals field and value pairs. * @param inValue Value for the operator in. * @return with the partition key. */ private ByteBuffer getPartitionKey(List<Pair<String, Serializable>> equalsList, Serializable inValue) { assert (equalsList.size() + 1) == ((CompositeType) keyValidator).componentsCount(); ByteBuffer[] serialized = new ByteBuffer[equalsList.size() + 1]; for (int i = 0; i < equalsList.size(); i++) { ByteBuffer buffer = ((AbstractType) keyValidator.getComponents().get(i)).decompose(equalsList.get(i).right); serialized[i] = buffer; } serialized[serialized.length - 1] = ((AbstractType) keyValidator.getComponents().get(serialized.length - 1)) .decompose(inValue); return CompositeType.build(serialized); } }
private ByteBuffer defaultPartitionKey() { ByteBuffer partitionKey; AbstractType keyType = table.metadata.getKeyValidator(); if (keyType instanceof CompositeType) { CompositeType compositeType = ((CompositeType) keyType); CompositeType.Builder builder = compositeType.builder(); compositeType.getComponents(); for (AbstractType component : compositeType.getComponents()) { builder.add(Fields.defaultValue(component)); } partitionKey = builder.build(); } else { partitionKey = Fields.defaultValue(keyType); } return partitionKey; }
protected AbstractType<?> getComparator(int i, ByteBuffer bb1, ByteBuffer bb2) { return getComparator(i, bb1); }
@Override public Composite fromByteBuffer(ByteBuffer bytes) { if (!bytes.hasRemaining()) return Composites.EMPTY; ByteBuffer[] elements = new ByteBuffer[fullSize]; int idx = bytes.position(), i = 0; byte eoc = 0; boolean isStatic = false; if (CompositeType.isStaticName(bytes)) { isStatic = true; idx += 2; } while (idx < bytes.limit()) { checkRemaining(bytes, idx, 2); int length = bytes.getShort(idx) & 0xFFFF; idx += 2; checkRemaining(bytes, idx, length + 1); elements[i++] = sliceBytes(bytes, idx, length); idx += length; eoc = bytes.get(idx++); } return makeWith(elements, i, Composite.EOC.from(eoc), isStatic); }
public ByteBuffer primaryKey(ByteBuffer rowKey, CellName clusteringKey) { return primaryKeyType.builder().add(rowKey).add(clusteringKey.toByteBuffer()).build(); }
private void serializeCompound(DataOutputPlus out, boolean isDense) throws IOException { List<AbstractType<?>> types = new ArrayList<>(comparator.clusteringComparator.subtypes()); if (!isDense) types.add(UTF8Type.instance); CompositeType type = CompositeType.getInstance(types); for (int i = 0; i < size; i++) { LegacyBound start = starts[i]; LegacyBound end = ends[i]; CompositeType.Builder startBuilder = type.builder(start.isStatic); CompositeType.Builder endBuilder = type.builder(end.isStatic); for (int j = 0; j < start.bound.clustering().size(); j++) { startBuilder.add(start.bound.get(j)); endBuilder.add(end.bound.get(j)); } if (start.collectionName != null) startBuilder.add(start.collectionName.name.bytes); if (end.collectionName != null) endBuilder.add(end.collectionName.name.bytes); ByteBufferUtil.writeWithShortLength(startBuilder.build(), out); ByteBufferUtil.writeWithShortLength(endBuilder.buildAsEndOfRange(), out); out.writeInt(delTimes[i]); out.writeLong(markedAts[i]); } }
List<ByteBuffer> components = CompositeType.splitName(bound); byte eoc = CompositeType.lastEOC(bound); return new LegacyBound(cb, metadata.isCompound() && CompositeType.isStaticName(bound), collectionName);
public ByteBuffer getIndexedValue(ByteBuffer partitionKey, Clustering clustering, CellPath path, ByteBuffer cellValue) { CompositeType keyComparator = (CompositeType)baseCfs.metadata.getKeyValidator(); ByteBuffer[] components = keyComparator.split(partitionKey); return components[indexedColumn.position()]; }
public static Clustering decodeClustering(CFMetaData metadata, ByteBuffer value) { int csize = metadata.comparator.size(); if (csize == 0) return Clustering.EMPTY; if (metadata.isCompound() && CompositeType.isStaticName(value)) return Clustering.STATIC_CLUSTERING; List<ByteBuffer> components = metadata.isCompound() ? CompositeType.splitName(value) : Collections.singletonList(value); return Clustering.make(components.subList(0, Math.min(csize, components.size())).toArray(new ByteBuffer[csize])); }
public ByteBuffer extractLastComponent(ByteBuffer bb) { int idx = types.get(types.size() - 1) instanceof ColumnToCollectionType ? types.size() - 2 : types.size() - 1; return extractComponent(bb, idx); }