Java Code Examples for io.prestosql.spi.block.Block#getLong()

The following examples show how to use io.prestosql.spi.block.Block#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: ShortTimestampType.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public Object getObjectValue(ConnectorSession session, Block block, int position)
{
    if (block.isNull(position)) {
        return null;
    }

    long value = block.getLong(position, 0);

    if (getPrecision() <= 3) {
        value = scaleEpochMillisToMicros(value);
    }

    if (session.isLegacyTimestamp()) {
        return SqlTimestamp.newLegacyInstance(getPrecision(), value, 0, session.getTimeZoneKey());
    }
    else {
        return SqlTimestamp.newInstance(getPrecision(), value, 0);
    }
}
 
Example 2
Source File: TestingIdType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObjectValue(ConnectorSession session, Block block, int position)
{
    if (block.isNull(position)) {
        return null;
    }

    return block.getLong(position, 0);
}
 
Example 3
Source File: ShortDecimalType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
    long leftValue = leftBlock.getLong(leftPosition, 0);
    long rightValue = rightBlock.getLong(rightPosition, 0);
    return Long.compare(leftValue, rightValue);
}
 
Example 4
Source File: BigintType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObjectValue(ConnectorSession session, Block block, int position)
{
    if (block.isNull(position)) {
        return null;
    }

    return block.getLong(position, 0);
}
 
Example 5
Source File: ShortDecimalType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObjectValue(ConnectorSession session, Block block, int position)
{
    if (block.isNull(position)) {
        return null;
    }
    long unscaledValue = block.getLong(position, 0);
    return new SqlDecimal(BigInteger.valueOf(unscaledValue), getPrecision(), getScale());
}
 
Example 6
Source File: ShortTimestampType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
    long leftValue = leftBlock.getLong(leftPosition, 0);
    long rightValue = rightBlock.getLong(rightPosition, 0);
    return Long.compare(leftValue, rightValue);
}
 
Example 7
Source File: ShortTimestampWithTimeZoneType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObjectValue(ConnectorSession session, Block block, int position)
{
    if (block.isNull(position)) {
        return null;
    }

    long value = block.getLong(position, 0);
    return SqlTimestampWithTimeZone.newInstance(getPrecision(), unpackMillisUtc(value), 0, unpackZoneKey(value));
}
 
Example 8
Source File: TimeType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObjectValue(ConnectorSession session, Block block, int position)
{
    if (block.isNull(position)) {
        return null;
    }

    if (session.isLegacyTimestamp()) {
        return new SqlTime(block.getLong(position, 0), session.getTimeZoneKey());
    }
    else {
        return new SqlTime(block.getLong(position, 0));
    }
}
 
Example 9
Source File: ShortTimestampType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equalTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
    long leftValue = leftBlock.getLong(leftPosition, 0);
    long rightValue = rightBlock.getLong(rightPosition, 0);
    return leftValue == rightValue;
}
 
Example 10
Source File: LongDecimalType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
    long leftLow = leftBlock.getLong(leftPosition, 0);
    long leftHigh = leftBlock.getLong(leftPosition, SIZE_OF_LONG);
    long rightLow = rightBlock.getLong(rightPosition, 0);
    long rightHigh = rightBlock.getLong(rightPosition, SIZE_OF_LONG);
    return compare(leftLow, leftHigh, rightLow, rightHigh);
}
 
Example 11
Source File: BenchmarkGroupByHash.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(POSITIONS)
public long baseline(BaselinePagesData data)
{
    int hashSize = arraySize(GROUP_COUNT, 0.9f);
    int mask = hashSize - 1;
    long[] table = new long[hashSize];
    Arrays.fill(table, -1);

    long groupIds = 0;
    for (Page page : data.getPages()) {
        Block block = page.getBlock(0);
        int positionCount = block.getPositionCount();
        for (int position = 0; position < positionCount; position++) {
            long value = block.getLong(position, 0);

            int tablePosition = (int) (value & mask);
            while (table[tablePosition] != -1 && table[tablePosition] != value) {
                tablePosition++;
            }
            if (table[tablePosition] == -1) {
                table[tablePosition] = value;
                groupIds++;
            }
        }
    }
    return groupIds;
}
 
