Search in sources :

Example 96 with BlockBuilder

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

the class TestIpPrefixType method createTestBlock.

public static Block createTestBlock() {
    BlockBuilder blockBuilder = IPPREFIX.createBlockBuilder(null, 1);
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8320/48"));
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8321/48"));
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8322/48"));
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8323/48"));
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8324/48"));
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8325/48"));
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8326/48"));
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8327/48"));
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8328/48"));
    IPPREFIX.writeSlice(blockBuilder, getSliceForPrefix("2001:db8::ff00:42:8329/48"));
    return blockBuilder.build();
}
Also used : BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 97 with BlockBuilder

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

the class TestJsonType method createTestBlock.

public static Block createTestBlock() {
    BlockBuilder blockBuilder = JSON.createBlockBuilder(null, 1);
    Slice slice = Slices.utf8Slice("{\"x\":1, \"y\":2}");
    JSON.writeSlice(blockBuilder, slice);
    return blockBuilder.build();
}
Also used : Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 98 with BlockBuilder

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

the class PassthroughQueryPageSource method getNextPage.

@Override
public Page getNextPage() {
    if (done) {
        return null;
    }
    done = true;
    PageBuilder page = new PageBuilder(1, ImmutableList.of(jsonType));
    page.declarePosition();
    BlockBuilder column = page.getBlockBuilder(0);
    jsonType.writeSlice(column, Slices.utf8Slice(result));
    return page.build();
}
Also used : PageBuilder(com.facebook.presto.common.PageBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 99 with BlockBuilder

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

the class NodesSystemTable method pageSource.

@Override
public ConnectorPageSource pageSource(ConnectorTransactionHandle transaction, ConnectorSession session, TupleDomain<Integer> constraint) {
    Set<ElasticsearchNode> nodes = client.getNodes();
    BlockBuilder nodeId = VARCHAR.createBlockBuilder(null, nodes.size());
    BlockBuilder prestoAddress = VARCHAR.createBlockBuilder(null, nodes.size());
    BlockBuilder elasticsearchNodeId = VARCHAR.createBlockBuilder(null, nodes.size());
    BlockBuilder elasticsearchAddress = VARCHAR.createBlockBuilder(null, nodes.size());
    for (ElasticsearchNode node : nodes) {
        VARCHAR.writeString(nodeId, currentNode.getNodeIdentifier());
        VARCHAR.writeString(prestoAddress, currentNode.getHostAndPort().toString());
        VARCHAR.writeString(elasticsearchNodeId, node.getId());
        if (node.getAddress().isPresent()) {
            VARCHAR.writeString(elasticsearchAddress, node.getAddress().get());
        } else {
            elasticsearchAddress.appendNull();
        }
    }
    return new FixedPageSource(ImmutableList.of(new Page(nodeId.build(), prestoAddress.build(), elasticsearchNodeId.build(), elasticsearchAddress.build())));
}
Also used : ElasticsearchNode(com.facebook.presto.elasticsearch.client.ElasticsearchNode) Page(com.facebook.presto.common.Page) FixedPageSource(com.facebook.presto.spi.FixedPageSource) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 100 with BlockBuilder

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

the class ScanQueryPageSource method getNextPage.

@Override
public Page getNextPage() {
    long size = 0;
    while (size < PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES && iterator.hasNext()) {
        SearchHit hit = iterator.next();
        Map<String, Object> document = hit.getSourceAsMap();
        for (int i = 0; i < decoders.size(); i++) {
            String field = columns.get(i).getName();
            decoders.get(i).decode(hit, () -> getField(document, field), columnBuilders[i]);
        }
        if (hit.getSourceRef() != null) {
            totalBytes += hit.getSourceRef().length();
        }
        completedPositions += 1;
        size = Arrays.stream(columnBuilders).mapToLong(BlockBuilder::getSizeInBytes).sum();
    }
    Block[] blocks = new Block[columnBuilders.length];
    for (int i = 0; i < columnBuilders.length; i++) {
        blocks[i] = columnBuilders[i].build();
        columnBuilders[i] = columnBuilders[i].newBlockBuilderLike(null);
    }
    return new Page(blocks);
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Aggregations

BlockBuilder (com.facebook.presto.common.block.BlockBuilder)493 Block (com.facebook.presto.common.block.Block)124 Test (org.testng.annotations.Test)106 Slice (io.airlift.slice.Slice)85 Type (com.facebook.presto.common.type.Type)76 Page (com.facebook.presto.common.Page)49 SqlType (com.facebook.presto.spi.function.SqlType)46 ArrayType (com.facebook.presto.common.type.ArrayType)44 MapType (com.facebook.presto.common.type.MapType)32 RowType (com.facebook.presto.common.type.RowType)28 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)26 RowBlockBuilder (com.facebook.presto.common.block.RowBlockBuilder)22 PrestoException (com.facebook.presto.spi.PrestoException)22 PageBuilder (com.facebook.presto.common.PageBuilder)21 StructuralTestUtil.appendToBlockBuilder (com.facebook.presto.util.StructuralTestUtil.appendToBlockBuilder)21 Map (java.util.Map)21 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)20 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)19 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)18 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)18