use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestPageProcessorCompiler method testSanityColumnarDictionary.
@Test
public void testSanityColumnarDictionary() {
PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), ImmutableList.of(field(0, VARCHAR)), false, MAX_BATCH_SIZE).get();
Page page = new Page(createDictionaryBlock(createExpectedValues(10), 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 DictionaryBlock);
DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
}
use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestPageProcessor method testProjectLazyLoad.
@Test
public void testProjectLazyLoad() {
PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new PageProjectionWithOutputs(new LazyPagePageProjection(), new int[] { 0 })), OptionalInt.of(MAX_BATCH_SIZE));
// 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);
List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
assertEquals(outputPages.size(), 1);
assertPageEquals(ImmutableList.of(BIGINT), outputPages.get(0).orElse(null), new Page(createLongSequenceBlock(0, 100)));
}
use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestPageProcessor method testExpressionProfiler.
@Test
public void testExpressionProfiler() {
MetadataManager metadata = createTestMetadataManager();
CallExpression add10Expression = call(ADD.name(), metadata.getFunctionAndTypeManager().resolveOperator(ADD, fromTypes(BIGINT, BIGINT)), BIGINT, field(0, BIGINT), constant(10L, BIGINT));
TestingTicker testingTicker = new TestingTicker();
PageFunctionCompiler functionCompiler = new PageFunctionCompiler(metadata, 0);
Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(SESSION.getSqlFunctionProperties(), add10Expression, Optional.empty());
PageProjection projection = projectionSupplier.get();
Page page = new Page(createLongSequenceBlock(1, 11));
ExpressionProfiler profiler = new ExpressionProfiler(testingTicker, SPLIT_RUN_QUANTA);
for (int i = 0; i < 100; i++) {
profiler.start();
Work<List<Block>> work = projection.project(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), page, SelectedPositions.positionsRange(0, page.getPositionCount()));
if (i < 10) {
// increment the ticker with a large value to mark the expression as expensive
testingTicker.increment(10, SECONDS);
profiler.stop(page.getPositionCount());
assertTrue(profiler.isExpressionExpensive());
} else {
testingTicker.increment(0, NANOSECONDS);
profiler.stop(page.getPositionCount());
assertFalse(profiler.isExpressionExpensive());
}
work.process();
}
}
use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestPageProcessor method testAdaptiveBatchSize.
@Test
public void testAdaptiveBatchSize() {
PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(createInputPageProjectionWithOutputs(0, VARCHAR, 0)), OptionalInt.of(MAX_BATCH_SIZE));
// process large page which will reduce batch size
Slice[] slices = new Slice[(int) (MAX_BATCH_SIZE * 2.5)];
Arrays.fill(slices, Slices.allocate(1024));
Page inputPage = new Page(createSlicesBlock(slices));
Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, new DriverYieldSignal(), inputPage);
List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
int batchSize = MAX_BATCH_SIZE;
for (Optional<Page> actualPage : outputPages) {
Page expectedPage = new Page(createSlicesBlock(Arrays.copyOfRange(slices, 0, batchSize)));
assertPageEquals(ImmutableList.of(VARCHAR), actualPage.orElse(null), expectedPage);
if (actualPage.orElseThrow(() -> new AssertionError("page is not present")).getSizeInBytes() > MAX_PAGE_SIZE_IN_BYTES) {
batchSize = batchSize / 2;
}
}
// process small page which will increase batch size
Arrays.fill(slices, Slices.allocate(128));
inputPage = new Page(createSlicesBlock(slices));
output = processAndAssertRetainedPageSize(pageProcessor, new DriverYieldSignal(), inputPage);
outputPages = ImmutableList.copyOf(output);
int offset = 0;
for (Optional<Page> actualPage : outputPages) {
Page expectedPage = new Page(createSlicesBlock(Arrays.copyOfRange(slices, 0, Math.min(inputPage.getPositionCount() - offset, batchSize))));
assertPageEquals(ImmutableList.of(VARCHAR), actualPage.orElse(null), expectedPage);
offset += actualPage.orElseThrow(() -> new AssertionError("page is not present")).getPositionCount();
if (actualPage.orElseThrow(() -> new AssertionError("page is not present")).getSizeInBytes() < MIN_PAGE_SIZE_IN_BYTES) {
batchSize = batchSize * 2;
}
}
}
use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.
the class TestPageProcessor method testSelectNoneFilter.
@Test
public void testSelectNoneFilter() {
PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(createInputPageProjectionWithOutputs(0, BIGINT, 0)));
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(), 0);
}
Aggregations