Search in sources :

Example 1 with PrestoThriftPage

use of com.facebook.presto.thrift.api.udf.PrestoThriftPage 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 2 with PrestoThriftPage

use of com.facebook.presto.thrift.api.udf.PrestoThriftPage in project presto by prestodb.

the class EchoFirstInputThriftUdfService method invokeUdf.

@Override
public ListenableFuture<ThriftUdfResult> invokeUdf(ThriftUdfRequest request) throws ThriftUdfServiceException {
    ThriftUdfPage inputs = request.getInputs();
    ThriftUdfPage result;
    switch(inputs.getPageFormat()) {
        case PRESTO_THRIFT:
            PrestoThriftPage thriftPage = inputs.getThriftPage();
            if (thriftPage.getThriftBlocks().isEmpty()) {
                throw toThriftUdfServiceException(false, EchoFirstInputErrorCode.GENERIC_INTERNAL_ERROR.toErrorCode(), new UnsupportedOperationException("No input to echo"));
            }
            result = thriftPage(new PrestoThriftPage(ImmutableList.of(thriftPage.getThriftBlocks().get(0)), inputs.getThriftPage().getPositionCount()));
            break;
        case PRESTO_SERIALIZED:
            PagesSerde pagesSerde = new PagesSerde(blockEncodingSerde, Optional.empty(), Optional.empty(), Optional.empty());
            Page page = pagesSerde.deserialize(inputs.getPrestoPage().toSerializedPage());
            if (page.getChannelCount() == 0) {
                throw toThriftUdfServiceException(false, EchoFirstInputErrorCode.GENERIC_INTERNAL_ERROR.toErrorCode(), new UnsupportedOperationException("No input to echo"));
            }
            result = prestoPage(pagesSerde.serialize(new Page(page.getBlock(0))));
            break;
        default:
            throw new UnsupportedOperationException();
    }
    return immediateFuture(new ThriftUdfResult(result, new ThriftUdfStats(100)));
}
Also used : PrestoThriftPage(com.facebook.presto.thrift.api.udf.PrestoThriftPage) PagesSerde(com.facebook.presto.spi.page.PagesSerde) ThriftUdfStats(com.facebook.presto.thrift.api.udf.ThriftUdfStats) Page(com.facebook.presto.common.Page) ThriftUdfPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage) ThriftUdfPage.prestoPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage.prestoPage) ThriftUdfPage.thriftPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage.thriftPage) PrestoThriftPage(com.facebook.presto.thrift.api.udf.PrestoThriftPage) ThriftUdfResult(com.facebook.presto.thrift.api.udf.ThriftUdfResult) ThriftUdfPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage)

Aggregations

PagesSerde (com.facebook.presto.spi.page.PagesSerde)2 PrestoThriftPage (com.facebook.presto.thrift.api.udf.PrestoThriftPage)2 Page (com.facebook.presto.common.Page)1 Block (com.facebook.presto.common.block.Block)1 PrestoThriftBlock (com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock)1 ThriftUdfPage (com.facebook.presto.thrift.api.udf.ThriftUdfPage)1 ThriftUdfPage.prestoPage (com.facebook.presto.thrift.api.udf.ThriftUdfPage.prestoPage)1 ThriftUdfPage.thriftPage (com.facebook.presto.thrift.api.udf.ThriftUdfPage.thriftPage)1 ThriftUdfPageFormat (com.facebook.presto.thrift.api.udf.ThriftUdfPageFormat)1 ThriftUdfResult (com.facebook.presto.thrift.api.udf.ThriftUdfResult)1 ThriftUdfStats (com.facebook.presto.thrift.api.udf.ThriftUdfStats)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1