use of io.crate.data.join.CombinedRow in project crate by crate.
the class HashInnerJoinBatchIteratorMemoryTest method testReleaseAccountingRows.
@Test
public void testReleaseAccountingRows() throws Exception {
BatchSimulatingIterator<Row> leftIterator = new BatchSimulatingIterator<>(TestingBatchIterators.range(0, 12), 3, 3, null);
BatchIterator<Row> rightIterator = new BatchSimulatingIterator<>(TestingBatchIterators.range(0, 10), 2, 4, null);
when(circuitBreaker.getLimit()).thenReturn(110L);
when(circuitBreaker.getUsed()).thenReturn(10L);
RowAccounting<Object[]> rowAccounting = mock(RowAccounting.class);
BatchIterator<Row> it = new HashInnerJoinBatchIterator(leftIterator, rightIterator, rowAccounting, new CombinedRow(1, 1), getCol0EqCol1JoinCondition(), getHashForLeft(), getHashForRight(), () -> 2);
TestingRowConsumer consumer = new TestingRowConsumer();
consumer.accept(it, null);
consumer.getResult();
verify(rowAccounting, times(8)).release();
verify(rowAccounting, times(12)).accountForAndMaybeBreak(Mockito.any(Object[].class));
}
use of io.crate.data.join.CombinedRow in project crate by crate.
the class HashInnerJoinBatchIteratorBehaviouralTest method test_SwitchToRightWhenLeftExhausted.
@Test
public void test_SwitchToRightWhenLeftExhausted() throws Exception {
BatchSimulatingIterator<Row> leftIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(1, 2, 3, 4)), 2, 1, null);
BatchSimulatingIterator<Row> rightIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(2, 0, 4, 5)), 2, 1, null);
BatchIterator<Row> batchIterator = new HashInnerJoinBatchIterator(leftIterator, rightIterator, mock(RowAccounting.class), new CombinedRow(1, 1), row -> Objects.equals(row.get(0), row.get(1)), row -> Objects.hash(row.get(0)), row -> Objects.hash(row.get(0)), () -> 500000);
TestingRowConsumer consumer = new TestingRowConsumer();
consumer.accept(batchIterator, null);
List<Object[]> result = consumer.getResult();
assertThat(result, contains(new Object[] { 2, 2 }, new Object[] { 4, 4 }));
}
use of io.crate.data.join.CombinedRow in project crate by crate.
the class HashInnerJoinBatchIteratorTest method testInnerHashJoin.
@Test
public void testInnerHashJoin() throws Exception {
Supplier<BatchIterator<Row>> batchIteratorSupplier = () -> new HashInnerJoinBatchIterator(leftIterator.get(), rightIterator.get(), mock(RowAccounting.class), new CombinedRow(1, 1), getCol0EqCol1JoinCondition(), getHashForLeft(), getHashForRight(), () -> 5);
BatchIteratorTester tester = new BatchIteratorTester(batchIteratorSupplier);
tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
use of io.crate.data.join.CombinedRow in project crate by crate.
the class HashInnerJoinBatchIteratorBehaviouralTest method testDistributed_SwitchToRightEvenIfLeftBatchDoesNotDeliverAllRowsExpectedByOneBatch.
@Test
public void testDistributed_SwitchToRightEvenIfLeftBatchDoesNotDeliverAllRowsExpectedByOneBatch() throws Exception {
BatchSimulatingIterator<Row> leftIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(1, 2, 4)), 1, 2, null);
BatchSimulatingIterator<Row> rightIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(2, 0, 4, 5)), 2, 1, null);
BatchIterator<Row> batchIterator = new HashInnerJoinBatchIterator(leftIterator, rightIterator, mock(RowAccounting.class), new CombinedRow(1, 1), row -> Objects.equals(row.get(0), row.get(1)), row -> Objects.hash(row.get(0)), row -> Objects.hash(row.get(0)), () -> 2);
TestingRowConsumer consumer = new TestingRowConsumer();
consumer.accept(batchIterator, null);
List<Object[]> result = consumer.getResult();
assertThat(result, contains(new Object[] { 2, 2 }, new Object[] { 4, 4 }));
// as the blocksize is defined of 2 but the left batch size 1, normally it would call left loadNextBatch until
// the blocksize is reached. we don't want that as parallel running hash iterators must call loadNextBatch always
// on the same side synchronously as the upstreams will only send new data after all downstreams responded.
// to validate this, the right must be repeated 3 times
assertThat(rightIterator.getMovetoStartCalls(), is(2));
}
use of io.crate.data.join.CombinedRow in project crate by crate.
the class HashInnerJoinBatchIteratorTest method testInnerHashJoinWithBlockSizeSmallerThanDataSet.
@Test
public void testInnerHashJoinWithBlockSizeSmallerThanDataSet() throws Exception {
Supplier<BatchIterator<Row>> batchIteratorSupplier = () -> new HashInnerJoinBatchIterator(leftIterator.get(), rightIterator.get(), mock(RowAccounting.class), new CombinedRow(1, 1), getCol0EqCol1JoinCondition(), getHashForLeft(), getHashForRight(), () -> 1);
BatchIteratorTester tester = new BatchIteratorTester(batchIteratorSupplier);
tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Aggregations