Refine search
public void testIncrement() throws IOException { long timeStamp = 111111; MutationProto.Builder mutateBuilder = MutationProto.newBuilder(); mutateBuilder.setRow(ByteString.copyFromUtf8("row")); mutateBuilder.setMutateType(MutationType.INCREMENT); ColumnValue.Builder valueBuilder = ColumnValue.newBuilder(); valueBuilder.setFamily(ByteString.copyFromUtf8("f1")); QualifierValue.Builder qualifierBuilder = QualifierValue.newBuilder(); qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c1")); qualifierBuilder.setValue(ByteString.copyFrom(Bytes.toBytes(11L))); qualifierBuilder.setTimestamp(timeStamp); assertEquals(MutationProto.Durability.USE_DEFAULT, proto.getDurability()); mutateBuilder = MutationProto.newBuilder(proto); mutateBuilder.setDurability(MutationProto.Durability.USE_DEFAULT); Increment increment = ProtobufUtil.toIncrement(proto, null); mutateBuilder.setTimestamp(increment.getTimestamp()); mutateBuilder.setTimeRange(ProtobufUtil.toTimeRange(increment.getTimeRange())); assertEquals(mutateBuilder.build(), ProtobufUtil.toMutation(MutationType.INCREMENT, increment));
hash = (19 * hash) + getDescriptorForType().hashCode(); if (hasRow()) { hash = (37 * hash) + ROW_FIELD_NUMBER; hash = (53 * hash) + getRow().hashCode(); if (hasMutateType()) { hash = (37 * hash) + MUTATE_TYPE_FIELD_NUMBER; hash = (53 * hash) + hashEnum(getMutateType()); if (getColumnValueCount() > 0) { hash = (37 * hash) + COLUMN_VALUE_FIELD_NUMBER; hash = (53 * hash) + getColumnValueList().hashCode(); if (hasTimestamp()) { hash = (37 * hash) + TIMESTAMP_FIELD_NUMBER; hash = (53 * hash) + hashLong(getTimestamp()); if (getAttributeCount() > 0) { hash = (37 * hash) + ATTRIBUTE_FIELD_NUMBER; hash = (53 * hash) + getAttributeList().hashCode(); if (hasDurability()) { hash = (37 * hash) + DURABILITY_FIELD_NUMBER; hash = (53 * hash) + hashEnum(getDurability()); if (hasTimeRange()) { hash = (37 * hash) + TIME_RANGE_FIELD_NUMBER; hash = (53 * hash) + getTimeRange().hashCode();
result = result && (hasRow() == other.hasRow()); if (hasRow()) { result = result && getRow() .equals(other.getRow()); result = result && (hasMutateType() == other.hasMutateType()); if (hasMutateType()) { result = result && (getMutateType() == other.getMutateType()); result = result && getColumnValueList() .equals(other.getColumnValueList()); result = result && (hasTimestamp() == other.hasTimestamp()); if (hasTimestamp()) { result = result && (getTimestamp() == other.getTimestamp()); result = result && getAttributeList() .equals(other.getAttributeList()); result = result && (hasDurability() == other.hasDurability()); if (hasDurability()) { result = result && (getDurability() == other.getDurability()); result = result && (hasTimeRange() == other.hasTimeRange()); if (hasTimeRange()) { result = result && getTimeRange() .equals(other.getTimeRange());
public void testAppend() throws IOException { long timeStamp = 111111; MutationProto.Builder mutateBuilder = MutationProto.newBuilder(); mutateBuilder.setRow(ByteString.copyFromUtf8("row")); mutateBuilder.setMutateType(MutationType.APPEND); mutateBuilder.setTimestamp(timeStamp); ColumnValue.Builder valueBuilder = ColumnValue.newBuilder(); valueBuilder.setFamily(ByteString.copyFromUtf8("f1")); QualifierValue.Builder qualifierBuilder = QualifierValue.newBuilder(); qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c1")); qualifierBuilder.setValue(ByteString.copyFromUtf8("v1")); qualifierBuilder.setTimestamp(timeStamp); assertEquals(MutationProto.Durability.USE_DEFAULT, proto.getDurability()); mutateBuilder = MutationProto.newBuilder(proto); mutateBuilder.setDurability(MutationProto.Durability.USE_DEFAULT); Append append = ProtobufUtil.toAppend(proto, null); mutateBuilder.setTimeRange(ProtobufUtil.toTimeRange(append.getTimeRange())); assertEquals(mutateBuilder.build(), ProtobufUtil.toMutation(MutationType.APPEND, append));
MutationProto.Builder mutateBuilder = MutationProto.newBuilder(); mutateBuilder.setRow(ByteString.copyFromUtf8("row")); mutateBuilder.setMutateType(MutationType.PUT); mutateBuilder.setTimestamp(111111); ColumnValue.Builder valueBuilder = ColumnValue.newBuilder(); valueBuilder.setFamily(ByteString.copyFromUtf8("f1")); QualifierValue.Builder qualifierBuilder = QualifierValue.newBuilder(); qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c1")); qualifierBuilder.setValue(ByteString.copyFromUtf8("v1")); valueBuilder.addQualifierValue(qualifierBuilder.build()); assertEquals(MutationProto.Durability.USE_DEFAULT, proto.getDurability()); mutateBuilder = MutationProto.newBuilder(proto); mutateBuilder.setDurability(MutationProto.Durability.USE_DEFAULT); Put put = ProtobufUtil.toPut(proto); ProtobufUtil.toMutation(MutationType.PUT, put));
MutationProto.Builder mutateBuilder = MutationProto.newBuilder(); mutateBuilder.setRow(ByteString.copyFromUtf8("row")); mutateBuilder.setMutateType(MutationType.DELETE); mutateBuilder.setTimestamp(111111); ColumnValue.Builder valueBuilder = ColumnValue.newBuilder(); valueBuilder.setFamily(ByteString.copyFromUtf8("f1")); QualifierValue.Builder qualifierBuilder = QualifierValue.newBuilder(); qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c1")); qualifierBuilder.setDeleteType(DeleteType.DELETE_ONE_VERSION); qualifierBuilder.setTimestamp(111222); assertEquals(MutationProto.Durability.USE_DEFAULT, proto.getDurability()); mutateBuilder = MutationProto.newBuilder(proto); mutateBuilder.setDurability(MutationProto.Durability.USE_DEFAULT); Delete delete = ProtobufUtil.toDelete(proto); ProtobufUtil.toMutation(MutationType.DELETE, delete));
throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.PUT: type.name(); long timestamp = proto.hasTimestamp()? proto.getTimestamp(): HConstants.LATEST_TIMESTAMP; Put put = proto.hasRow() ? new Put(proto.getRow().toByteArray(), timestamp) : null; int cellCount = proto.hasAssociatedCellCount()? proto.getAssociatedCellCount(): 0; if (cellCount > 0) { toShortString(proto)); " no cell returned: " + toShortString(proto)); for (ColumnValue column: proto.getColumnValueList()) { byte[] family = column.getFamily().toByteArray(); for (QualifierValue qv: column.getQualifierValueList()) { if (!qv.hasValue()) { allTagsBytes = qv.getTags().toByteArray(); if(qv.hasDeleteType()) { put.add(cellBuilder.clear() put.setDurability(toDurability(proto.getDurability())); for (NameBytesPair attribute: proto.getAttributeList()) { put.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
private static <T extends Mutation> T toDelta(Function<Bytes, T> supplier, ConsumerWithException<T, Cell> consumer, final MutationProto proto, final CellScanner cellScanner) throws IOException { byte[] row = proto.hasRow() ? proto.getRow().toByteArray() : null; T mutation = row == null ? null : supplier.apply(new Bytes(row)); int cellCount = proto.hasAssociatedCellCount() ? proto.getAssociatedCellCount() : 0; if (cellCount > 0) { toShortString(proto)); " no cell returned: " + toShortString(proto)); throw new IllegalArgumentException("row cannot be null"); for (ColumnValue column : proto.getColumnValueList()) { byte[] family = column.getFamily().toByteArray(); for (QualifierValue qv : column.getQualifierValueList()) { byte[] qualifier = qv.getQualifier().toByteArray(); if (!qv.hasValue()) { throw new DoNotRetryIOException( mutation.setDurability(toDurability(proto.getDurability())); for (NameBytesPair attribute : proto.getAttributeList()) { mutation.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
MutationType type = proto.getMutateType(); assert type == MutationType.INCREMENT || type == MutationType.APPEND : type.name(); byte[] row = proto.hasRow() ? proto.getRow().toByteArray() : null; Get get = null; int cellCount = proto.hasAssociatedCellCount() ? proto.getAssociatedCellCount() : 0; if (cellCount > 0) { for (ColumnValue column : proto.getColumnValueList()) { byte[] family = column.getFamily().toByteArray(); for (QualifierValue qv : column.getQualifierValueList()) { byte[] qualifier = qv.getQualifier().toByteArray(); if (!qv.hasValue()) { throw new DoNotRetryIOException("Missing required field: qualifier value"); if (proto.hasTimeRange()) { TimeRange timeRange = protoToTimeRange(proto.getTimeRange()); get.setTimeRange(timeRange.getMin(), timeRange.getMax()); for (NameBytesPair attribute : proto.getAttributeList()) { get.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
MutationType type = proto.getMutateType(); assert type == MutationType.DELETE : type.name(); long timestamp = proto.hasTimestamp() ? proto.getTimestamp() : HConstants.LATEST_TIMESTAMP; Delete delete = proto.hasRow() ? new Delete(proto.getRow().toByteArray(), timestamp) : null; int cellCount = proto.hasAssociatedCellCount()? proto.getAssociatedCellCount(): 0; if (cellCount > 0) { throw new IllegalArgumentException("row cannot be null"); for (ColumnValue column: proto.getColumnValueList()) { byte[] family = column.getFamily().toByteArray(); for (QualifierValue qv: column.getQualifierValueList()) { DeleteType deleteType = qv.getDeleteType(); byte[] qualifier = null; if (qv.hasQualifier()) { qualifier = qv.getQualifier().toByteArray(); delete.setDurability(toDurability(proto.getDurability())); for (NameBytesPair attribute: proto.getAttributeList()) { delete.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
/** * Print out some subset of a MutationProto rather than all of it and its data * @param proto Protobuf to print out * @return Short String of mutation proto */ static String toShortString(final MutationProto proto) { return "row=" + Bytes.toString(proto.getRow().toByteArray()) + ", type=" + proto.getMutateType().toString(); }
/** * Create a protocol buffer Mutate based on a client Mutation * * @param type * @param mutation * @return a protobuf'd Mutation * @throws IOException */ public static MutationProto toMutation(final MutationType type, final Mutation mutation, final long nonce) throws IOException { return toMutation(type, mutation, MutationProto.newBuilder(), nonce); }
/** * Convert a MutateRequest to Mutation * * @param proto the protocol buffer Mutate to convert * @return the converted Mutation * @throws IOException */ public static Mutation toMutation(final MutationProto proto) throws IOException { MutationType type = proto.getMutateType(); if (type == MutationType.APPEND) { return toAppend(proto, null); } if (type == MutationType.DELETE) { return toDelete(proto, null); } if (type == MutationType.PUT) { return toPut(proto, null); } throw new IOException("Unknown mutation type " + type); }
MutationProto m = action.getMutation(); Mutation mutation; if (m.getMutateType() == MutationType.PUT) { mutation = ProtobufUtil.toPut(m, cells); batchContainsPuts = true; } else { mutation = ProtobufUtil.toDelete(m, cells); batchContainsDelete = true;
@Override public Mutation deserialize(Mutation mutation) throws IOException { ClientProtos.MutationProto.Builder builder = ClientProtos.MutationProto.newBuilder(); ProtobufUtil.mergeDelimitedFrom(builder, in); ClientProtos.MutationProto proto = builder.build(); return ProtobufUtil.toMutation(proto); }
long before = EnvironmentEdgeManager.currentTime(); try { Get get = ProtobufUtil.toGet(action.getGet()); r = region.get(get); } finally { MutationType type = action.getMutation().getMutateType(); if (type != MutationType.PUT && type != MutationType.DELETE && mutations != null && !mutations.isEmpty()) { ClientProtos.Result pbResult = null; if (isClientCellBlockSupport()) { pbResult = ProtobufUtil.toResultNoData(r); pbResult = ProtobufUtil.toResult(r);
/** * Convert a protocol buffer Mutate to an Append * @param cellScanner * @param proto the protocol buffer Mutate to convert * @return the converted client Append * @throws IOException */ public static Append toAppend(final MutationProto proto, final CellScanner cellScanner) throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.APPEND : type.name(); Append append = toDelta((Bytes row) -> new Append(row.get(), row.getOffset(), row.getLength()), Append::add, proto, cellScanner); if (proto.hasTimeRange()) { TimeRange timeRange = protoToTimeRange(proto.getTimeRange()); append.setTimeRange(timeRange.getMin(), timeRange.getMax()); } return append; }
Result r = null; Boolean processed = null; MutationType type = mutation.getMutateType(); long mutationSize = 0; quota = getQuotaManager().checkQuota(region, OperationQuota.OperationType.MUTATE); break; case PUT: Put put = ProtobufUtil.toPut(mutation, cellScanner); quota.addMutation(put); if (request.hasCondition()) { CompareOp compareOp = CompareOp.valueOf(condition.getCompareType().name()); ByteArrayComparable comparator = ProtobufUtil.toComparator(condition.getComparator()); if (region.getCoprocessorHost() != null) { processed = region.getCoprocessorHost().preCheckAndPut( Delete delete = ProtobufUtil.toDelete(mutation, cellScanner); quota.addMutation(delete); if (request.hasCondition()) {
/** * Create a protocol buffer MutationProto based on a client Mutation. Does NOT include data. * Understanding is that the Cell will be transported other than via protobuf. * @param type * @param mutation * @return a protobuf'd Mutation * @throws IOException */ public static MutationProto toMutationNoData(final MutationType type, final Mutation mutation) throws IOException { MutationProto.Builder builder = MutationProto.newBuilder(); return toMutationNoData(type, mutation, builder); }
throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.PUT: type.name(); long timestamp = proto.hasTimestamp()? proto.getTimestamp(): HConstants.LATEST_TIMESTAMP; Put put = proto.hasRow() ? new Put(proto.getRow().toByteArray(), timestamp) : null; int cellCount = proto.hasAssociatedCellCount()? proto.getAssociatedCellCount(): 0; if (cellCount > 0) { for (ColumnValue column: proto.getColumnValueList()) { byte[] family = column.getFamily().toByteArray(); for (QualifierValue qv: column.getQualifierValueList()) { put.add(new KeyValue(proto.getRow().toByteArray(), family, qual, ts, fromDeleteType(qv.getDeleteType()), null, tags)); } else { put.addImmutable(family, qualifier, ts, value, tagArray); if(qv.hasDeleteType()) { byte[] qual = qv.hasQualifier() ? qv.getQualifier().toByteArray() : null; put.add(new KeyValue(proto.getRow().toByteArray(), family, qual, ts, fromDeleteType(qv.getDeleteType()))); } else{ put.setDurability(toDurability(proto.getDurability())); for (NameBytesPair attribute: proto.getAttributeList()) { put.setAttribute(attribute.getName(), attribute.getValue().toByteArray());