use of io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class TestPageProcessor method testAdaptiveBatchSize.
@Test
public void testAdaptiveBatchSize() {
PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(new InputPageProjection(0, VARCHAR)), 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 io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class TestDictionaryAwarePageProjection method testProjectFastReturnIgnoreYield.
private static void testProjectFastReturnIgnoreYield(Block block, DictionaryAwarePageProjection projection, boolean produceLazyBlock) {
if (produceLazyBlock) {
block = lazyWrapper(block);
}
DriverYieldSignal yieldSignal = new DriverYieldSignal();
Work<Block> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsRange(5, 10));
yieldSignal.setWithDelay(1, executor);
yieldSignal.forceYieldForTesting();
// yield signal is ignored given the block has already been loaded
assertTrue(work.process());
Block result = work.getResult();
yieldSignal.reset();
if (produceLazyBlock) {
assertInstanceOf(result, LazyBlock.class);
assertFalse(result.isLoaded());
assertFalse(block.isLoaded());
result = result.getLoadedBlock();
}
assertBlockEquals(BIGINT, result, block.getRegion(5, 10));
assertInstanceOf(result, DictionaryBlock.class);
}
use of io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class TestPageFunctionCompiler method testGeneratedClassName.
@Test
public void testGeneratedClassName() {
PageFunctionCompiler functionCompiler = FUNCTION_RESOLUTION.getPageFunctionCompiler();
String planNodeId = "7";
String stageId = "20170707_223500_67496_zguwn.2";
String classSuffix = stageId + "_" + planNodeId;
Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(ADD_10_EXPRESSION, Optional.of(classSuffix));
PageProjection projection = projectionSupplier.get();
Work<Block> work = projection.project(SESSION, new DriverYieldSignal(), createLongBlockPage(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));
}
use of io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class TestPageProcessorCompiler method testSanityColumnarDictionary.
@Test
public void testSanityColumnarDictionary() {
PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(field(0, VARCHAR)), 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 io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class TestPageProcessorCompiler method testNonDeterministicProject.
@Test
public void testNonDeterministicProject() {
ResolvedFunction lessThan = functionResolution.resolveOperator(LESS_THAN, ImmutableList.of(BIGINT, BIGINT));
CallExpression random = new CallExpression(functionResolution.resolveFunction(QualifiedName.of("random"), fromTypes(BIGINT)), singletonList(constant(10L, BIGINT)));
InputReferenceExpression col0 = field(0, BIGINT);
CallExpression lessThanRandomExpression = new CallExpression(lessThan, ImmutableList.of(col0, random));
PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(lessThanRandomExpression), MAX_BATCH_SIZE).get();
assertFalse(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);
}
Aggregations