private void writeToOutputStream(Slice source, int sourceIndex, int length) { try { source.getBytes(sourceIndex, outputStream, length); } catch (IOException e) { throw new UncheckedIOException(e); } } }
private long parseTimestamp(Slice slice, int offset, int length) { //noinspection deprecation return dateTimeFormatter.parseMillis(new String(slice.getBytes(offset, length), 0)); } }
public static BigInteger unscaledDecimalToBigInteger(Slice decimal) { byte[] bytes = decimal.getBytes(0, UNSCALED_DECIMAL_128_SLICE_LENGTH); // convert to big-endian order reverse(bytes); bytes[0] &= ~SIGN_BYTE_MASK; return new BigInteger(isNegative(decimal) ? -1 : 1, bytes); }
@Override public void encodeValueInto(int depth, Block block, int position, SliceOutput output) { Slice slice = type.getSlice(block, position); byte[] data = slice.getBytes(); slice = Slices.wrappedBuffer(base64Encoder.encode(data)); output.writeBytes(slice); }
@Description("Compute HMAC with SHA512") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice hmacSha512(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) { return wrappedBuffer(Hashing.hmacSha512(key.getBytes()).hashBytes(slice.getBytes()).asBytes()); } }
@Description("encode binary data as base64") @ScalarFunction @SqlType(StandardTypes.VARCHAR) public static Slice toBase64(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.wrappedBuffer(Base64.getEncoder().encode(slice.getBytes())); }
@Override protected Object getGreaterValue(Object value) { byte[] address = ((Slice) value).getBytes(); checkState(++address[address.length - 1] != 0, "Last byte of address is 0xff"); return Slices.wrappedBuffer(address); }
private static UserMetadataItem toUserMetadata(Entry<String, Slice> entry) { return UserMetadataItem.newBuilder() .setName(entry.getKey()) .setValue(ByteString.copyFrom(entry.getValue().getBytes())) .build(); }
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } return new SqlVarbinary(block.getSlice(position, 0, block.getSliceLength(position)).getBytes()); } }
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } return new SqlVarbinary(block.getSlice(position, 0, block.getSliceLength(position)).getBytes()); }
@ScalarOperator(CAST) @SqlType(StandardTypes.HYPER_LOG_LOG) public static Slice castToHyperLogLog(@SqlType(SetDigestType.NAME) Slice slice) { checkArgument(slice.getByte(0) == 1, "Legacy version of SetDigest cannot cast to HyperLogLog"); int hllLength = slice.getInt(SIZE_OF_BYTE); return Slices.wrappedBuffer(slice.getBytes(SIZE_OF_BYTE + SIZE_OF_INT, hllLength)); } }
@Description("encode binary data as base64 using the URL safe alphabet") @ScalarFunction("to_base64url") @SqlType(StandardTypes.VARCHAR) public static Slice toBase64Url(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.wrappedBuffer(Base64.getUrlEncoder().encode(slice.getBytes())); }
private static void assertByteCountWithoutTrailingSpace(byte[] actual, int offset, int length, byte[] expected) { Slice slice = wrappedBuffer(actual); int trimmedLength = byteCountWithoutTrailingSpace(slice, offset, length); byte[] bytes = slice.getBytes(offset, trimmedLength); assertEquals(bytes, expected); }
@Description("decode URL safe base64 encoded binary data") @ScalarFunction("from_base64url") @SqlType(StandardTypes.VARBINARY) public static Slice fromBase64UrlVarbinary(@SqlType(StandardTypes.VARBINARY) Slice slice) { try { return Slices.wrappedBuffer(Base64.getUrlDecoder().decode(slice.getBytes())); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } }
public IntegerDictionary(DictionaryPage dictionaryPage) throws IOException { super(dictionaryPage.getEncoding()); content = new int[dictionaryPage.getDictionarySize()]; IntegerPlainValuesReader intReader = new IntegerPlainValuesReader(); intReader.initFromPage(dictionaryPage.getDictionarySize(), dictionaryPage.getSlice().getBytes(), 0); for (int i = 0; i < content.length; i++) { content[i] = intReader.readInteger(); } }
private Object getExpectedValueLongs(double maxError, long... values) { if (values.length == 0) { return null; } QuantileDigest qdigest = new QuantileDigest(maxError); Arrays.stream(values).forEach(qdigest::add); return new SqlVarbinary(qdigest.serialize().getBytes()); }
public LongDictionary(DictionaryPage dictionaryPage) throws IOException { super(dictionaryPage.getEncoding()); content = new long[dictionaryPage.getDictionarySize()]; LongPlainValuesReader longReader = new LongPlainValuesReader(); longReader.initFromPage(dictionaryPage.getDictionarySize(), dictionaryPage.getSlice().getBytes(), 0); for (int i = 0; i < content.length; i++) { content[i] = longReader.readLong(); } }
public FloatDictionary(DictionaryPage dictionaryPage) throws IOException { super(dictionaryPage.getEncoding()); content = new float[dictionaryPage.getDictionarySize()]; FloatPlainValuesReader floatReader = new FloatPlainValuesReader(); floatReader.initFromPage(dictionaryPage.getDictionarySize(), dictionaryPage.getSlice().getBytes(), 0); for (int i = 0; i < content.length; i++) { content[i] = floatReader.readFloat(); } }
public DoubleDictionary(DictionaryPage dictionaryPage) throws IOException { super(dictionaryPage.getEncoding()); content = new double[dictionaryPage.getDictionarySize()]; DoublePlainValuesReader doubleReader = new DoublePlainValuesReader(); doubleReader.initFromPage(dictionaryPage.getDictionarySize(), dictionaryPage.getSlice().getBytes(), 0); for (int i = 0; i < content.length; i++) { content[i] = doubleReader.readDouble(); } }