Search in sources :

Example 1 with ConstantPageProjection

use of io.trino.operator.project.ConstantPageProjection 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));
}
Also used : InputReferenceExpression(io.trino.sql.relational.InputReferenceExpression) ConstantPageProjection(io.trino.operator.project.ConstantPageProjection) ConstantExpression(io.trino.sql.relational.ConstantExpression) GeneratedPageProjection(io.trino.operator.project.GeneratedPageProjection) Page(io.trino.spi.Page) ClassDefinition(io.airlift.bytecode.ClassDefinition) TrinoException(io.trino.spi.TrinoException) MethodTooLargeException(org.objectweb.asm.MethodTooLargeException) InputPageProjection(io.trino.operator.project.InputPageProjection) PageFieldsToInputParametersRewriter(io.trino.operator.project.PageFieldsToInputParametersRewriter) MethodTooLargeException(org.objectweb.asm.MethodTooLargeException) SelectedPositions(io.trino.operator.project.SelectedPositions) Work(io.trino.operator.Work) TrinoException(io.trino.spi.TrinoException) ConnectorSession(io.trino.spi.connector.ConnectorSession) BlockBuilder(io.trino.spi.block.BlockBuilder)

Aggregations

ClassDefinition (io.airlift.bytecode.ClassDefinition)1 Work (io.trino.operator.Work)1 ConstantPageProjection (io.trino.operator.project.ConstantPageProjection)1 GeneratedPageProjection (io.trino.operator.project.GeneratedPageProjection)1 InputPageProjection (io.trino.operator.project.InputPageProjection)1 PageFieldsToInputParametersRewriter (io.trino.operator.project.PageFieldsToInputParametersRewriter)1 SelectedPositions (io.trino.operator.project.SelectedPositions)1 Page (io.trino.spi.Page)1 TrinoException (io.trino.spi.TrinoException)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 ConnectorSession (io.trino.spi.connector.ConnectorSession)1 ConstantExpression (io.trino.sql.relational.ConstantExpression)1 InputReferenceExpression (io.trino.sql.relational.InputReferenceExpression)1 MethodTooLargeException (org.objectweb.asm.MethodTooLargeException)1