/** * Decodes a primary key into a row * * @param schema the table schema * @param key the encoded key * @return the decoded primary key as a row */ public static PartialRow decodePrimaryKey(Schema schema, byte[] key) { PartialRow row = schema.newPartialRow(); ByteBuffer buf = ByteBuffer.wrap(key); buf.order(ByteOrder.BIG_ENDIAN); for (int idx = 0; idx < schema.getPrimaryKeyColumnCount(); idx++) { decodeColumn(buf, row, idx, idx + 1 == schema.getPrimaryKeyColumnCount()); } if (buf.hasRemaining()) { throw new IllegalArgumentException("Unable to decode all primary key bytes"); } return row; }
/** * Decodes a range partition key into a partial row. * * @param schema the schema of the table * @param partitionSchema the partition schema of the table * @param buf the encoded range partition key * @return the decoded range key */ private static PartialRow decodeRangePartitionKey(Schema schema, PartitionSchema partitionSchema, ByteBuffer buf) { PartialRow row = schema.newPartialRow(); Iterator<Integer> rangeIds = partitionSchema.getRangeSchema().getColumns().iterator(); while (rangeIds.hasNext()) { int idx = schema.getColumnIndex(rangeIds.next()); if (buf.hasRemaining()) { decodeColumn(buf, row, idx, !rangeIds.hasNext()); } else { row.setMin(idx); } } if (buf.hasRemaining()) { throw new IllegalArgumentException("Unable to decode all partition key bytes"); } return row; }