@Test public void testExceedMemoryLimit() throws Exception { List<Page> input = rowPagesBuilder(BIGINT) .row(1L) .build(); DriverContext smallDiverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION, new DataSize(1, BYTE)) .addPipelineContext(0, true, true, false) .addDriverContext(); TopNOperatorFactory operatorFactory = new TopNOperatorFactory( 0, new PlanNodeId("test"), ImmutableList.of(BIGINT), 100, ImmutableList.of(0), ImmutableList.of(ASC_NULLS_LAST)); try (Operator operator = operatorFactory.createOperator(smallDiverContext)) { operator.addInput(input.get(0)); fail("must fail because of exceeding local memory limit"); } catch (ExceededMemoryLimitException ignore) { } } }
@Test public void testLimitZero() throws Exception { List<Page> input = rowPagesBuilder(BIGINT).row(1L).build(); TopNOperatorFactory factory = new TopNOperatorFactory( 0, new PlanNodeId("test"), ImmutableList.of(BIGINT), 0, ImmutableList.of(0), ImmutableList.of(DESC_NULLS_LAST)); try (Operator operator = factory.createOperator(driverContext)) { assertEquals(operator.isFinished(), true); assertEquals(operator.needsInput(), false); assertEquals(operator.getOutput(), null); } }
@Test public void testLimitZero() throws Exception { List<Page> input = rowPagesBuilder(BIGINT).row(1).build(); TopNOperatorFactory factory = new TopNOperatorFactory( 0, new PlanNodeId("test"), ImmutableList.of(BIGINT), 0, ImmutableList.of(0), ImmutableList.of(DESC_NULLS_LAST), false); Operator operator = factory.createOperator(driverContext); MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).build(); // assertOperatorEquals assumes operators do not start in finished state assertEquals(operator.isFinished(), true); assertEquals(operator.needsInput(), false); assertEquals(operator.getOutput(), null); List<Page> pages = OperatorAssertion.toPages(operator, input.iterator()); MaterializedResult actual = OperatorAssertion.toMaterializedResult(operator.getOperatorContext().getSession(), operator.getTypes(), pages); assertEquals(actual, expected); }
false); Operator operator = operatorFactory.createOperator(driverContext);
false); Operator operator = factory.createOperator(driverContext);
false); Operator operator = operatorFactory.createOperator(driverContext);
true); Operator operator = factory.createOperator(smallDiverContext);