/** * Gives the size in bytes for a single row given the specified schema * @param columns the row's columns * @return row size in bytes */ private static int getRowSize(List<ColumnSchema> columns) { int totalSize = 0; boolean hasNullables = false; for (ColumnSchema column : columns) { totalSize += column.getTypeSize(); hasNullables |= column.isNullable(); } if (hasNullables) { totalSize += Bytes.getBitSetSize(columns.size()); } return totalSize; }
offset += column.getTypeSize(); if (this.columnsByName.put(column.getName(), index) != null) { throw new IllegalArgumentException(
private void encodeRow(PartialRow row, ChangeType type) { rows.put(type.toEncodedByte()); rows.put(Bytes.fromBitSet(row.getColumnsBitSet(), schema.getColumnCount())); if (schema.hasNullableColumns()) { rows.put(Bytes.fromBitSet(row.getNullsBitSet(), schema.getColumnCount())); } int colIdx = 0; byte[] rowData = row.getRowAlloc(); int currentRowOffset = 0; for (ColumnSchema col : row.getSchema().getColumns()) { // Keys should always be specified, maybe check? if (row.isSet(colIdx) && !row.isSetToNull(colIdx)) { if (col.getType() == Type.STRING || col.getType() == Type.BINARY) { ByteBuffer varLengthData = row.getVarLengthData().get(colIdx); varLengthData.reset(); rows.putLong(indirectWrittenBytes); int bbSize = varLengthData.remaining(); rows.putLong(bbSize); indirect.add(varLengthData); indirectWrittenBytes += bbSize; } else { // This is for cols other than strings rows.put(rowData, currentRowOffset, col.getTypeSize()); } } currentRowOffset += col.getTypeSize(); colIdx++; } }
case DOUBLE: case DECIMAL: { Preconditions.checkArgument(value.length == column.getTypeSize()); System.arraycopy(value, 0, rowAlloc, getPositionInRowAllocAndSetBitSet(index), value.length);
int previousSize = column.getTypeSize(); columnOffsets[i] = previousSize + currentOffset; currentOffset += previousSize;
int size = column.getTypeSize(); switch (size) { case DecimalUtil.DECIMAL32_SIZE:
/** * Encodes a single column of a row into the output buffer. * @param row the row being encoded * @param columnIdx the column index of the column to encode * @param isLast whether the column is the last component of the key */ private static void encodeColumn(PartialRow row, int columnIdx, boolean isLast, ByteVec buf) { final Schema schema = row.getSchema(); final ColumnSchema column = schema.getColumnByIndex(columnIdx); if (!row.isSet(columnIdx)) { throw new IllegalStateException(String.format("Primary key column %s is not set", column.getName())); } final Type type = column.getType(); if (type == Type.STRING || type == Type.BINARY) { encodeBinary(row.getVarLengthData().get(columnIdx), isLast, buf); } else { encodeSignedInt(row.getRowAlloc(), schema.getColumnOffset(columnIdx), column.getTypeSize(), buf); } }