use of com.facebook.presto.spi.page.PagesSerde 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)));
}
Aggregations