Search in sources :

Example 16 with PageProcessor

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

the class TestPageProcessorCompiler method testNoCaching.

@Test
public void testNoCaching() {
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder();
    ArrayType arrayType = new ArrayType(VARCHAR);
    FunctionHandle functionHandle = functionAndTypeManager.lookupFunction("concat", fromTypes(arrayType, arrayType));
    projectionsBuilder.add(new CallExpression("concat", functionHandle, arrayType, ImmutableList.of(field(0, arrayType), field(1, arrayType))));
    ImmutableList<RowExpression> projections = projectionsBuilder.build();
    PageProcessor pageProcessor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), projections).get();
    PageProcessor pageProcessor2 = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), projections).get();
    assertTrue(pageProcessor != pageProcessor2);
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) PageProcessor(com.facebook.presto.operator.project.PageProcessor) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) ImmutableList(com.google.common.collect.ImmutableList) RowExpression(com.facebook.presto.spi.relation.RowExpression) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 17 with PageProcessor

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

the class TestPageProcessorCompiler method testSanityRLE.

@Test
public void testSanityRLE() {
    PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), ImmutableList.of(field(0, BIGINT), field(1, VARCHAR)), false, MAX_BATCH_SIZE).get();
    Slice varcharValue = Slices.utf8Slice("hello");
    Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 123L, 100), RunLengthEncodedBlock.create(VARCHAR, varcharValue, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
    assertTrue(outputPage.getBlock(1) instanceof RunLengthEncodedBlock);
    RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rleBlock.getValue(), 0), 123L);
    RunLengthEncodedBlock rleBlock1 = (RunLengthEncodedBlock) outputPage.getBlock(1);
    assertEquals(VARCHAR.getSlice(rleBlock1.getValue(), 0), varcharValue);
}
Also used : PageProcessor(com.facebook.presto.operator.project.PageProcessor) Slice(io.airlift.slice.Slice) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 18 with PageProcessor

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

the class TestPageProcessorCompiler method testNonDeterministicProject.

@Test
public void testNonDeterministicProject() {
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    FunctionHandle lessThan = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT));
    CallExpression random = new CallExpression("random", functionAndTypeManager.lookupFunction("random", fromTypes(BIGINT)), BIGINT, singletonList(constant(10L, BIGINT)));
    InputReferenceExpression col0 = field(0, BIGINT);
    CallExpression lessThanRandomExpression = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(col0, random));
    PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), ImmutableList.of(lessThanRandomExpression), false, MAX_BATCH_SIZE).get();
    assertFalse(new RowExpressionDeterminismEvaluator(metadataManager.getFunctionAndTypeManager()).isDeterministic(lessThanRandomExpression));
    Page page = new Page(createLongDictionaryBlock(1, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertFalse(outputPage.getBlock(0) instanceof DictionaryBlock);
}
Also used : RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) InputReferenceExpression(com.facebook.presto.spi.relation.InputReferenceExpression) PageProcessor(com.facebook.presto.operator.project.PageProcessor) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 19 with PageProcessor

use of com.facebook.presto.operator.project.PageProcessor 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)

Example 20 with PageProcessor

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

the class TestColumnarPageProcessor method testProcess.

@Test
public void testProcess() {
    PageProcessor processor = newPageProcessor();
    Page page = createPage(types, false);
    Page outputPage = getOnlyElement(processor.process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertPageEquals(types, outputPage, page);
}
Also used : PageProcessor(com.facebook.presto.operator.project.PageProcessor) Page(com.facebook.presto.common.Page) SequencePageBuilder.createSequencePage(com.facebook.presto.SequencePageBuilder.createSequencePage) Test(org.testng.annotations.Test)

Aggregations

PageProcessor (com.facebook.presto.operator.project.PageProcessor)24 Test (org.testng.annotations.Test)18 Page (com.facebook.presto.common.Page)17 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)13 RowExpression (com.facebook.presto.spi.relation.RowExpression)13 DataSize (io.airlift.units.DataSize)12 PageFunctionCompiler (com.facebook.presto.sql.gen.PageFunctionCompiler)9 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)8 CursorProcessor (com.facebook.presto.operator.project.CursorProcessor)8 ConnectorId (com.facebook.presto.spi.ConnectorId)8 Split (com.facebook.presto.metadata.Split)7 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)7 TestingSplit (com.facebook.presto.testing.TestingSplit)7 ExpressionCompiler (com.facebook.presto.sql.gen.ExpressionCompiler)6 MaterializedResult (com.facebook.presto.testing.MaterializedResult)6 ImmutableList (com.google.common.collect.ImmutableList)5 Metadata (com.facebook.presto.metadata.Metadata)4 MetadataManager (com.facebook.presto.metadata.MetadataManager)4 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)4 OperatorAssertion.toMaterializedResult (com.facebook.presto.operator.OperatorAssertion.toMaterializedResult)4