Search in sources :

Example 6 with PageFunctionCompiler

use of com.facebook.presto.sql.gen.PageFunctionCompiler in project presto by prestodb.

the class TestTupleFilterProcessor method testFilter.

@Test
public void testFilter() {
    Page tuplePage = Iterables.getOnlyElement(rowPagesBuilder(BIGINT, VARCHAR, DOUBLE).row(1L, "a", 0.1).build());
    List<Type> outputTypes = ImmutableList.of(VARCHAR, BIGINT, BOOLEAN, DOUBLE, DOUBLE);
    Page inputPage = Iterables.getOnlyElement(rowPagesBuilder(outputTypes).row("a", 1L, true, 0.1, 0.0).row("b", 1L, true, 0.1, 2.0).row("a", 1L, false, 0.1, 2.0).row("a", 0L, false, 0.2, 0.2).build());
    DynamicTupleFilterFactory filterFactory = new DynamicTupleFilterFactory(42, new PlanNodeId("42"), new int[] { 0, 1, 2 }, new int[] { 1, 0, 3 }, outputTypes, SESSION.getSqlFunctionProperties(), SESSION.getSessionFunctions(), new PageFunctionCompiler(createTestMetadataManager(), 0));
    PageProcessor tupleFilterProcessor = filterFactory.createPageProcessor(tuplePage, OptionalInt.of(MAX_BATCH_SIZE)).get();
    Page actualPage = getOnlyElement(tupleFilterProcessor.process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), inputPage)).orElseThrow(() -> new AssertionError("page is not present"));
    Page expectedPage = Iterables.getOnlyElement(rowPagesBuilder(outputTypes).row("a", 1L, true, 0.1, 0.0).row("a", 1L, false, 0.1, 2.0).build());
    assertPageEquals(outputTypes, actualPage, expectedPage);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) PageProcessor(com.facebook.presto.operator.project.PageProcessor) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 7 with PageFunctionCompiler

use of com.facebook.presto.sql.gen.PageFunctionCompiler in project presto by prestodb.

the class AbstractOperatorBenchmark method createHashProjectOperator.

protected final OperatorFactory createHashProjectOperator(int operatorId, PlanNodeId planNodeId, List<Type> types) {
    ImmutableList.Builder<VariableReferenceExpression> variables = ImmutableList.builder();
    ImmutableMap.Builder<VariableReferenceExpression, Integer> variableToInputMapping = ImmutableMap.builder();
    ImmutableList.Builder<PageProjectionWithOutputs> projections = ImmutableList.builder();
    for (int channel = 0; channel < types.size(); channel++) {
        VariableReferenceExpression variable = new VariableReferenceExpression(Optional.empty(), "h" + channel, types.get(channel));
        variables.add(variable);
        variableToInputMapping.put(variable, channel);
        projections.add(new PageProjectionWithOutputs(new InputPageProjection(channel), new int[] { channel }));
    }
    Optional<RowExpression> hashExpression = HashGenerationOptimizer.getHashExpression(localQueryRunner.getMetadata().getFunctionAndTypeManager(), variables.build());
    verify(hashExpression.isPresent());
    RowExpression translatedHashExpression = translate(hashExpression.get(), variableToInputMapping.build());
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(localQueryRunner.getMetadata(), 0);
    projections.add(new PageProjectionWithOutputs(functionCompiler.compileProjection(session.getSqlFunctionProperties(), translatedHashExpression, Optional.empty()).get(), new int[] { types.size() }));
    return new FilterAndProjectOperator.FilterAndProjectOperatorFactory(operatorId, planNodeId, () -> new PageProcessor(Optional.empty(), projections.build()), ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT))), getFilterAndProjectMinOutputPageSize(session), getFilterAndProjectMinOutputPageRowCount(session));
}
Also used : PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RowExpression(com.facebook.presto.spi.relation.RowExpression) PageProjectionWithOutputs(com.facebook.presto.operator.project.PageProjectionWithOutputs) ImmutableMap(com.google.common.collect.ImmutableMap) InputPageProjection(com.facebook.presto.operator.project.InputPageProjection) PageProcessor(com.facebook.presto.operator.project.PageProcessor) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression)

Example 8 with PageFunctionCompiler

use of com.facebook.presto.sql.gen.PageFunctionCompiler in project presto by prestodb.

