Search in sources :

Example 1 with CombinedRow

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));
}
Also used : BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) Row(io.crate.data.Row) CombinedRow(io.crate.data.join.CombinedRow) CombinedRow(io.crate.data.join.CombinedRow) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 2 with CombinedRow

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 }));
}
Also used : RowAccounting(io.crate.breaker.RowAccounting) BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) Row(io.crate.data.Row) CombinedRow(io.crate.data.join.CombinedRow) CombinedRow(io.crate.data.join.CombinedRow) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 3 with CombinedRow

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);
}
Also used : RowAccounting(io.crate.breaker.RowAccounting) BatchIteratorTester(io.crate.testing.BatchIteratorTester) BatchIterator(io.crate.data.BatchIterator) CombinedRow(io.crate.data.join.CombinedRow) Test(org.junit.Test)

Example 4 with CombinedRow

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));
}
Also used : RowAccounting(io.crate.breaker.RowAccounting) BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) Row(io.crate.data.Row) CombinedRow(io.crate.data.join.CombinedRow) CombinedRow(io.crate.data.join.CombinedRow) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 5 with CombinedRow

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);
}
Also used : RowAccounting(io.crate.breaker.RowAccounting) BatchIteratorTester(io.crate.testing.BatchIteratorTester) BatchIterator(io.crate.data.BatchIterator) CombinedRow(io.crate.data.join.CombinedRow) Test(org.junit.Test)

Aggregations

CombinedRow (io.crate.data.join.CombinedRow)7 Test (org.junit.Test)7 RowAccounting (io.crate.breaker.RowAccounting)6 BatchIterator (io.crate.data.BatchIterator)4 BatchIteratorTester (io.crate.testing.BatchIteratorTester)4 Row (io.crate.data.Row)3 BatchSimulatingIterator (io.crate.testing.BatchSimulatingIterator)3 TestingRowConsumer (io.crate.testing.TestingRowConsumer)3