Search in sources :

Example 1 with SourceOperator

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

the class TestOrcPageSourceMemoryTracking method testTableScanOperator.

@Test
public void testTableScanOperator() throws Exception {
    // Numbers used in assertions in this test may change when implementation is modified,
    // feel free to change them if they break in the future
    DriverContext driverContext = testPreparer.newDriverContext();
    SourceOperator operator = testPreparer.newTableScanOperator(driverContext);
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
    long memoryUsage = -1;
    for (int i = 0; i < 20; i++) {
        assertFalse(operator.isFinished());
        Page page = operator.getOutput();
        assertNotNull(page);
        page.getBlock(1);
        if (memoryUsage == -1) {
            memoryUsage = driverContext.getSystemMemoryUsage();
            assertBetweenInclusive(memoryUsage, 460000L, 469999L);
        } else {
            assertEquals(driverContext.getSystemMemoryUsage(), memoryUsage);
        }
    }
    memoryUsage = -1;
    for (int i = 20; i < 40; i++) {
        assertFalse(operator.isFinished());
        Page page = operator.getOutput();
        assertNotNull(page);
        page.getBlock(1);
        if (memoryUsage == -1) {
            memoryUsage = driverContext.getSystemMemoryUsage();
            assertBetweenInclusive(memoryUsage, 460000L, 469999L);
        } else {
            assertEquals(driverContext.getSystemMemoryUsage(), memoryUsage);
        }
    }
    memoryUsage = -1;
    for (int i = 40; i < 50; i++) {
        assertFalse(operator.isFinished());
        Page page = operator.getOutput();
        assertNotNull(page);
        page.getBlock(1);
        if (memoryUsage == -1) {
            memoryUsage = driverContext.getSystemMemoryUsage();
            assertBetweenInclusive(memoryUsage, 360000L, 369999L);
        } else {
            assertEquals(driverContext.getSystemMemoryUsage(), memoryUsage);
        }
    }
    assertFalse(operator.isFinished());
    assertNull(operator.getOutput());
    assertTrue(operator.isFinished());
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
}
Also used : DriverContext(com.facebook.presto.operator.DriverContext) SourceOperator(com.facebook.presto.operator.SourceOperator) Page(com.facebook.presto.spi.Page) Test(org.testng.annotations.Test)

Example 2 with SourceOperator

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

the class FunctionAssertions method executeFilter.

private static boolean executeFilter(SourceOperatorFactory operatorFactory, Split split, Session session) {
    SourceOperator operator = operatorFactory.createOperator(createDriverContext(session));
    operator.addSplit(split);
    operator.noMoreSplits();
    return executeFilter(operator);
}
Also used : SourceOperator(com.facebook.presto.operator.SourceOperator)

Example 3 with SourceOperator

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

the class TestOrcPageSourceMemoryTracking method testScanFilterAndProjectOperator.

@Test
public void testScanFilterAndProjectOperator() throws Exception {
    // Numbers used in assertions in this test may change when implementation is modified,
    // feel free to change them if they break in the future
    DriverContext driverContext = testPreparer.newDriverContext();
    SourceOperator operator = testPreparer.newScanFilterAndProjectOperator(driverContext);
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
    for (int i = 0; i < 52; i++) {
        assertFalse(operator.isFinished());
        operator.getOutput();
        assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 550000L, 639999L);
    }
    for (int i = 52; i < 65; i++) {
        assertFalse(operator.isFinished());
        operator.getOutput();
        assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 450000L, 539999L);
    }
    // Page source is over, but data still exist in buffer of ScanFilterProjectOperator
    assertFalse(operator.isFinished());
    assertNull(operator.getOutput());
    assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 100000L, 109999L);
    assertFalse(operator.isFinished());
    Page lastPage = operator.getOutput();
    assertNotNull(lastPage);
    // No data is left
    assertTrue(operator.isFinished());
    // an empty page builder of two variable width block builders is left in ScanFilterAndProjectOperator
    PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(createUnboundedVarcharType(), createUnboundedVarcharType()));
    for (int i = 0; i < lastPage.getPositionCount(); i++) {
        pageBuilder.declarePosition();
        createUnboundedVarcharType().appendTo(lastPage.getBlock(0), i, pageBuilder.getBlockBuilder(0));
        createUnboundedVarcharType().appendTo(lastPage.getBlock(1), i, pageBuilder.getBlockBuilder(1));
    }
    pageBuilder.reset();
    assertEquals(driverContext.getSystemMemoryUsage(), pageBuilder.getRetainedSizeInBytes());
}
Also used : DriverContext(com.facebook.presto.operator.DriverContext) SourceOperator(com.facebook.presto.operator.SourceOperator) Page(com.facebook.presto.spi.Page) PageBuilder(com.facebook.presto.spi.PageBuilder) Test(org.testng.annotations.Test)

Example 4 with SourceOperator

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

the class FunctionAssertions method selectSingleValue.

private Object selectSingleValue(SourceOperatorFactory operatorFactory, Split split, Session session) {
    SourceOperator operator = operatorFactory.createOperator(createDriverContext(session));
    operator.addSplit(split);
    operator.noMoreSplits();
    return selectSingleValue(operator);
}
Also used : SourceOperator(com.facebook.presto.operator.SourceOperator)

Example 5 with SourceOperator

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

the class FunctionAssertions method selectSingleValue.

private Object selectSingleValue(SourceOperatorFactory operatorFactory, Type type, Split split, Session session) {
    SourceOperator operator = operatorFactory.createOperator(createDriverContext(session));
    operator.addSplit(split);
    operator.noMoreSplits();
    return selectSingleValue(operator, type);
}
Also used : SourceOperator(com.facebook.presto.operator.SourceOperator)

Aggregations

SourceOperator (com.facebook.presto.operator.SourceOperator)7 DriverContext (com.facebook.presto.operator.DriverContext)4 Test (org.testng.annotations.Test)4 Page (com.facebook.presto.common.Page)2 Page (com.facebook.presto.spi.Page)2 PageBuilder (com.facebook.presto.spi.PageBuilder)1