Search in sources :

Example 1 with PrestoThriftBlock

use of com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock in project presto by prestodb.

the class PrestoThriftEquatableValueSet method fromEquatableValueSet.

public static PrestoThriftEquatableValueSet fromEquatableValueSet(EquatableValueSet valueSet) {
    Type type = valueSet.getType();
    Set<ValueEntry> values = valueSet.getEntries();
    List<PrestoThriftBlock> thriftValues = new ArrayList<>(values.size());
    for (ValueEntry value : values) {
        checkState(type.equals(value.getType()), "ValueEntrySet has elements of different types: %s vs %s", type, value.getType());
        thriftValues.add(fromBlock(value.getBlock(), type));
    }
    return new PrestoThriftEquatableValueSet(valueSet.isWhiteList(), thriftValues);
}
Also used : Type(com.facebook.presto.common.type.Type) PrestoThriftBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock) ArrayList(java.util.ArrayList) ValueEntry(com.facebook.presto.common.predicate.EquatableValueSet.ValueEntry)

Example 2 with PrestoThriftBlock

use of com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock in project presto by prestodb.

the class ThriftSqlFunctionExecutor method buildThriftPage.

private ThriftUdfPage buildThriftPage(RemoteScalarFunctionImplementation functionImplementation, Page input, List<Integer> channels, List<Type> argumentTypes) {
    ThriftUdfPageFormat pageFormat = executionConfigs.get(functionImplementation.getLanguage()).getThriftPageFormat();
    Block[] blocks = new Block[channels.size()];
    for (int i = 0; i < channels.size(); i++) {
        blocks[i] = input.getBlock(channels.get(i));
    }
    switch(pageFormat) {
        case PRESTO_THRIFT:
            ImmutableList.Builder<PrestoThriftBlock> thriftBlocks = ImmutableList.builder();
            for (int i = 0; i < blocks.length; i++) {
                thriftBlocks.add(PrestoThriftBlock.fromBlock(blocks[i], argumentTypes.get(i)));
            }
            return thriftPage(new PrestoThriftPage(thriftBlocks.build(), input.getPositionCount()));
        case PRESTO_SERIALIZED:
            checkState(blockEncodingSerde != null, "blockEncodingSerde not set");
            PagesSerde pagesSerde = new PagesSerde(blockEncodingSerde, Optional.empty(), Optional.empty(), Optional.empty());
            return prestoPage(pagesSerde.serialize(wrapBlocksWithoutCopy(input.getPositionCount(), blocks)));
        default:
            throw new IllegalArgumentException(format("Unknown page format: %s", pageFormat));
    }
}
Also used : PrestoThriftBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock) PrestoThriftPage(com.facebook.presto.thrift.api.udf.PrestoThriftPage) PagesSerde(com.facebook.presto.spi.page.PagesSerde) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PrestoThriftBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock) Block(com.facebook.presto.common.block.Block) ThriftUdfPageFormat(com.facebook.presto.thrift.api.udf.ThriftUdfPageFormat)

Example 3 with PrestoThriftBlock

use of com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock in project presto by prestodb.

the class ThriftIndexedTpchService method thriftPageToList.

private static List<List<String>> thriftPageToList(PrestoThriftPageResult page, int begin, int end) {
    checkArgument(begin <= end, "invalid interval");
    if (begin == end) {
        // empty interval
        return ImmutableList.of();
    }
    List<PrestoThriftBlock> blocks = page.getColumnBlocks();
    List<List<String>> result = new ArrayList<>(blocks.size());
    for (PrestoThriftBlock block : blocks) {
        result.add(blockAsList(block, begin, end));
    }
    return result;
}
Also used : PrestoThriftBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

PrestoThriftBlock (com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 Block (com.facebook.presto.common.block.Block)1 ValueEntry (com.facebook.presto.common.predicate.EquatableValueSet.ValueEntry)1 Type (com.facebook.presto.common.type.Type)1 PagesSerde (com.facebook.presto.spi.page.PagesSerde)1 PrestoThriftPage (com.facebook.presto.thrift.api.udf.PrestoThriftPage)1 ThriftUdfPageFormat (com.facebook.presto.thrift.api.udf.ThriftUdfPageFormat)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 List (java.util.List)1