Search in sources :

Example 1 with PageFilter

use of io.trino.operator.project.PageFilter in project trino by trinodb.

the class PageFunctionCompiler method compileFilterInternal.

private Supplier<PageFilter> compileFilterInternal(RowExpression filter, Optional<String> classNameSuffix) {
    requireNonNull(filter, "filter is null");
    PageFieldsToInputParametersRewriter.Result result = rewritePageFieldsToInputParameters(filter);
    CallSiteBinder callSiteBinder = new CallSiteBinder();
    ClassDefinition classDefinition = defineFilterClass(result.getRewrittenExpression(), result.getInputChannels(), callSiteBinder, classNameSuffix);
    Class<? extends PageFilter> functionClass;
    try {
        functionClass = defineClass(classDefinition, PageFilter.class, callSiteBinder.getBindings(), getClass().getClassLoader());
    } catch (Exception e) {
        if (Throwables.getRootCause(e) instanceof MethodTooLargeException) {
            throw new TrinoException(COMPILER_ERROR, "Query exceeded maximum filters. Please reduce the number of filters referenced and re-run the query.", e);
        }
        throw new TrinoException(COMPILER_ERROR, filter.toString(), e.getCause());
    }
    return () -> {
        try {
            return functionClass.getConstructor().newInstance();
        } catch (ReflectiveOperationException e) {
            throw new TrinoException(COMPILER_ERROR, e);
        }
    };
}
Also used : PageFieldsToInputParametersRewriter(io.trino.operator.project.PageFieldsToInputParametersRewriter) MethodTooLargeException(org.objectweb.asm.MethodTooLargeException) TrinoException(io.trino.spi.TrinoException) PageFilter(io.trino.operator.project.PageFilter) ClassDefinition(io.airlift.bytecode.ClassDefinition) TrinoException(io.trino.spi.TrinoException) MethodTooLargeException(org.objectweb.asm.MethodTooLargeException)

Example 2 with PageFilter

use of io.trino.operator.project.PageFilter in project trino by trinodb.

the class ExpressionCompiler method compilePageProcessor.

private Supplier<PageProcessor> compilePageProcessor(Optional<RowExpression> filter, List<? extends RowExpression> projections, Optional<String> classNameSuffix, OptionalInt initialBatchSize) {
    Optional<Supplier<PageFilter>> filterFunctionSupplier = filter.map(expression -> pageFunctionCompiler.compileFilter(expression, classNameSuffix));
    List<Supplier<PageProjection>> pageProjectionSuppliers = projections.stream().map(projection -> pageFunctionCompiler.compileProjection(projection, classNameSuffix)).collect(toImmutableList());
    return () -> {
        Optional<PageFilter> filterFunction = filterFunctionSupplier.map(Supplier::get);
        List<PageProjection> pageProjections = pageProjectionSuppliers.stream().map(Supplier::get).collect(toImmutableList());
        return new PageProcessor(filterFunction, pageProjections, initialBatchSize);
    };
}
Also used : CacheStatsMBean(io.airlift.jmx.CacheStatsMBean) ParameterizedType.type(io.airlift.bytecode.ParameterizedType.type) Nested(org.weakref.jmx.Nested) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) OptionalInt(java.util.OptionalInt) Supplier(java.util.function.Supplier) Access.a(io.airlift.bytecode.Access.a) NonEvictableLoadingCache(io.trino.collect.cache.NonEvictableLoadingCache) PageFilter(io.trino.operator.project.PageFilter) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Managed(org.weakref.jmx.Managed) CursorProcessor(io.trino.operator.project.CursorProcessor) Objects.requireNonNull(java.util.Objects.requireNonNull) PageProcessor(io.trino.operator.project.PageProcessor) CompilerUtils.makeClassName(io.trino.util.CompilerUtils.makeClassName) FINAL(io.airlift.bytecode.Access.FINAL) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) BytecodeUtils.invoke(io.trino.sql.gen.BytecodeUtils.invoke) Expressions.constant(io.trino.sql.relational.Expressions.constant) TrinoException(io.trino.spi.TrinoException) PageProjection(io.trino.operator.project.PageProjection) FunctionManager(io.trino.metadata.FunctionManager) CompilerUtils.defineClass(io.trino.util.CompilerUtils.defineClass) CacheLoader(com.google.common.cache.CacheLoader) Objects(java.util.Objects) SafeCaches.buildNonEvictableCache(io.trino.collect.cache.SafeCaches.buildNonEvictableCache) COMPILER_ERROR(io.trino.spi.StandardErrorCode.COMPILER_ERROR) CompilationException(io.airlift.bytecode.CompilationException) List(java.util.List) RowExpression(io.trino.sql.relational.RowExpression) PUBLIC(io.airlift.bytecode.Access.PUBLIC) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CacheBuilder(com.google.common.cache.CacheBuilder) ClassDefinition(io.airlift.bytecode.ClassDefinition) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) PageProcessor(io.trino.operator.project.PageProcessor) Optional(java.util.Optional) Supplier(java.util.function.Supplier) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List)

Aggregations

ClassDefinition (io.airlift.bytecode.ClassDefinition)2 PageFilter (io.trino.operator.project.PageFilter)2 TrinoException (io.trino.spi.TrinoException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 FINAL (io.airlift.bytecode.Access.FINAL)1 PUBLIC (io.airlift.bytecode.Access.PUBLIC)1 Access.a (io.airlift.bytecode.Access.a)1 CompilationException (io.airlift.bytecode.CompilationException)1 ParameterizedType.type (io.airlift.bytecode.ParameterizedType.type)1 CacheStatsMBean (io.airlift.jmx.CacheStatsMBean)1 NonEvictableLoadingCache (io.trino.collect.cache.NonEvictableLoadingCache)1 SafeCaches.buildNonEvictableCache (io.trino.collect.cache.SafeCaches.buildNonEvictableCache)1 FunctionManager (io.trino.metadata.FunctionManager)1 CursorProcessor (io.trino.operator.project.CursorProcessor)1 PageFieldsToInputParametersRewriter (io.trino.operator.project.PageFieldsToInputParametersRewriter)1