public static byte[] writeShort(short num) { byte[] output = new byte[Shorts.BYTES]; writeShort(num, output, 0, output.length); return output; }
public byte[] encodeRowKey(String[] keys) { keyByteBuffer.clear(); for (String key : keys) { if (key == null) { throw new IllegalArgumentException("key cannot be null:" + Arrays.toString(keys)); } byte[] byteKey = Bytes.toBytes(key); keyByteBuffer.putShort((short) byteKey.length); keyByteBuffer.put(byteKey); } byte[] result = new byte[RowConstants.ROWKEY_SHARDID_LEN + keyByteBuffer.position()]; System.arraycopy(keyByteBuffer.array(), 0, result, RowConstants.ROWKEY_SHARDID_LEN, keyByteBuffer.position()); short shard = ShardingHash.getShard(result, RowConstants.ROWKEY_SHARDID_LEN, result.length, shardNum); BytesUtil.writeShort(shard, result, 0, RowConstants.ROWKEY_SHARDID_LEN); return result; }
public void fillHeader(byte[] bytes) { int offset = 0; if (enableSharding) { short shard = calculateShard(bytes); BytesUtil.writeShort(shard, bytes, offset, RowConstants.ROWKEY_SHARDID_LEN); offset += RowConstants.ROWKEY_SHARDID_LEN; } System.arraycopy(cuboid.getBytes(), 0, bytes, offset, RowConstants.ROWKEY_CUBOIDID_LEN); //offset += RowConstants.ROWKEY_CUBOIDID_LEN; //return offset; }
private List<byte[]> getRowKeysDifferentShards(byte[] halfCookedKey) { final short cuboidShardNum = cubeSeg.getCuboidShardNum(cuboid.getId()); if (!cubeSeg.isEnableSharding()) { return Lists.newArrayList(halfCookedKey);//not shard to append at head, so it is already well cooked } else { List<byte[]> ret = Lists.newArrayList(); for (short i = 0; i < cuboidShardNum; ++i) { short shard = ShardingHash.normalize(cubeSeg.getCuboidBaseShard(cuboid.getId()), i, cubeSeg.getTotalShards(cuboid.getId())); byte[] cookedKey = Arrays.copyOf(halfCookedKey, halfCookedKey.length); BytesUtil.writeShort(shard, cookedKey, 0, RowConstants.ROWKEY_SHARDID_LEN); ret.add(cookedKey); } return ret; } }
private static RawScan mockFullScan(GTInfo gtInfo, KylinConfig kylinConfig) { final List<Pair<byte[], byte[]>> selectedColumns = Lists.newArrayList(); selectedColumns.add(new Pair<>(FAM, COL_M)); int headerLength = RowConstants.ROWKEY_SHARD_AND_CUBOID_LEN; int bodyLength = 0; ImmutableBitSet primaryKey = gtInfo.getPrimaryKey(); for (int i = 0; i < primaryKey.trueBitCount(); i++) { bodyLength += gtInfo.getCodeSystem().getDimEnc(primaryKey.trueBitAt(i)).getLengthOfEncoding(); } //Mock start key byte[] start = new byte[headerLength + bodyLength]; BytesUtil.writeShort((short) 0, start, 0, RowConstants.ROWKEY_SHARDID_LEN); System.arraycopy(Bytes.toBytes(baseCuboid), 0, start, RowConstants.ROWKEY_SHARDID_LEN, RowConstants.ROWKEY_CUBOIDID_LEN); //Mock end key byte[] end = new byte[headerLength + bodyLength + 1]; for (int i = 0; i < end.length - 1; i++) { end[i] = RowConstants.ROWKEY_UPPER_BYTE; } BytesUtil.writeShort((short) 0, end, 0, RowConstants.ROWKEY_SHARDID_LEN); System.arraycopy(Bytes.toBytes(baseCuboid), 0, end, RowConstants.ROWKEY_SHARDID_LEN, RowConstants.ROWKEY_CUBOIDID_LEN); //Mock fuzzy key List<Pair<byte[], byte[]>> fuzzyKeys = Collections.emptyList(); return new RawScan(start, end, selectedColumns, fuzzyKeys, kylinConfig.getHBaseScanCacheRows(), kylinConfig.getHBaseScanMaxResultSize()); }
public static byte[] writeShort(short num) { byte[] output = new byte[Shorts.BYTES]; writeShort(num, output, 0, output.length); return output; }
public byte[] encodeRowKey(String[] keys) { keyByteBuffer.clear(); for (String key : keys) { if (key == null) { throw new IllegalArgumentException("key cannot be null:" + Arrays.toString(keys)); } byte[] byteKey = Bytes.toBytes(key); keyByteBuffer.putShort((short) byteKey.length); keyByteBuffer.put(byteKey); } byte[] result = new byte[RowConstants.ROWKEY_SHARDID_LEN + keyByteBuffer.position()]; System.arraycopy(keyByteBuffer.array(), 0, result, RowConstants.ROWKEY_SHARDID_LEN, keyByteBuffer.position()); short shard = ShardingHash.getShard(result, RowConstants.ROWKEY_SHARDID_LEN, result.length, shardNum); BytesUtil.writeShort(shard, result, 0, RowConstants.ROWKEY_SHARDID_LEN); return result; }
public void fillHeader(byte[] bytes) { int offset = 0; if (enableSharding) { short shard = calculateShard(bytes); BytesUtil.writeShort(shard, bytes, offset, RowConstants.ROWKEY_SHARDID_LEN); offset += RowConstants.ROWKEY_SHARDID_LEN; } System.arraycopy(cuboid.getBytes(), 0, bytes, offset, RowConstants.ROWKEY_CUBOIDID_LEN); //offset += RowConstants.ROWKEY_CUBOIDID_LEN; //return offset; }
private List<byte[]> getRowKeysDifferentShards(byte[] halfCookedKey) { final short cuboidShardNum = cubeSeg.getCuboidShardNum(cuboid.getId()); if (!cubeSeg.isEnableSharding()) { return Lists.newArrayList(halfCookedKey);//not shard to append at head, so it is already well cooked } else { List<byte[]> ret = Lists.newArrayList(); for (short i = 0; i < cuboidShardNum; ++i) { short shard = ShardingHash.normalize(cubeSeg.getCuboidBaseShard(cuboid.getId()), i, cubeSeg.getTotalShards(cuboid.getId())); byte[] cookedKey = Arrays.copyOf(halfCookedKey, halfCookedKey.length); BytesUtil.writeShort(shard, cookedKey, 0, RowConstants.ROWKEY_SHARDID_LEN); ret.add(cookedKey); } return ret; } }