Search in sources :

Example 1 with RowBlockBuilder

use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.

the class TestSimpleRowType method getGreaterValue.

@Override
protected Object getGreaterValue(Object value) {
    RowBlockBuilder blockBuilder = (RowBlockBuilder) TYPE.createBlockBuilder(null, 1);
    SingleRowBlockWriter singleRowBlockWriter;
    Block block = (Block) value;
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, block.getSingleValueBlock(0).getLong(0, 0) + 1);
    VARCHAR.writeSlice(singleRowBlockWriter, block.getSingleValueBlock(1).getSlice(0, 0, 1));
    blockBuilder.closeEntry();
    return TYPE.getObject(blockBuilder.build(), 0);
}
Also used : RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder) Block(io.prestosql.spi.block.Block) SingleRowBlockWriter(io.prestosql.spi.block.SingleRowBlockWriter)

Example 2 with RowBlockBuilder

use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.

the class BlockAssertions method createRowBlock.

public static Block createRowBlock(List<Type> fieldTypes, Object[]... rows) {
    BlockBuilder rowBlockBuilder = new RowBlockBuilder(fieldTypes, null, 1);
    for (Object[] row : rows) {
        if (row == null) {
            rowBlockBuilder.appendNull();
            continue;
        }
        BlockBuilder singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
        for (Object fieldValue : row) {
            if (fieldValue == null) {
                singleRowBlockWriter.appendNull();
                continue;
            }
            if (fieldValue instanceof String) {
                VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice((String) fieldValue));
            } else if (fieldValue instanceof Slice) {
                VARBINARY.writeSlice(singleRowBlockWriter, (Slice) fieldValue);
            } else if (fieldValue instanceof Double) {
                DOUBLE.writeDouble(singleRowBlockWriter, ((Double) fieldValue).doubleValue());
            } else if (fieldValue instanceof Long) {
                BIGINT.writeLong(singleRowBlockWriter, ((Long) fieldValue).longValue());
            } else if (fieldValue instanceof Boolean) {
                BOOLEAN.writeBoolean(singleRowBlockWriter, ((Boolean) fieldValue).booleanValue());
            } else if (fieldValue instanceof Block) {
                singleRowBlockWriter.appendStructure((Block) fieldValue);
            } else if (fieldValue instanceof Integer) {
                INTEGER.writeLong(singleRowBlockWriter, ((Integer) fieldValue).intValue());
            } else {
                throw new IllegalArgumentException();
            }
        }
        rowBlockBuilder.closeEntry();
    }
    return rowBlockBuilder.build();
}
Also used : BigInteger(java.math.BigInteger) RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) BlockBuilder(io.prestosql.spi.block.BlockBuilder) RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder)

Example 3 with RowBlockBuilder

use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.

the class OperatorAssertion method toRow.

public static Block toRow(List<Type> parameterTypes, Object... values) {
    checkArgument(parameterTypes.size() == values.length, "parameterTypes.size(" + parameterTypes.size() + ") does not equal to values.length(" + values.length + ")");
    RowType rowType = RowType.anonymous(parameterTypes);
    BlockBuilder blockBuilder = new RowBlockBuilder(parameterTypes, null, 1);
    BlockBuilder singleRowBlockWriter = blockBuilder.beginBlockEntry();
    for (int i = 0; i < values.length; i++) {
        appendToBlockBuilder(parameterTypes.get(i), values[i], singleRowBlockWriter);
    }
    blockBuilder.closeEntry();
    return rowType.getObject(blockBuilder, 0);
}
Also used : RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder) RowType(io.prestosql.spi.type.RowType) BlockBuilder(io.prestosql.spi.block.BlockBuilder) StructuralTestUtil.appendToBlockBuilder(io.prestosql.util.StructuralTestUtil.appendToBlockBuilder) RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder)

Example 4 with RowBlockBuilder

use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.

the class TestRowBlock method createBlockBuilderWithValues.

private BlockBuilder createBlockBuilderWithValues(List<Type> fieldTypes, List<Object>[] rows) {
    BlockBuilder rowBlockBuilder = new RowBlockBuilder(fieldTypes, null, 1);
    for (List<Object> row : rows) {
        if (row == null) {
            rowBlockBuilder.appendNull();
        } else {
            BlockBuilder singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
            for (Object fieldValue : row) {
                if (fieldValue == null) {
                    singleRowBlockWriter.appendNull();
                } else {
                    if (fieldValue instanceof Long) {
                        BIGINT.writeLong(singleRowBlockWriter, ((Long) fieldValue).longValue());
                    } else if (fieldValue instanceof String) {
                        VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice((String) fieldValue));
                    } else {
                        throw new IllegalArgumentException();
                    }
                }
            }
            rowBlockBuilder.closeEntry();
        }
    }
    return rowBlockBuilder;
}
Also used : RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder) BlockBuilder(io.prestosql.spi.block.BlockBuilder) RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder)

Example 5 with RowBlockBuilder

use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.

the class TestSimpleRowType method createTestBlock.

private static Block createTestBlock() {
    RowBlockBuilder blockBuilder = (RowBlockBuilder) TYPE.createBlockBuilder(null, 3);
    SingleRowBlockWriter singleRowBlockWriter;
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, 1);
    VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("cat"));
    blockBuilder.closeEntry();
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, 2);
    VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("cats"));
    blockBuilder.closeEntry();
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, 3);
    VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("dog"));
    blockBuilder.closeEntry();
    return blockBuilder.build();
}
Also used : RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder) SingleRowBlockWriter(io.prestosql.spi.block.SingleRowBlockWriter)

Aggregations

RowBlockBuilder (io.prestosql.spi.block.RowBlockBuilder)5 BlockBuilder (io.prestosql.spi.block.BlockBuilder)3 Block (io.prestosql.spi.block.Block)2 SingleRowBlockWriter (io.prestosql.spi.block.SingleRowBlockWriter)2 Slice (io.airlift.slice.Slice)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)1 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)1 RowType (io.prestosql.spi.type.RowType)1 StructuralTestUtil.appendToBlockBuilder (io.prestosql.util.StructuralTestUtil.appendToBlockBuilder)1 BigInteger (java.math.BigInteger)1