Java Code Examples for io.airlift.slice.Slice#setLong()

The following examples show how to use io.airlift.slice.Slice#setLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VarbinaryFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 2
Source File: VarbinaryFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 3
Source File: VarbinaryFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 4
Source File: VarbinaryFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 5
Source File: ModelUtils.java    From presto with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes the model using the following format
 * int: format version
 * byte[32]: SHA256 hash of all following data
 * int: id of algorithm
 * int: length of hyperparameters section
 * byte[]: hyperparameters (currently not used)
 * long: length of data section
 * byte[]: model data
 * <p>
 * note: all multibyte values are in little endian
 */
public static Slice serialize(Model model)
{
    requireNonNull(model, "model is null");
    Integer id = MODEL_SERIALIZATION_IDS.get(model.getClass());
    requireNonNull(id, "id is null");
    int size = HYPERPARAMETERS_OFFSET;

    // hyperparameters aren't implemented yet
    byte[] hyperparameters = new byte[0];
    size += hyperparameters.length;

    int dataLengthOffset = size;
    size += SIZE_OF_LONG;
    int dataOffset = size;
    byte[] data = model.getSerializedData();
    size += data.length;

    Slice slice = Slices.allocate(size);
    slice.setInt(VERSION_OFFSET, CURRENT_FORMAT_VERSION);
    slice.setInt(ALGORITHM_OFFSET, id);
    slice.setInt(HYPERPARAMETER_LENGTH_OFFSET, hyperparameters.length);
    slice.setBytes(HYPERPARAMETERS_OFFSET, hyperparameters);
    slice.setLong(dataLengthOffset, data.length);
    slice.setBytes(dataOffset, data);

    byte[] modelHash = Hashing.sha256().hashBytes(slice.getBytes(ALGORITHM_OFFSET, slice.length() - ALGORITHM_OFFSET)).asBytes();
    checkState(modelHash.length == 32, "sha256 hash code expected to be 32 bytes");
    slice.setBytes(HASH_OFFSET, modelHash);

    return slice;
}
 
Example 6
Source File: UnscaledDecimal128Arithmetic.java    From presto with Apache License 2.0 5 votes vote down vote up
public static void pack(long low, long high, boolean negative, Slice result, int resultOffset)
{
    result.setLong(resultOffset, low);

    long value = high | (negative ? SIGN_LONG_MASK : 0);
    result.setLong(resultOffset + SIZE_OF_LONG, value);
}
 
Example 7
Source File: RcFileReader.java    From presto with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: TestTupleDomainParquetPredicate.java    From presto with Apache License 2.0 5 votes vote down vote up
private static byte[] toParquetEncoding(Instant timestamp)
{
    long startOfDay = LocalDate.ofInstant(timestamp, ZoneOffset.UTC).atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli();
    long timeOfDayNanos = (long) ((timestamp.toEpochMilli() - startOfDay) * Math.pow(10, 6));

    Slice slice = Slices.allocate(12);
    slice.setLong(0, timeOfDayNanos);
    slice.setInt(8, millisToJulianDay(timestamp.toEpochMilli()));
    return slice.byteArray();
}
 
Example 9
Source File: UnscaledDecimal128Arithmetic.java    From presto with Apache License 2.0 4 votes vote down vote up
private static void setRawLong(Slice decimal, int index, long value)
{
    decimal.setLong(SIZE_OF_LONG * index, value);
}