Example 12
Source File: DecimalInequalityOperators.java    From presto with Apache License 2.0 5 votes vote down vote up
@UsedByGeneratedCode
public static boolean distinctBlockPositionShortShort(Block left, int leftPosition, Block right, int rightPosition)
{
    if (left.isNull(leftPosition) != right.isNull(rightPosition)) {
        return true;
    }
    if (left.isNull(leftPosition)) {
        return false;
    }

    long leftValue = left.getLong(leftPosition, 0);
    long rightValue = right.getLong(rightPosition, 0);
    return Long.compare(leftValue, rightValue) != 0;
}
 
Example 13
Source File: IntervalDayTimeType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObjectValue(ConnectorSession session, Block block, int position)
{
    if (block.isNull(position)) {
        return null;
    }
    return new SqlIntervalDayTime(block.getLong(position, 0));
}
 
Example 14
Source File: UuidType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public boolean equalTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
    return leftBlock.getLong(leftPosition, SIZE_OF_LONG) == rightBlock.getLong(rightPosition, SIZE_OF_LONG) &&
            leftBlock.getLong(leftPosition, 0) == rightBlock.getLong(rightPosition, 0);
}
 
Example 15
Source File: TestReaderProjectionsAdapter.java    From presto with Apache License 2.0 4 votes vote down vote up
private static Block createProjectedColumnBlock(Block data, Type finalType, Type blockType, List<Integer> dereferences)
{
    if (dereferences.size() == 0) {
        return data;
    }

    BlockBuilder builder = finalType.createBlockBuilder(null, data.getPositionCount());

    for (int i = 0; i < data.getPositionCount(); i++) {
        Type sourceType = blockType;

        Block currentData = null;
        boolean isNull = data.isNull(i);

        if (!isNull) {
            // Get SingleRowBlock corresponding to element at position i
            currentData = data.getObject(i, Block.class);
        }

        // Apply all dereferences except for the last one, because the type can be different
        for (int j = 0; j < dereferences.size() - 1; j++) {
            if (isNull) {
                // If null element is discovered at any dereferencing step, break
                break;
            }

            checkArgument(sourceType instanceof RowType);
            if (currentData.isNull(dereferences.get(j))) {
                currentData = null;
            }
            else {
                sourceType = ((RowType) sourceType).getFields().get(dereferences.get(j)).getType();
                currentData = currentData.getObject(dereferences.get(j), Block.class);
            }

            isNull = isNull || (currentData == null);
        }

        if (isNull) {
            // Append null if any of the elements in the dereference chain were null
            builder.appendNull();
        }
        else {
            int lastDereference = dereferences.get(dereferences.size() - 1);

            if (currentData.isNull(lastDereference)) {
                // Append null if the last dereference is null
                builder.appendNull();
            }
            else {
                // Append actual values otherwise
                if (finalType.equals(BIGINT)) {
                    Long value = currentData.getLong(lastDereference, 0);
                    builder.writeLong(value);
                }
                else if (finalType instanceof RowType) {
                    Block block = currentData.getObject(lastDereference, Block.class);
                    builder.appendStructure(block);
                }
                else {
                    throw new UnsupportedOperationException();
                }
            }
        }
    }

    return builder.build();
}
 
Example 16
Source File: ShortTimestampWithTimeZoneType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public final long getLong(Block block, int position)
{
    return block.getLong(position, 0);
}
 
Example 17
Source File: LongTimestampType.java    From presto with Apache License 2.0 4 votes vote down vote up
private static long getEpochMicros(Block block, int position)
{
    return block.getLong(position, 0);
}
 
Example 18
Source File: ShortTimestampType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public final long getLong(Block block, int position)
{
    return block.getLong(position, 0);
}
 
Example 19
Source File: ShortDecimalType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public long hash(Block block, int position)
{
    return block.getLong(position, 0);
}
 
Example 20
Source File: IpAddressType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public boolean equalTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
    return leftBlock.getLong(leftPosition, SIZE_OF_LONG) == rightBlock.getLong(rightPosition, SIZE_OF_LONG) &&
            leftBlock.getLong(leftPosition, 0) == rightBlock.getLong(rightPosition, 0);
}