public static Slice unscaledDecimal() { return Slices.allocate(UNSCALED_DECIMAL_128_SLICE_LENGTH); }
public static Slice unscaledDecimal(BigInteger unscaledValue) { Slice decimal = Slices.allocate(UNSCALED_DECIMAL_128_SLICE_LENGTH); return pack(unscaledValue, decimal); }
public static Slice varcharToVarcharCreateSliceWithExtraParameterLength(Slice string, int extraParameter) { return Slices.allocate(extraParameter); }
public Slice getSync() { Slice sync = Slices.allocate(SIZE_OF_LONG + SIZE_OF_LONG); sync.setLong(0, syncFirst); sync.setLong(SIZE_OF_LONG, syncSecond); return sync; }
@Description("encode value as a big endian varbinary according to IEEE 754 double-precision floating-point format") @ScalarFunction("to_ieee754_64") @SqlType(StandardTypes.VARBINARY) public static Slice toIEEE754Binary64(@SqlType(StandardTypes.DOUBLE) double value) { Slice slice = Slices.allocate(Double.BYTES); slice.setLong(0, Long.reverseBytes(Double.doubleToLongBits(value))); return slice; }
private static void assertMultiply256(Slice left, Slice right, Slice expected) { Slice actual = Slices.allocate(Long.BYTES * 4); multiply256(left, right, actual); assertEquals(actual, expected); }
@Description("encode value as a 32-bit 2's complement big endian varbinary") @ScalarFunction("to_big_endian_32") @SqlType(StandardTypes.VARBINARY) public static Slice toBigEndian32(@SqlType(StandardTypes.INTEGER) long value) { Slice slice = Slices.allocate(Integer.BYTES); slice.setInt(0, Integer.reverseBytes((int) value)); return slice; }
@Description("encode value as a big endian varbinary according to IEEE 754 single-precision floating-point format") @ScalarFunction("to_ieee754_32") @SqlType(StandardTypes.VARBINARY) public static Slice toIEEE754Binary32(@SqlType(StandardTypes.REAL) long value) { Slice slice = Slices.allocate(Float.BYTES); slice.setInt(0, Integer.reverseBytes((int) value)); return slice; }
@Description("encode value as a 64-bit 2's complement big endian varbinary") @ScalarFunction("to_big_endian_64") @SqlType(StandardTypes.VARBINARY) public static Slice toBigEndian64(@SqlType(StandardTypes.BIGINT) long value) { Slice slice = Slices.allocate(Long.BYTES); slice.setLong(0, Long.reverseBytes(value)); return slice; }
static Slice concatSlice(Slice... slices) { int totalLength = Arrays.stream(slices) .mapToInt(Slice::length) .sum(); Slice value = Slices.allocate(totalLength); SliceOutput output = value.getOutput(); for (Slice slice : slices) { output.writeBytes(slice); } return value; } }
@Description("compute xxhash64 hash") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice xxhash64(@SqlType(StandardTypes.VARBINARY) Slice slice) { Slice hash = Slices.allocate(Long.BYTES); hash.setLong(0, Long.reverseBytes(XxHash64.hash(slice))); return hash; }
@Description("compute SpookyHashV2 32-bit hash") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice spookyHashV2_32(@SqlType(StandardTypes.VARBINARY) Slice slice) { Slice hash = Slices.allocate(Integer.BYTES); hash.setInt(0, Integer.reverseBytes(SpookyHashV2.hash32(slice, 0, slice.length(), 0))); return hash; }
@Description("compute SpookyHashV2 64-bit hash") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice spookyHashV2_64(@SqlType(StandardTypes.VARBINARY) Slice slice) { Slice hash = Slices.allocate(Long.BYTES); hash.setLong(0, Long.reverseBytes(SpookyHashV2.hash64(slice, 0, slice.length(), 0))); return hash; }
private void testIsFull(PageBuilderStatus pageBuilderStatus) { BlockBuilder blockBuilder = new VariableWidthBlockBuilder(pageBuilderStatus.createBlockBuilderStatus(), 32, 1024); assertTrue(pageBuilderStatus.isEmpty()); while (!pageBuilderStatus.isFull()) { VARCHAR.writeSlice(blockBuilder, Slices.allocate(VARCHAR_VALUE_SIZE)); } assertEquals(blockBuilder.getPositionCount(), EXPECTED_ENTRY_COUNT); assertEquals(pageBuilderStatus.isFull(), true); } }
@Override public void serialize(LongDecimalWithOverflowState state, BlockBuilder out) { if (state.getLongDecimal() == null) { out.appendNull(); } else { Slice slice = Slices.allocate(Long.BYTES + UnscaledDecimal128Arithmetic.UNSCALED_DECIMAL_128_SLICE_LENGTH); SliceOutput output = slice.getOutput(); output.writeLong(state.getOverflow()); output.writeBytes(state.getLongDecimal()); VARBINARY.writeSlice(out, slice); } }
@Override public byte[] getSerializedData() { // Serialization format is (<key:int><min:double><max:double>)* SliceOutput output = Slices.allocate((SizeOf.SIZE_OF_INT + 2 * SizeOf.SIZE_OF_DOUBLE) * mins.size()).getOutput(); for (int key : mins.keySet()) { output.appendInt(key); output.appendDouble(mins.get(key)); output.appendDouble(maxs.get(key)); } return output.slice().getBytes(); }
@Override public void serialize(LongDecimalWithOverflowAndLongState state, BlockBuilder out) { if (state.getLongDecimal() == null) { out.appendNull(); } else { Slice slice = Slices.allocate(Long.BYTES + Long.BYTES + UnscaledDecimal128Arithmetic.UNSCALED_DECIMAL_128_SLICE_LENGTH); SliceOutput output = slice.getOutput(); output.writeLong(state.getLong()); output.writeLong(state.getOverflow()); output.writeBytes(state.getLongDecimal()); VARBINARY.writeSlice(out, slice); } }
public Slice serialize() { compact(); int requiredBytes = SizeOf.SIZE_OF_BYTE + // format SizeOf.SIZE_OF_INT + // max buckets SizeOf.SIZE_OF_INT + // entry count SizeOf.SIZE_OF_DOUBLE * nextIndex + // values SizeOf.SIZE_OF_DOUBLE * nextIndex; // weights return Slices.allocate(requiredBytes) .getOutput() .appendByte(FORMAT_TAG) .appendInt(maxBuckets) .appendInt(nextIndex) .appendBytes(Slices.wrappedDoubleArray(values, 0, nextIndex)) .appendBytes(Slices.wrappedDoubleArray(weights, 0, nextIndex)) .getUnderlyingSlice(); }
@Override public void serialize(DigestAndPercentileState state, BlockBuilder out) { if (state.getDigest() == null) { out.appendNull(); } else { Slice serialized = state.getDigest().serialize(); SliceOutput output = Slices.allocate(SIZE_OF_DOUBLE + SIZE_OF_INT + serialized.length()).getOutput(); output.appendDouble(state.getPercentile()); output.appendInt(serialized.length()); output.appendBytes(serialized); VARBINARY.writeSlice(out, output.slice()); } }