Search in sources :

Example 6 with AggregationOperatorFactory

use of com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory in project presto by prestodb.

the class TestAggregationOperator method testDistinctMaskWithNull.

@Test
public void testDistinctMaskWithNull() {
    AccumulatorFactory distinctFactory = COUNT.bind(ImmutableList.of(0), Optional.of(1), ImmutableList.of(BIGINT, BOOLEAN), ImmutableList.of(), ImmutableList.of(), null, // distinct
    true, new JoinCompiler(MetadataManager.createTestMetadataManager(), new FeaturesConfig()), ImmutableList.of(), false, TEST_SESSION, new TempStorageStandaloneSpillerFactory(new TestingTempStorageManager(), new BlockEncodingManager(), new NodeSpillConfig(), new FeaturesConfig(), new SpillerStats()));
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(distinctFactory), false);
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    ByteArrayBlock trueMaskAllNull = new ByteArrayBlock(4, Optional.of(new boolean[] { true, true, true, true }), /* all positions are null */
    new byte[] { 1, 1, 1, 1 });
    /* non-zero value is true, all masks are true */
    Block trueNullRleMask = new RunLengthEncodedBlock(trueMaskAllNull.getSingleValueBlock(0), 4);
    List<Page> input = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), trueMaskAllNull), new Page(4, createLongsBlock(5, 6, 7, 8), trueNullRleMask));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(// all rows should be filtered by nulls
    0L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) TempStorageStandaloneSpillerFactory(com.facebook.presto.spiller.TempStorageStandaloneSpillerFactory) NodeSpillConfig(com.facebook.presto.spiller.NodeSpillConfig) Page(com.facebook.presto.common.Page) SpillerStats(com.facebook.presto.spiller.SpillerStats) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) TestingTempStorageManager(com.facebook.presto.testing.TestingTempStorageManager) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) AccumulatorFactory(com.facebook.presto.operator.aggregation.AccumulatorFactory) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) Block(com.facebook.presto.common.block.Block) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 7 with AggregationOperatorFactory

use of com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory in project presto by prestodb.

the class TestTableWriterOperator method testStatisticsAggregation.

@Test
public void testStatisticsAggregation() throws Exception {
    PageSinkManager pageSinkManager = new PageSinkManager();
    pageSinkManager.addConnectorPageSinkProvider(CONNECTOR_ID, new ConstantPageSinkProvider(new TableWriteInfoTestPageSink()));
    ImmutableList<Type> outputTypes = ImmutableList.of(BIGINT, VARBINARY, VARBINARY, BIGINT);
    Session session = testSessionBuilder().setSystemProperty("statistics_cpu_timer_enabled", "true").build();
    TaskContext taskContext = createTaskContext(executor, scheduledExecutor, session);
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    TaskMetadataContext taskMetadataContext = taskContext.getTaskMetadataContext();
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    InternalAggregationFunction longMaxFunction = functionAndTypeManager.getAggregateFunctionImplementation(functionAndTypeManager.lookupFunction("max", fromTypes(BIGINT)));
    TableWriterOperator operator = (TableWriterOperator) createTableWriterOperator(pageSinkManager, new AggregationOperatorFactory(1, new PlanNodeId("test"), AggregationNode.Step.SINGLE, ImmutableList.of(longMaxFunction.bind(ImmutableList.of(0), Optional.empty())), true), outputTypes, session, taskMetadataContext, driverContext);
    operator.addInput(rowPagesBuilder(BIGINT).row(42).build().get(0));
    operator.addInput(rowPagesBuilder(BIGINT).row(43).build().get(0));
    assertTrue(operator.isBlocked().isDone());
    assertTrue(operator.needsInput());
    assertThat(driverContext.getSystemMemoryUsage()).isGreaterThan(0);
    assertEquals(driverContext.getMemoryUsage(), 0);
    operator.finish();
    assertFalse(operator.isFinished());
    assertPageEquals(outputTypes, operator.getOutput(), rowPagesBuilder(outputTypes).row(null, null, getTableCommitContext(false), 43).build().get(0));
    BlockBuilder rowsBuilder = BIGINT.createBlockBuilder(null, 1);
    BlockBuilder fragmentsBuilder = VARBINARY.createBlockBuilder(null, 1);
    rowsBuilder.writeLong(1);
    fragmentsBuilder.appendNull();
    assertPageEquals(outputTypes, operator.getOutput(), rowPagesBuilder(outputTypes).row(2, null, getTableCommitContext(true), null).build().get(0));
    assertTrue(operator.isBlocked().isDone());
    assertFalse(operator.needsInput());
    assertTrue(operator.isFinished());
    operator.close();
    assertMemoryIsReleased(operator);
    TableWriterInfo info = operator.getInfo();
    assertThat(info.getStatisticsWallTime().getValue(NANOSECONDS)).isGreaterThan(0);
    assertThat(info.getStatisticsCpuTime().getValue(NANOSECONDS)).isGreaterThan(0);
}
Also used : TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) TaskMetadataContext(com.facebook.presto.execution.TaskMetadataContext) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) TableWriterInfo(com.facebook.presto.operator.TableWriterOperator.TableWriterInfo) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) PageSinkManager(com.facebook.presto.split.PageSinkManager) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Session(com.facebook.presto.Session) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

AggregationOperatorFactory (com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory)7 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)7 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)4 Page (com.facebook.presto.common.Page)3 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)3 OperatorFactory (com.facebook.presto.operator.OperatorFactory)3 Test (org.testng.annotations.Test)3 MaterializedResult (com.facebook.presto.testing.MaterializedResult)2 Session (com.facebook.presto.Session)1 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)1 Block (com.facebook.presto.common.block.Block)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)1 ByteArrayBlock (com.facebook.presto.common.block.ByteArrayBlock)1 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)1 Type (com.facebook.presto.common.type.Type)1 TaskMetadataContext (com.facebook.presto.execution.TaskMetadataContext)1 FilterAndProjectOperator (com.facebook.presto.operator.FilterAndProjectOperator)1 TableWriterInfo (com.facebook.presto.operator.TableWriterOperator.TableWriterInfo)1 AccumulatorFactory (com.facebook.presto.operator.aggregation.AccumulatorFactory)1