Search in sources :

Example 1 with PageProjection

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

the class TestPageFunctionCompiler method testGeneratedClassName.

@Test
public void testGeneratedClassName() {
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(createTestMetadataManager(), 0);
    String planNodeId = "7";
    String stageId = "20170707_223500_67496_zguwn.2";
    String classSuffix = stageId + "_" + planNodeId;
    Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(SESSION.getSqlFunctionProperties(), ADD_10_EXPRESSION, Optional.of(classSuffix));
    PageProjection projection = projectionSupplier.get();
    Work<List<Block>> work = projection.project(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), createLongBlockPage(1, 0), SelectedPositions.positionsRange(0, 1));
    // class name should look like PageProjectionOutput_20170707_223500_67496_zguwn_2_7_XX
    assertTrue(work.getClass().getSimpleName().startsWith("PageProjectionWork_" + stageId.replace('.', '_') + "_" + planNodeId));
}
Also used : PageProjection(com.facebook.presto.operator.project.PageProjection) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 2 with PageProjection

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

the class TestPageFunctionCompiler method testFailureDoesNotCorruptFutureResults.

@Test
public void testFailureDoesNotCorruptFutureResults() {
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(createTestMetadataManager(), 0);
    Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(SESSION.getSqlFunctionProperties(), ADD_10_EXPRESSION, Optional.empty());
    PageProjection projection = projectionSupplier.get();
    // process good page and verify we got the expected number of result rows
    Page goodPage = createLongBlockPage(1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    Block goodResult = project(projection, goodPage, SelectedPositions.positionsRange(0, goodPage.getPositionCount())).get(0);
    assertEquals(goodPage.getPositionCount(), goodResult.getPositionCount());
    // addition will throw due to integer overflow
    Page badPage = createLongBlockPage(1, 0, 1, 2, 3, 4, Long.MAX_VALUE);
    try {
        project(projection, badPage, SelectedPositions.positionsRange(0, 100));
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NUMERIC_VALUE_OUT_OF_RANGE.toErrorCode());
    }
    // running the good page should still work
    // if block builder in generated code was not reset properly, we could get junk results after the failure
    goodResult = project(projection, goodPage, SelectedPositions.positionsRange(0, goodPage.getPositionCount())).get(0);
    assertEquals(goodPage.getPositionCount(), goodResult.getPositionCount());
}
Also used : PageProjection(com.facebook.presto.operator.project.PageProjection) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) PrestoException(com.facebook.presto.spi.PrestoException) Test(org.testng.annotations.Test)

Aggregations

PageProjection (com.facebook.presto.operator.project.PageProjection)2 Test (org.testng.annotations.Test)2 Page (com.facebook.presto.common.Page)1 Block (com.facebook.presto.common.block.Block)1 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)1 PrestoException (com.facebook.presto.spi.PrestoException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 List (java.util.List)1