use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestHashAggregationOperator method testHashBuilderResize.
@Test(dataProvider = "hashEnabledAndMemoryLimitBeforeSpillValues")
public void testHashBuilderResize(boolean hashEnabled, long memoryLimitBeforeSpill, long memoryLimitForMergeWithMemory) {
BlockBuilder builder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 1, DEFAULT_MAX_BLOCK_SIZE_IN_BYTES);
// this must be larger than DEFAULT_MAX_BLOCK_SIZE, 64K
VARCHAR.writeSlice(builder, Slices.allocate(200_000));
builder.build();
List<Integer> hashChannels = Ints.asList(0);
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, VARCHAR);
List<Page> input = rowPagesBuilder.addSequencePage(10, 100).addBlocksPage(builder.build()).addSequencePage(10, 100).build();
DriverContext driverContext = createTaskContext(executor, TEST_SESSION, new DataSize(10, MEGABYTE)).addPipelineContext(0, true, true).addDriverContext();
HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(VARCHAR), hashChannels, ImmutableList.of(), Step.SINGLE, ImmutableList.of(COUNT.bind(ImmutableList.of(0), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, new DataSize(16, MEGABYTE), memoryLimitBeforeSpill > 0, succinctBytes(memoryLimitBeforeSpill), succinctBytes(memoryLimitForMergeWithMemory), spillerFactory, joinCompiler);
toPages(operatorFactory, driverContext, input);
}
use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestHashAggregationOperator method testHashAggregation.
@Test(dataProvider = "hashEnabledAndMemoryLimitBeforeSpillValues")
public void testHashAggregation(boolean hashEnabled, long memoryLimitBeforeSpill, long memoryLimitForMergeWithMemory) throws Exception {
MetadataManager metadata = MetadataManager.createTestMetadataManager();
InternalAggregationFunction countVarcharColumn = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("count", AGGREGATE, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.VARCHAR)));
InternalAggregationFunction countBooleanColumn = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("count", AGGREGATE, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BOOLEAN)));
InternalAggregationFunction maxVarcharColumn = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("max", AGGREGATE, parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.VARCHAR)));
List<Integer> hashChannels = Ints.asList(1);
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, VARCHAR, VARCHAR, VARCHAR, BIGINT, BOOLEAN);
List<Page> input = rowPagesBuilder.addSequencePage(10, 100, 0, 100, 0, 500).addSequencePage(10, 100, 0, 200, 0, 500).addSequencePage(10, 100, 0, 300, 0, 500).build();
HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(VARCHAR), hashChannels, ImmutableList.of(), Step.SINGLE, ImmutableList.of(COUNT.bind(ImmutableList.of(0), Optional.empty()), LONG_SUM.bind(ImmutableList.of(3), Optional.empty()), LONG_AVERAGE.bind(ImmutableList.of(3), Optional.empty()), maxVarcharColumn.bind(ImmutableList.of(2), Optional.empty()), countVarcharColumn.bind(ImmutableList.of(0), Optional.empty()), countBooleanColumn.bind(ImmutableList.of(4), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, new DataSize(16, MEGABYTE), memoryLimitBeforeSpill > 0, succinctBytes(memoryLimitBeforeSpill), succinctBytes(memoryLimitForMergeWithMemory), spillerFactory, joinCompiler);
MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, BIGINT, BIGINT, DOUBLE, VARCHAR, BIGINT, BIGINT).row("0", 3L, 0L, 0.0, "300", 3L, 3L).row("1", 3L, 3L, 1.0, "301", 3L, 3L).row("2", 3L, 6L, 2.0, "302", 3L, 3L).row("3", 3L, 9L, 3.0, "303", 3L, 3L).row("4", 3L, 12L, 4.0, "304", 3L, 3L).row("5", 3L, 15L, 5.0, "305", 3L, 3L).row("6", 3L, 18L, 6.0, "306", 3L, 3L).row("7", 3L, 21L, 7.0, "307", 3L, 3L).row("8", 3L, 24L, 8.0, "308", 3L, 3L).row("9", 3L, 27L, 9.0, "309", 3L, 3L).build();
assertOperatorEqualsIgnoreOrder(operatorFactory, driverContext, input, expected, hashEnabled, Optional.of(hashChannels.size()));
}
use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestMarkDistinctOperator method testMarkDistinct.
@Test(dataProvider = "hashEnabledValues")
public void testMarkDistinct(boolean hashEnabled) throws Exception {
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), BIGINT);
List<Page> input = rowPagesBuilder.addSequencePage(100, 0).addSequencePage(100, 0).build();
OperatorFactory operatorFactory = new MarkDistinctOperatorFactory(0, new PlanNodeId("test"), rowPagesBuilder.getTypes(), ImmutableList.of(0), rowPagesBuilder.getHashChannel(), joinCompiler);
MaterializedResult.Builder expected = resultBuilder(driverContext.getSession(), BIGINT, BOOLEAN);
for (long i = 0; i < 100; i++) {
expected.row(i, true);
expected.row(i, false);
}
OperatorAssertion.assertOperatorEqualsIgnoreOrder(operatorFactory, driverContext, input, expected.build(), hashEnabled, Optional.of(1));
}
use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestMergeHashSort method testPageRewriteIterator.
@Test
public void testPageRewriteIterator() {
ImmutableList<Type> types = ImmutableList.of(BIGINT, BIGINT);
RowPagesBuilder pagesBuilder = rowPagesBuilder(types);
pagesBuilder.row(0, 42);
pagesBuilder.row(0, 43);
pagesBuilder.pageBreak();
pagesBuilder.row(0, 44);
pagesBuilder.row(1, 45);
pagesBuilder.pageBreak();
pagesBuilder.row(2, 46);
Iterator<Page> rewriterIterator = new MergeHashSort.PageRewriteIterator(new InterpretedHashGenerator(ImmutableList.of(BIGINT), new int[] { 0 }), types, new MergeHashSort.SingleChannelPagePositions(pagesBuilder.build().iterator()));
List<Page> pages = Lists.newArrayList(rewriterIterator);
assertEquals(pages.size(), 1);
List<Page> expectedPages = rowPagesBuilder(types).row(0, 42).row(0, 43).row(0, 44).row(1, 45).row(2, 46).build();
assertPageEquals(types, pages.get(0), expectedPages.get(0));
}
use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestMergeHashSort method testChannelIterator.
@Test
public void testChannelIterator() {
RowPagesBuilder pageBuilder = rowPagesBuilder(BIGINT);
pageBuilder.addSequencePage(2, 2);
pageBuilder.addSequencePage(2, 10);
MergeHashSort.PagePositions iterator = new MergeHashSort.SingleChannelPagePositions(pageBuilder.build().iterator());
assertTrue(iterator.hasNext());
assertEquals(iterator.next().getPosition(), 0);
assertTrue(iterator.hasNext());
assertEquals(iterator.next().getPosition(), 1);
assertTrue(iterator.hasNext());
assertEquals(iterator.next().getPosition(), 0);
assertTrue(iterator.hasNext());
assertEquals(iterator.next().getPosition(), 1);
assertFalse(iterator.hasNext());
}
Aggregations