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

The following examples show how to use io.airlift.slice.Slice#getLong() . 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: DoubleEncoding.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public Block decodeColumn(ColumnData columnData)
{
    int size = columnData.rowCount();
    BlockBuilder builder = type.createBlockBuilder(null, size);

    Slice slice = columnData.getSlice();
    for (int i = 0; i < size; i++) {
        int length = columnData.getLength(i);
        if (length != 0) {
            checkState(length == SIZE_OF_DOUBLE, "Double should be 8 bytes");

            long longBits = slice.getLong(columnData.getOffset(i));

            // the file format uses big endian
            type.writeDouble(builder, Double.longBitsToDouble(Long.reverseBytes(longBits)));
        }
        else {
            builder.appendNull();
        }
    }
    return builder.build();
}
 
Example 2
Source File: DoubleEncoding.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void decodeValueInto(BlockBuilder builder, Slice slice, int offset, int length)
{
    long longBits = slice.getLong(offset);

    // the file format uses big endian
    double value = Double.longBitsToDouble(Long.reverseBytes(longBits));
    type.writeDouble(builder, value);
}
 
Example 3
Source File: RcFileTester.java    From presto with Apache License 2.0 5 votes vote down vote up
private static List<Long> getSyncPositionsSimple(RcFileReader recordReader, File file)
        throws IOException
{
    List<Long> syncPositions = new ArrayList<>();
    Slice sync = recordReader.getSync();
    long syncFirst = sync.getLong(0);
    long syncSecond = sync.getLong(8);
    long syncPosition = 0;
    try (RcFileDataSource dataSource = new FileRcFileDataSource(file)) {
        while (syncPosition >= 0) {
            syncPosition = findFirstSyncPosition(dataSource, syncPosition, file.length() - syncPosition, syncFirst, syncSecond);
            if (syncPosition > 0) {
                assertEquals(findFirstSyncPosition(dataSource, syncPosition, 1, syncFirst, syncSecond), syncPosition);
                assertEquals(findFirstSyncPosition(dataSource, syncPosition, 2, syncFirst, syncSecond), syncPosition);
                assertEquals(findFirstSyncPosition(dataSource, syncPosition, 10, syncFirst, syncSecond), syncPosition);

                assertEquals(findFirstSyncPosition(dataSource, syncPosition - 1, 1, syncFirst, syncSecond), -1);
                assertEquals(findFirstSyncPosition(dataSource, syncPosition - 2, 2, syncFirst, syncSecond), -1);
                assertEquals(findFirstSyncPosition(dataSource, syncPosition + 1, 1, syncFirst, syncSecond), -1);

                syncPositions.add(syncPosition);
                syncPosition++;
            }
        }
    }
    return syncPositions;
}
 
Example 4
Source File: UnscaledDecimal128Arithmetic.java    From presto with Apache License 2.0 4 votes vote down vote up
private static long getRawLong(Slice decimal, int index)
{
    return decimal.getLong(SIZE_OF_LONG * index);
}