use of io.trino.spi.function.SqlType in project trino by trinodb.
the class VarbinaryFunctions method toIEEE754Binary64.
@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;
}
use of io.trino.spi.function.SqlType in project trino by trinodb.
the class VarbinaryFunctions method toBigEndian32.
@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;
}
use of io.trino.spi.function.SqlType in project trino by trinodb.
the class VarbinaryFunctions method spookyHashV2_32.
@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;
}
use of io.trino.spi.function.SqlType in project trino by trinodb.
the class VarbinaryFunctions method toIEEE754Binary32.
@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;
}
use of io.trino.spi.function.SqlType in project trino by trinodb.
the class VarbinaryFunctions method crc32.
@Description("Compute CRC-32")
@ScalarFunction
@SqlType(StandardTypes.BIGINT)
public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice) {
CRC32 crc32 = new CRC32();
crc32.update(slice.toByteBuffer());
return crc32.getValue();
}
Aggregations