/** * Encodes the provided row into a range partition key. * * @param row the row to encode * @param rangeSchema the range partition schema * @return the encoded range partition key */ public static byte[] encodeRangePartitionKey(PartialRow row, PartitionSchema.RangeSchema rangeSchema) { ByteVec buf = ByteVec.create(); encodeColumns(row, rangeSchema.getColumns(), buf); return buf.toArray(); }
/** * Encodes the provided row into a partition key according to the partition schema. * * @param row the row to encode * @param partitionSchema the partition schema describing the table's partitioning * @return an encoded partition key */ public static byte[] encodePartitionKey(PartialRow row, PartitionSchema partitionSchema) { ByteVec buf = ByteVec.create(); if (!partitionSchema.getHashBucketSchemas().isEmpty()) { for (final HashBucketSchema hashSchema : partitionSchema.getHashBucketSchemas()) { encodeHashBucket(getHashBucket(row, hashSchema), buf); } } encodeColumns(row, partitionSchema.getRangeSchema().getColumns(), buf); return buf.toArray(); }
/** * Returns the bucket of the row for the given hash bucket schema. All columns * in the hash bucket schema must be set in the row. * * @param row the row containing hash schema columns * @param hashSchema the hash schema * @return the hash bucket of the row */ public static int getHashBucket(PartialRow row, HashBucketSchema hashSchema) { ByteVec buf = ByteVec.create(); encodeColumns(row, hashSchema.getColumnIds(), buf); long hash = Murmur2.hash64(buf.data(), buf.len(), hashSchema.getSeed()); return (int) UnsignedLongs.remainder(hash, hashSchema.getNumBuckets()); }