use of io.trino.operator.PagesIndex in project trino by trinodb.
the class MatchAssert method identityEvaluator.
private static LabelEvaluator identityEvaluator(int[] input) {
// create dummy WindowIndex for the LabelEvaluator
PagesIndex pagesIndex = new PagesIndex.TestingFactory(false).newPagesIndex(ImmutableList.of(), 1);
pagesIndex.addPage(new Page(1));
return new IdentityEvaluator(input, new ProjectingPagesWindowIndex(pagesIndex, 0, 1, ImmutableList.of(), ImmutableList.of()));
}
use of io.trino.operator.PagesIndex in project trino by trinodb.
the class BenchmarkPagesSort method runPagesIndexSortBenchmark.
@Benchmark
public List<Page> runPagesIndexSortBenchmark(PagesIndexSortBenchmarkData data) {
PagesIndex.TestingFactory pagesIndexFactory = new PagesIndex.TestingFactory(false);
PagesIndex pageIndex = pagesIndexFactory.newPagesIndex(data.getTypes(), data.getTotalPositions());
for (Page page : data.getPages()) {
pageIndex.addPage(page);
}
pageIndex.sort(data.getSortChannels(), data.getSortOrders());
return Streams.stream(pageIndex.getSortedPages()).collect(toImmutableList());
}
use of io.trino.operator.PagesIndex in project trino by trinodb.
the class AbstractTestAggregationFunction method testSlidingWindow.
@Test
public void testSlidingWindow() {
// Builds trailing windows of length 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0
int totalPositions = 12;
int[] windowWidths = new int[totalPositions];
Object[] expectedValues = new Object[totalPositions];
for (int i = 0; i < totalPositions; ++i) {
int windowWidth = Integer.min(i, totalPositions - 1 - i);
windowWidths[i] = windowWidth;
expectedValues[i] = getExpectedValue(i, windowWidth);
}
Page inputPage = new Page(totalPositions, getSequenceBlocks(0, totalPositions));
PagesIndex pagesIndex = new PagesIndex.TestingFactory(false).newPagesIndex(getFunctionParameterTypes(), totalPositions);
pagesIndex.addPage(inputPage);
WindowIndex windowIndex = new PagesWindowIndex(pagesIndex, 0, totalPositions - 1);
ResolvedFunction resolvedFunction = functionResolution.resolveFunction(QualifiedName.of(getFunctionName()), fromTypes(getFunctionParameterTypes()));
AggregationMetadata aggregationMetadata = functionResolution.getPlannerContext().getFunctionManager().getAggregateFunctionImplementation(resolvedFunction);
WindowAccumulator aggregation = createWindowAccumulator(resolvedFunction, aggregationMetadata);
int oldStart = 0;
int oldWidth = 0;
for (int start = 0; start < totalPositions; ++start) {
int width = windowWidths[start];
// Note that add/removeInput's interval is inclusive on both ends
if (aggregationMetadata.getRemoveInputFunction().isPresent()) {
for (int oldi = oldStart; oldi < oldStart + oldWidth; ++oldi) {
if (oldi < start || oldi >= start + width) {
aggregation.removeInput(windowIndex, oldi, oldi);
}
}
for (int newi = start; newi < start + width; ++newi) {
if (newi < oldStart || newi >= oldStart + oldWidth) {
aggregation.addInput(windowIndex, newi, newi);
}
}
} else {
aggregation = createWindowAccumulator(resolvedFunction, aggregationMetadata);
aggregation.addInput(windowIndex, start, start + width - 1);
}
oldStart = start;
oldWidth = width;
Type outputType = resolvedFunction.getSignature().getReturnType();
BlockBuilder blockBuilder = outputType.createBlockBuilder(null, 1000);
aggregation.evaluateFinal(blockBuilder);
Block block = blockBuilder.build();
assertThat(makeValidityAssertion(expectedValues[start]).apply(BlockAssertions.getOnlyValue(outputType, block), expectedValues[start])).isTrue();
}
}
Aggregations