private int getRowLength() { org.apache.kudu.util.Slice rawData = getCurrentRowRawData(); if (rawData != null) { return rawData.length(); } else { return columnTypes.size(); } }
@Override public String toString() { return getClass().getSimpleName() + '(' + "length=" + length() + ')'; } }
public static Slice ensureSize(Slice existingSlice, int minWritableBytes) { if (existingSlice == null) { existingSlice = EMPTY_SLICE; } if (minWritableBytes <= existingSlice.length()) { return existingSlice; } int newCapacity; if (existingSlice.length() == 0) { newCapacity = 1; } else { newCapacity = existingSlice.length(); } int minNewCapacity = existingSlice.length() + minWritableBytes; while (newCapacity < minNewCapacity) { newCapacity <<= 1; } Slice newSlice = Slices.allocate(newCapacity); newSlice.setBytes(0, existingSlice, 0, existingSlice.length()); return newSlice; }
private int getRowLength() { org.apache.kudu.util.Slice rawData = getCurrentRowRawData(); if (rawData != null) { return rawData.length(); } else { return columnTypes.size(); } }
private int getRowLength() { org.apache.kudu.util.Slice rawData = getCurrentRowRawData(); if (rawData != null) { return rawData.length(); } else { return columnTypes.size(); } }
/** * @param sidecar The index of the sidecar to retrieve. * @return A slice pointing to the desired sidecar. * @throws IllegalStateException If the sidecar offsets specified in the * header response PB are not valid offsets for the array. * @throws IllegalArgumentException If the sidecar with the specified index * does not exist. */ public Slice getSidecar(int sidecar) { cacheMessage(); List<Integer> sidecarList = this.header.getSidecarOffsetsList(); if (sidecar < 0 || sidecar > sidecarList.size()) { throw new IllegalArgumentException("Sidecar " + sidecar + " not valid, response has " + sidecarList.size() + " sidecars"); } final int prevOffset = sidecarList.get(sidecar); final int nextOffset = sidecar + 1 == sidecarList.size() ? this.message.length() : sidecarList.get(sidecar + 1); final int length = nextOffset - prevOffset; if (prevOffset < 0 || length < 0 || prevOffset + length > this.message.length()) { throw new IllegalStateException("Sidecar " + sidecar + " invalid " + "(offset = " + prevOffset + ", length = " + length + "). The size " + "of the message " + "excluding the header is " + this.message.length()); } return subslice(this.message, prevOffset, length); }
/** * @return A slice pointing to the section of the packet reserved for the main * protobuf message. * @throws IllegalStateException If the offset for the main protobuf message * is not valid. */ public Slice getPBMessage() { cacheMessage(); final int mainLength = this.header.getSidecarOffsetsCount() == 0 ? this.message.length() : this.header.getSidecarOffsets(0); if (mainLength < 0 || mainLength > this.message.length()) { throw new IllegalStateException("Main protobuf message invalid. " + "Length is " + mainLength + " while the size of the message " + "excluding the header is " + this.message.length()); } return subslice(this.message, 0, mainLength); }
static void readProtobuf(final Slice slice, final Builder builder) { final int length = slice.length(); final byte[] payload = slice.getRawArray(); final int offset = slice.getRawOffset(); try { builder.mergeFrom(payload, offset, length); if (!builder.isInitialized()) { throw new RuntimeException("Could not deserialize the response," + " incompatible RPC? Error is: " + builder.getInitializationErrorString()); } } catch (InvalidProtocolBufferException e) { throw new RuntimeException("Invalid RPC response: length=" + length, e); } }
static RowResultIterator makeRowResultIterator(long ellapsedMillis, String tsUUID, Schema schema, WireProtocol.RowwiseRowBlockPB data, final CallResponse callResponse) throws KuduException { if (data == null || data.getNumRows() == 0) { return new RowResultIterator(ellapsedMillis, tsUUID, schema, 0, null, null); } Slice bs = callResponse.getSidecar(data.getRowsSidecar()); Slice indirectBs = callResponse.getSidecar(data.getIndirectDataSidecar()); int numRows = data.getNumRows(); // Integrity check int rowSize = schema.getRowSize(); int expectedSize = numRows * rowSize; if (expectedSize != bs.length()) { Status statusIllegalState = Status.IllegalState("RowResult block has " + bs.length() + " bytes of data but expected " + expectedSize + " for " + numRows + " rows"); throw new NonRecoverableException(statusIllegalState); } return new RowResultIterator(ellapsedMillis, tsUUID, schema, numRows, bs, indirectBs); }