use of io.trino.operator.project.InputPageProjection in project trino by trinodb.
the class PageFunctionCompiler method compileProjectionInternal.
private Supplier<PageProjection> compileProjectionInternal(RowExpression projection, Optional<String> classNameSuffix) {
requireNonNull(projection, "projection is null");
if (projection instanceof InputReferenceExpression) {
InputReferenceExpression input = (InputReferenceExpression) projection;
InputPageProjection projectionFunction = new InputPageProjection(input.getField(), input.getType());
return () -> projectionFunction;
}
if (projection instanceof ConstantExpression) {
ConstantExpression constant = (ConstantExpression) projection;
ConstantPageProjection projectionFunction = new ConstantPageProjection(constant.getValue(), constant.getType());
return () -> projectionFunction;
}
PageFieldsToInputParametersRewriter.Result result = rewritePageFieldsToInputParameters(projection);
CallSiteBinder callSiteBinder = new CallSiteBinder();
// generate Work
ClassDefinition pageProjectionWorkDefinition = definePageProjectWorkClass(result.getRewrittenExpression(), callSiteBinder, classNameSuffix);
Class<?> pageProjectionWorkClass;
try {
pageProjectionWorkClass = defineClass(pageProjectionWorkDefinition, Work.class, callSiteBinder.getBindings(), getClass().getClassLoader());
} catch (Exception e) {
if (Throwables.getRootCause(e) instanceof MethodTooLargeException) {
throw new TrinoException(COMPILER_ERROR, "Query exceeded maximum columns. Please reduce the number of columns referenced and re-run the query.", e);
}
throw new TrinoException(COMPILER_ERROR, e);
}
return () -> new GeneratedPageProjection(result.getRewrittenExpression(), isDeterministic(result.getRewrittenExpression()), result.getInputChannels(), constructorMethodHandle(pageProjectionWorkClass, BlockBuilder.class, ConnectorSession.class, Page.class, SelectedPositions.class));
}
use of io.trino.operator.project.InputPageProjection in project trino by trinodb.
the class AbstractOperatorBenchmark method createHashProjectOperator.
protected final OperatorFactory createHashProjectOperator(int operatorId, PlanNodeId planNodeId, List<Type> types) {
SymbolAllocator symbolAllocator = new SymbolAllocator();
ImmutableMap.Builder<Symbol, Integer> symbolToInputMapping = ImmutableMap.builder();
ImmutableList.Builder<PageProjection> projections = ImmutableList.builder();
for (int channel = 0; channel < types.size(); channel++) {
Symbol symbol = symbolAllocator.newSymbol("h" + channel, types.get(channel));
symbolToInputMapping.put(symbol, channel);
projections.add(new InputPageProjection(channel, types.get(channel)));
}
Map<Symbol, Type> symbolTypes = symbolAllocator.getTypes().allTypes();
Optional<Expression> hashExpression = HashGenerationOptimizer.getHashExpression(session, localQueryRunner.getMetadata(), symbolAllocator, ImmutableList.copyOf(symbolTypes.keySet()));
verify(hashExpression.isPresent());
Map<NodeRef<Expression>, Type> expressionTypes = createTestingTypeAnalyzer(localQueryRunner.getPlannerContext()).getTypes(session, TypeProvider.copyOf(symbolTypes), hashExpression.get());
RowExpression translated = translate(hashExpression.get(), expressionTypes, symbolToInputMapping.buildOrThrow(), localQueryRunner.getMetadata(), localQueryRunner.getFunctionManager(), session, false);
PageFunctionCompiler functionCompiler = new PageFunctionCompiler(localQueryRunner.getFunctionManager(), 0);
projections.add(functionCompiler.compileProjection(translated, Optional.empty()).get());
return FilterAndProjectOperator.createOperatorFactory(operatorId, planNodeId, () -> new PageProcessor(Optional.empty(), projections.build()), ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT))), getFilterAndProjectMinOutputPageSize(session), getFilterAndProjectMinOutputPageRowCount(session));
}
Aggregations