the class HandTpchQuery6 method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    // select sum(extendedprice * discount) as revenue
    // from lineitem
    // where shipdate >= '1994-01-01'
    // and shipdate < '1995-01-01'
    // and discount >= 0.05
    // and discount <= 0.07
    // and quantity < 24;
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "lineitem", "extendedprice", "discount", "shipdate", "quantity");
    List<Supplier<PageProjectionWithOutputs>> projection = new PageFunctionCompiler(localQueryRunner.getMetadata(), 0).compileProjections(session.getSqlFunctionProperties(), session.getSessionFunctions(), ImmutableList.of(field(0, BIGINT)), false, Optional.empty());
    FilterAndProjectOperator.FilterAndProjectOperatorFactory tpchQuery6Operator = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(1, new PlanNodeId("test"), () -> new PageProcessor(Optional.of(new TpchQuery6Filter()), projection.stream().map(Supplier::get).collect(toImmutableList())), ImmutableList.of(DOUBLE), new DataSize(0, BYTE), 0);
    AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(2, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(doubleSum.bind(ImmutableList.of(0), Optional.empty())), false);
    return ImmutableList.of(tableScanOperator, tpchQuery6Operator, aggregationOperator);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) PageProcessor(com.facebook.presto.operator.project.PageProcessor) OperatorFactory(com.facebook.presto.operator.OperatorFactory) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) DataSize(io.airlift.units.DataSize) Supplier(java.util.function.Supplier) FilterAndProjectOperator(com.facebook.presto.operator.FilterAndProjectOperator)

Example 9 with PageFunctionCompiler

use of com.facebook.presto.sql.gen.PageFunctionCompiler in project presto by prestodb.

the class BenchmarkEqualsOperator method setup.

@Setup
public void setup() {
    MetadataManager metadata = MetadataManager.createTestMetadataManager();
    FunctionAndTypeManager functionAndTypeManager = metadata.getFunctionAndTypeManager();
    ExpressionCompiler expressionCompiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0));
    RowExpression projection = generateComplexComparisonProjection(functionAndTypeManager, FIELDS_COUNT, COMPARISONS_COUNT);
    compiledProcessor = expressionCompiler.compilePageProcessor(SESSION.getSqlFunctionProperties(), Optional.empty(), ImmutableList.of(projection)).get();
}
Also used : MetadataManager(com.facebook.presto.metadata.MetadataManager) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) RowExpression(com.facebook.presto.spi.relation.RowExpression) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) Setup(org.openjdk.jmh.annotations.Setup)

Example 10 with PageFunctionCompiler

use of com.facebook.presto.sql.gen.PageFunctionCompiler in project presto by prestodb.

the class TestFilterAndProjectOperator method test.

@Test
public void test() {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).addSequencePage(100, 0, 0).build();
    MetadataManager metadata = createTestMetadataManager();
    FunctionAndTypeManager functionAndTypeManager = metadata.getFunctionAndTypeManager();
    RowExpression filter = call(BETWEEN.name(), functionAndTypeManager.resolveOperator(BETWEEN, fromTypes(BIGINT, BIGINT, BIGINT)), BOOLEAN, field(1, BIGINT), constant(10L, BIGINT), constant(19L, BIGINT));
    RowExpression field0 = field(0, VARCHAR);
    RowExpression add5 = call(ADD.name(), functionAndTypeManager.resolveOperator(ADD, fromTypes(BIGINT, BIGINT)), BIGINT, field(1, BIGINT), constant(5L, BIGINT));
    ExpressionCompiler compiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0));
    Supplier<PageProcessor> processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field0, add5));
    OperatorFactory operatorFactory = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of(VARCHAR, BIGINT), new DataSize(0, BYTE), 0);
    MaterializedResult expected = MaterializedResult.resultBuilder(driverContext.getSession(), VARCHAR, BIGINT).row("10", 15L).row("11", 16L).row("12", 17L).row("13", 18L).row("14", 19L).row("15", 20L).row("16", 21L).row("17", 22L).row("18", 23L).row("19", 24L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) RowExpression(com.facebook.presto.spi.relation.RowExpression) Page(com.facebook.presto.common.Page) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) MetadataManager(com.facebook.presto.metadata.MetadataManager) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) PageProcessor(com.facebook.presto.operator.project.PageProcessor) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) DataSize(io.airlift.units.DataSize) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

PageFunctionCompiler (com.facebook.presto.sql.gen.PageFunctionCompiler)12 PageProcessor (com.facebook.presto.operator.project.PageProcessor)8 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)8 ExpressionCompiler (com.facebook.presto.sql.gen.ExpressionCompiler)8 RowExpression (com.facebook.presto.spi.relation.RowExpression)7 Page (com.facebook.presto.common.Page)6 MetadataManager (com.facebook.presto.metadata.MetadataManager)6 DataSize (io.airlift.units.DataSize)6 Test (org.testng.annotations.Test)6 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)4 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)4 ImmutableList (com.google.common.collect.ImmutableList)4 Metadata (com.facebook.presto.metadata.Metadata)3 Split (com.facebook.presto.metadata.Split)3 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)2 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)2 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)2 FilterAndProjectOperator (com.facebook.presto.operator.FilterAndProjectOperator)2 PageRecordSet (com.facebook.presto.operator.index.PageRecordSet)2 CursorProcessor (com.facebook.presto.operator.project.CursorProcessor)2