Search in sources :

Example 1 with SingleRowBlock

use of com.facebook.presto.common.block.SingleRowBlock in project presto by prestodb.

the class TestRowBlock method assertValueUnchecked.

private void assertValueUnchecked(Block rowBlock, int internalPosition, List<Object> row) {
    // null rows are handled by assertPositionValue
    requireNonNull(row, "row is null");
    assertFalse(rowBlock.mayHaveNull() && rowBlock.isNullUnchecked(internalPosition));
    SingleRowBlock singleRowBlock = (SingleRowBlock) rowBlock.getBlockUnchecked(internalPosition);
    assertEquals(singleRowBlock.getPositionCount(), row.size());
    for (int i = 0; i < row.size(); i++) {
        Object fieldValue = row.get(i);
        if (fieldValue == null) {
            assertTrue(singleRowBlock.isNullUnchecked(i + singleRowBlock.getOffsetBase()));
        } else {
            if (fieldValue instanceof Long) {
                assertEquals(BIGINT.getLongUnchecked(singleRowBlock, i + singleRowBlock.getOffsetBase()), ((Long) fieldValue).longValue());
            } else if (fieldValue instanceof String) {
                assertEquals(VARCHAR.getSliceUnchecked(singleRowBlock, i + singleRowBlock.getOffsetBase()), utf8Slice((String) fieldValue));
            } else {
                fail("Unexpected type: " + fieldValue.getClass().getSimpleName());
            }
        }
    }
}
Also used : SingleRowBlock(com.facebook.presto.common.block.SingleRowBlock)

Example 2 with SingleRowBlock

use of com.facebook.presto.common.block.SingleRowBlock in project presto by prestodb.

the class TestRowBlock method assertValue.

private void assertValue(Block rowBlock, int position, List<Object> row) {
    // null rows are handled by assertPositionValue
    requireNonNull(row, "row is null");
    assertFalse(rowBlock.isNull(position));
    SingleRowBlock singleRowBlock = (SingleRowBlock) rowBlock.getBlock(position);
    assertEquals(singleRowBlock.getPositionCount(), row.size());
    for (int i = 0; i < row.size(); i++) {
        Object fieldValue = row.get(i);
        if (fieldValue == null) {
            assertTrue(singleRowBlock.isNull(i));
        } else {
            if (fieldValue instanceof Long) {
                assertEquals(BIGINT.getLong(singleRowBlock, i), ((Long) fieldValue).longValue());
            } else if (fieldValue instanceof String) {
                assertEquals(VARCHAR.getSlice(singleRowBlock, i), utf8Slice((String) fieldValue));
            } else {
                throw new IllegalArgumentException();
            }
        }
    }
}
Also used : SingleRowBlock(com.facebook.presto.common.block.SingleRowBlock)

Aggregations

SingleRowBlock (com.facebook.presto.common.block.SingleRowBlock)2