/** * This is not a stable API, prefer using {@link Schema#newPartialRow()} * to create a new partial row. * @param schema the schema to use for this row */ public PartialRow(Schema schema) { this.schema = schema; this.columnsBitSet = new BitSet(this.schema.getColumnCount()); this.nullsBitSet = schema.hasNullableColumns() ? new BitSet(this.schema.getColumnCount()) : null; this.rowAlloc = new byte[schema.getRowSize()]; // Pre-fill the array with nulls. We'll only replace cells that have varlen values. this.varLengthData = Arrays.asList(new ByteBuffer[this.schema.getColumnCount()]); }
/** * Initializes the state of the encoder based on the schema and number of operations to encode. * * @param schema the schema of the table which the operations belong to. * @param numOperations the number of operations. */ private void init(Schema schema, int numOperations) { this.schema = schema; // Set up the encoded data. // Estimate a maximum size for the data. This is conservative, but avoids // having to loop through all the operations twice. final int columnBitSetSize = Bytes.getBitSetSize(schema.getColumnCount()); int sizePerRow = 1 /* for the op type */ + schema.getRowSize() + columnBitSetSize; if (schema.hasNullableColumns()) { // nullsBitSet is the same size as the columnBitSet sizePerRow += columnBitSetSize; } // TODO: would be more efficient to use a buffer which "chains" smaller allocations // instead of a doubling buffer like BAOS. this.rows = ByteBuffer.allocate(sizePerRow * numOperations) .order(ByteOrder.LITTLE_ENDIAN); this.indirect = new ArrayList<>(schema.getVarLengthColumnCount() * numOperations); }
this.rowSize = getRowSize(this.columnsByIndex);
columnOffsetsSize++; this.rowSize = this.schema.getRowSize(); columnOffsets = new int[columnOffsetsSize];
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); }