use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestDictionaryAwarePageProjection method testProjectRange.
private static void testProjectRange(Block block, Class<? extends Block> expectedResultType, DictionaryAwarePageProjection projection, boolean forceYield) {
DriverYieldSignal yieldSignal = new DriverYieldSignal();
Work<List<Block>> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsRange(5, 10));
List<Block> result;
if (forceYield) {
result = projectWithYield(work, yieldSignal);
} else {
assertTrue(work.process());
result = work.getResult();
}
assertBlockEquals(BIGINT, result.get(0), block.getRegion(5, 10));
assertInstanceOf(result.get(0), expectedResultType);
}
use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestPageProcessor method testYieldProjection.
@Test
public void testYieldProjection() {
// each projection can finish without yield
// while between two projections, there is a yield
int rows = 128;
int columns = 20;
DriverYieldSignal yieldSignal = new DriverYieldSignal();
PageProcessor pageProcessor = new PageProcessor(Optional.empty(), IntStream.range(0, 20).mapToObj(i -> new PageProjectionWithOutputs(new YieldPageProjection(new InputPageProjection(0)), new int[] { i })).collect(toImmutableList()), OptionalInt.of(MAX_BATCH_SIZE));
Slice[] slices = new Slice[rows];
Arrays.fill(slices, Slices.allocate(rows));
Page inputPage = new Page(createSlicesBlock(slices));
Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, yieldSignal, inputPage);
// Also, we would like to reset the yield signal before starting to process the next column in order NOT to yield per position inside the column.
for (int i = 0; i < columns - 1; i++) {
assertTrue(output.hasNext());
assertNull(output.next().orElse(null));
assertTrue(yieldSignal.isSet());
yieldSignal.reset();
}
assertTrue(output.hasNext());
Page actualPage = output.next().orElse(null);
assertNotNull(actualPage);
assertTrue(yieldSignal.isSet());
yieldSignal.reset();
Block[] blocks = new Block[columns];
Arrays.fill(blocks, createSlicesBlock(Arrays.copyOfRange(slices, 0, rows)));
Page expectedPage = new Page(blocks);
assertPageEquals(Collections.nCopies(columns, VARCHAR), actualPage, expectedPage);
assertFalse(output.hasNext());
}
use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestPageProcessor method testFilterNoColumns.
@Test
public void testFilterNoColumns() {
PageProcessor pageProcessor = new PageProcessor(Optional.of(new TestingPageFilter(positionsRange(0, 50))), ImmutableList.of());
Page inputPage = new Page(createLongSequenceBlock(0, 100));
LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
Iterator<Optional<Page>> output = pageProcessor.process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), memoryContext, inputPage);
assertEquals(memoryContext.getBytes(), 0);
List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
assertEquals(outputPages.size(), 1);
Page outputPage = outputPages.get(0).orElse(null);
assertEquals(outputPage.getChannelCount(), 0);
assertEquals(outputPage.getPositionCount(), 50);
}
use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestPageProcessor method testRetainedSize.
@Test
public void testRetainedSize() {
PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(createInputPageProjectionWithOutputs(0, VARCHAR, 0), createInputPageProjectionWithOutputs(1, VARCHAR, 1)), OptionalInt.of(MAX_BATCH_SIZE));
// create 2 columns X 800 rows of strings with each string's size = 10KB
// this can force previouslyComputedResults to be saved given the page is 16MB in size
String value = join("", nCopies(10_000, "a"));
List<String> values = nCopies(800, value);
Page inputPage = new Page(createStringsBlock(values), createStringsBlock(values));
AggregatedMemoryContext memoryContext = newSimpleAggregatedMemoryContext();
Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, new DriverYieldSignal(), memoryContext, inputPage);
// force a compute
// one block of previouslyComputedResults will be saved given the first column is with 8MB
output.hasNext();
// verify we do not count block sizes twice
// comparing with the input page, the output page also contains an extra instance size for previouslyComputedResults
assertEquals(memoryContext.getBytes() - ClassLayout.parseClass(VariableWidthBlock.class).instanceSize(), inputPage.getRetainedSizeInBytes());
}
use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestPageProcessor method testSelectNoneFilterLazyLoad.
@Test
public void testSelectNoneFilterLazyLoad() {
PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(createInputPageProjectionWithOutputs(1, BIGINT, 0)));
// if channel 1 is loaded, test will fail
Page inputPage = new Page(createLongSequenceBlock(0, 100), new LazyBlock(100, lazyBlock -> {
throw new AssertionError("Lazy block should not be loaded");
}));
LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
Iterator<Optional<Page>> output = pageProcessor.process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), memoryContext, inputPage);
assertEquals(memoryContext.getBytes(), 0);
List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
assertEquals(outputPages.size(), 0);
}
Aggregations