Search in sources :

Example 31 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class MaterializedResult method appendToPage.

private static void appendToPage(PageBuilder pageBuilder, MaterializedRow row) {
    for (int field = 0; field < row.getFieldCount(); field++) {
        Type type = pageBuilder.getType(field);
        Object value = row.getField(field);
        BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(field);
        writeValue(type, blockBuilder, value);
    }
    pageBuilder.declarePosition();
}
Also used : RowType(com.facebook.presto.type.RowType) ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) CharType(com.facebook.presto.spi.type.CharType) VarcharType(com.facebook.presto.spi.type.VarcharType) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 32 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class RowPageBuilder method append.

private void append(int channel, Object element) {
    BlockBuilder blockBuilder = builders.get(channel);
    Type type = types.get(channel);
    appendToBlockBuilder(type, element, blockBuilder);
}
Also used : Type(com.facebook.presto.spi.type.Type) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) TypeJsonUtils.appendToBlockBuilder(com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder)

Example 33 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class SequencePageBuilder method createSequencePageWithDictionaryBlocks.

public static Page createSequencePageWithDictionaryBlocks(List<? extends Type> types, int length, int... initialValues) {
    Block[] blocks = new Block[initialValues.length];
    for (int i = 0; i < blocks.length; i++) {
        Type type = types.get(i);
        int initialValue = initialValues[i];
        if (type.equals(VARCHAR)) {
            blocks[i] = BlockAssertions.createStringDictionaryBlock(initialValue, initialValue + length);
        } else if (type.equals(BIGINT)) {
            blocks[i] = BlockAssertions.createLongDictionaryBlock(initialValue, initialValue + length);
        } else {
            throw new IllegalStateException("Unsupported type " + type);
        }
    }
    return new Page(blocks);
}
Also used : DecimalType(com.facebook.presto.spi.type.DecimalType) Type(com.facebook.presto.spi.type.Type) VarcharType(com.facebook.presto.spi.type.VarcharType) Block(com.facebook.presto.spi.block.Block) Page(com.facebook.presto.spi.Page)

Example 34 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class TestPagesIndexPageSorter method createOutputPages.

private static List<Page> createOutputPages(List<Type> types, List<Page> inputPages, long[] sortedAddresses) {
    PageBuilder pageBuilder = new PageBuilder(types);
    pageBuilder.reset();
    for (long address : sortedAddresses) {
        int index = sorter.decodePageIndex(address);
        int position = sorter.decodePositionIndex(address);
        Page page = inputPages.get(index);
        for (int i = 0; i < types.size(); i++) {
            Type type = types.get(i);
            type.appendTo(page.getBlock(i), position, pageBuilder.getBlockBuilder(i));
        }
        pageBuilder.declarePosition();
    }
    return ImmutableList.of(pageBuilder.build());
}
Also used : Type(com.facebook.presto.spi.type.Type) Page(com.facebook.presto.spi.Page) PageBuilder(com.facebook.presto.spi.PageBuilder)

Example 35 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class TestPageSplitterUtil method testSplitPage.

@Test
public void testSplitPage() throws Exception {
    int positionCount = 10;
    int maxPageSizeInBytes = 100;
    List<Type> types = ImmutableList.of(BIGINT, BIGINT, BIGINT);
    Page largePage = SequencePageBuilder.createSequencePage(types, positionCount, 0, 1, 1);
    List<Page> pages = PageSplitterUtil.splitPage(largePage, maxPageSizeInBytes);
    assertGreaterThan(pages.size(), 1);
    assertPageSize(pages, maxPageSizeInBytes);
    assertPositionCount(pages, positionCount);
    MaterializedResult actual = toMaterializedResult(TEST_SESSION, types, pages);
    MaterializedResult expected = toMaterializedResult(TEST_SESSION, types, ImmutableList.of(largePage));
    assertEquals(actual, expected);
}
Also used : Type(com.facebook.presto.spi.type.Type) Page(com.facebook.presto.spi.Page) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

Type (com.facebook.presto.spi.type.Type)392 Test (org.testng.annotations.Test)103 Block (com.facebook.presto.spi.block.Block)83 ImmutableList (com.google.common.collect.ImmutableList)79 ArrayType (com.facebook.presto.type.ArrayType)78 MapType (com.facebook.presto.type.MapType)72 Page (com.facebook.presto.spi.Page)68 PrestoException (com.facebook.presto.spi.PrestoException)51 List (java.util.List)50 VarcharType (com.facebook.presto.spi.type.VarcharType)48 DecimalType (com.facebook.presto.spi.type.DecimalType)44 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)40 MaterializedResult (com.facebook.presto.testing.MaterializedResult)40 ArrayList (java.util.ArrayList)40 MethodHandle (java.lang.invoke.MethodHandle)39 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)37 ImmutableMap (com.google.common.collect.ImmutableMap)36 Map (java.util.Map)36 Slice (io.airlift.slice.Slice)35 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)30