Refine search
@Nullable @Override public Comparable apply(final @Nullable String token) { return (Comparable) tkValidator.compose(tkValidator.fromString(token)); } }
public static List<String> asCQLTypeStringList(List<AbstractType<?>> abstractTypes) { List<String> r = new ArrayList<>(abstractTypes.size()); for (AbstractType<?> abstractType : abstractTypes) r.add(abstractType.asCQL3Type().toString()); return r; }
protected Object cassandraToObj(AbstractType validator, ByteBuffer value) { if (validator instanceof DecimalType || validator instanceof InetAddressType) return validator.getString(value); if (validator instanceof CollectionType) { // For CollectionType, the compose() method assumes the v3 protocol format of collection, which // is not correct here since we query using the CQL-over-thrift interface which use the pre-v3 format return ((CollectionSerializer)validator.getSerializer()).deserializeForNativeProtocol(value, nativeProtocolVersion); } return validator.compose(value); }
/** * Compose column value. * * @param cqlMetadata * the cql metadata * @param thriftColumnValue * the thrift column value * @param thriftColumnName * the thrift column name * @return the object */ private Object composeColumnValue(CqlMetadata cqlMetadata, byte[] thriftColumnValue, byte[] thriftColumnName) { Map<ByteBuffer, String> schemaTypes = cqlMetadata.getValue_types(); AbstractType<?> type = null; try { type = TypeParser.parse(schemaTypes.get(ByteBuffer.wrap(thriftColumnName))); } catch (SyntaxException | ConfigurationException ex) { log.error(ex.getMessage()); throw new KunderaException("Error while deserializing column value " + ex); } if (type.isCollection()) { return ((CollectionSerializer) type.getSerializer()) .deserializeForNativeProtocol(ByteBuffer.wrap(thriftColumnValue), ProtocolVersion.V2); } return type.compose(ByteBuffer.wrap(thriftColumnValue)); }
public default String toCQLString(CFMetaData metadata) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < size(); i++) { ColumnDefinition c = metadata.clusteringColumns().get(i); sb.append(i == 0 ? "" : ", ").append(c.type.getString(get(i))); } return sb.toString(); }
public int compareCollectionMembers(ByteBuffer o1, ByteBuffer o2, ByteBuffer collectionName) { CollectionType t = defined.get(collectionName); if (t == null) throw new RuntimeException(ByteBufferUtil.bytesToHex(collectionName) + " is not defined as a collection"); return t.nameComparator().compare(o1, o2); }
public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters) throws InvalidRequestException { ByteBuffer bb = parameters.get(0); if (bb == null) return ByteBufferUtil.bytes("null"); return ByteBufferUtil.bytes(argTypes.get(0).getSerializer().deserialize(bb).toString()); }
private void maybeLogLargePartitionWarning(DecoratedKey key, long rowSize) { if (rowSize > DatabaseDescriptor.getCompactionLargePartitionWarningThreshold()) { String keyString = metadata.getKeyValidator().getString(key.getKey()); logger.warn("Compacting large partition {}/{}:{} ({} bytes)", metadata.ksName, metadata.cfName, keyString, rowSize); } }
private void validateOperationOnDurations(AbstractType<?> type) { if (type.referencesDuration() && operator.isSlice()) { checkFalse(type.isCollection(), "Slice conditions are not supported on collections containing durations"); checkFalse(type.isTuple(), "Slice conditions are not supported on tuples containing durations"); checkFalse(type.isUDT(), "Slice conditions are not supported on UDTs containing durations"); throw invalidRequest("Slice conditions are not supported on durations", operator); } } }
/** * Compose and add. * * @param entity * the entity * @param cqlMetadata * the cql metadata * @param thriftColumnValue * the thrift column value * @param thriftColumnName * the thrift column name */ private void composeAndAdd(HashMap entity, CqlMetadata cqlMetadata, Object thriftColumnValue, String thriftColumnName) { byte[] columnName = thriftColumnName.getBytes(); Map<ByteBuffer, String> schemaTypes = this.clientBase.getCqlMetadata().getValue_types(); AbstractType<?> type = null; try { type = TypeParser.parse(schemaTypes.get(ByteBuffer.wrap((byte[]) columnName))); } catch (SyntaxException | ConfigurationException e) { log.error(e.getMessage()); throw new KunderaException("Error while parsing CQL Type " + e); } entity.put(thriftColumnName, type.compose(ByteBuffer.wrap((byte[]) thriftColumnValue))); }
public String asCqlString(CFMetaData cfm) { if (!cfm.getColumnDefinition(column).type.isCollection()) return column.toCQLString(); return String.format("%s(%s)", type.toString(), column.toCQLString()); }
private void validateCellPath(CellPath path) { if (!isComplex()) throw new MarshalException("Only complex cells should have a cell path"); assert type.isMultiCell(); if (type.isCollection()) ((CollectionType)type).nameComparator().validate(path.get(0)); else ((UserType)type).nameComparator().validate(path.get(0)); }
public static ByteBuffer fromString(AbstractType<?> atype, String v) throws IOException { if (atype instanceof BytesType) return ByteBuffer.wrap(Base64.getDecoder().decode(v)); return atype.fromString(v); }
public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters) { ByteBuffer bb = parameters.get(0); if (bb == null) return null; return outputType().decompose(inputType().getSerializer().toCQLLiteral(bb)); } }
/** * Returns the Java Driver {@link com.datastax.driver.core.DataType} for the C* internal type. */ public static DataType driverType(AbstractType abstractType) { CQL3Type cqlType = abstractType.asCQL3Type(); String abstractTypeDef = cqlType.getType().toString(); return driverTypeFromAbstractType(abstractTypeDef); }
private void writeType(AbstractType<?> type, DataOutputPlus out) throws IOException { // TODO: we should have a terser serializaion format. Not a big deal though ByteBufferUtil.writeWithVIntLength(UTF8Type.instance.decompose(type.toString()), out); }
public ByteBuffer decompose(Object... objects) { assert objects.length == types.size(); ByteBuffer[] serialized = new ByteBuffer[objects.length]; for (int i = 0; i < objects.length; i++) { ByteBuffer buffer = ((AbstractType) types.get(i)).decompose(objects[i]); serialized[i] = buffer; } return build(serialized); }
private static ByteBuffer min(ByteBuffer b1, ByteBuffer b2, AbstractType<?> comparator) { if (b1 == null) return b2; if (b2 == null) return b1; if (comparator.compare(b1, b2) >= 0) return b2; return b1; }
@Override public String toString() { return comparator.getString(token); }