Search in sources :

Example 1 with PageFilter

use of com.facebook.presto.operator.project.PageFilter in project presto by prestodb.

the class PageFunctionCompiler method compileFilterInternal.

private Supplier<PageFilter> compileFilterInternal(SqlFunctionProperties sqlFunctionProperties, Map<SqlFunctionId, SqlInvokedFunction> sessionFunctions, RowExpression filter, boolean isOptimizeCommonSubExpression, Optional<String> classNameSuffix) {
    requireNonNull(filter, "filter is null");
    PageFieldsToInputParametersRewriter.Result result = rewritePageFieldsToInputParameters(filter);
    CallSiteBinder callSiteBinder = new CallSiteBinder();
    ClassDefinition classDefinition = defineFilterClass(sqlFunctionProperties, sessionFunctions, result.getRewrittenExpression(), result.getInputChannels(), callSiteBinder, isOptimizeCommonSubExpression, classNameSuffix);
    Class<? extends PageFilter> functionClass;
    try {
        functionClass = defineClass(classDefinition, PageFilter.class, callSiteBinder.getBindings(), getClass().getClassLoader());
    } catch (PrestoException prestoException) {
        throw prestoException;
    } catch (Exception e) {
        throw new PrestoException(COMPILER_ERROR, filter.toString(), e.getCause());
    }
    return () -> {
        try {
            return functionClass.getConstructor().newInstance();
        } catch (ReflectiveOperationException e) {
            throw new PrestoException(COMPILER_ERROR, e);
        }
    };
}
Also used : PageFieldsToInputParametersRewriter(com.facebook.presto.operator.project.PageFieldsToInputParametersRewriter) CallSiteBinder(com.facebook.presto.bytecode.CallSiteBinder) PageFilter(com.facebook.presto.operator.project.PageFilter) PrestoException(com.facebook.presto.spi.PrestoException) ClassDefinition(com.facebook.presto.bytecode.ClassDefinition) PrestoException(com.facebook.presto.spi.PrestoException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException)

Example 2 with PageFilter

use of com.facebook.presto.operator.project.PageFilter in project presto by prestodb.

the class TestPageFunctionCompiler method testCommonSubExpressionInFilter.

@Test
public void testCommonSubExpressionInFilter() {
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(createTestMetadataManager(), 0);
    Supplier<PageFilter> pageFilter = functionCompiler.compileFilter(SESSION.getSqlFunctionProperties(), new SpecialFormExpression(AND, BIGINT, ADD_X_Y_GREATER_THAN_2, ADD_X_Y_LESS_THAN_10), true, Optional.empty());
    Page input = createLongBlockPage(2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    SelectedPositions positions = filter(pageFilter.get(), input);
    assertEquals(positions.size(), 3);
    assertEquals(positions.getPositions(), new int[] { 2, 3, 4 });
}
Also used : SelectedPositions(com.facebook.presto.operator.project.SelectedPositions) PageFilter(com.facebook.presto.operator.project.PageFilter) Page(com.facebook.presto.common.Page) SpecialFormExpression(com.facebook.presto.spi.relation.SpecialFormExpression) Test(org.testng.annotations.Test)

Aggregations

PageFilter (com.facebook.presto.operator.project.PageFilter)2 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)1 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)1 Page (com.facebook.presto.common.Page)1 PageFieldsToInputParametersRewriter (com.facebook.presto.operator.project.PageFieldsToInputParametersRewriter)1 SelectedPositions (com.facebook.presto.operator.project.SelectedPositions)1 PrestoException (com.facebook.presto.spi.PrestoException)1 SpecialFormExpression (com.facebook.presto.spi.relation.SpecialFormExpression)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 Test (org.testng.annotations.Test)1