Search in sources :

Example 31 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class GroupByStreamMergedResultTest method assertNextForMix.

@Test
public void assertNextForMix() throws SQLException {
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    when(resultSets.get(0).next()).thenReturn(true, false);
    when(resultSets.get(0).getObject(1)).thenReturn(20);
    when(resultSets.get(0).getObject(2)).thenReturn(0);
    when(resultSets.get(0).getObject(3)).thenReturn(2);
    when(resultSets.get(0).getObject(5)).thenReturn(2);
    when(resultSets.get(0).getObject(6)).thenReturn(20);
    when(resultSets.get(1).next()).thenReturn(true, true, true, false);
    when(resultSets.get(1).getObject(1)).thenReturn(20, 30, 30, 40);
    when(resultSets.get(1).getObject(2)).thenReturn(0);
    when(resultSets.get(1).getObject(3)).thenReturn(2, 2, 3, 3, 3, 4);
    when(resultSets.get(1).getObject(5)).thenReturn(2, 2, 3, 3, 3, 4);
    when(resultSets.get(1).getObject(6)).thenReturn(20, 20, 30, 30, 30, 40);
    when(resultSets.get(2).next()).thenReturn(true, true, false);
    when(resultSets.get(2).getObject(1)).thenReturn(10, 30);
    when(resultSets.get(2).getObject(2)).thenReturn(10);
    when(resultSets.get(2).getObject(3)).thenReturn(1, 1, 1, 1, 3);
    when(resultSets.get(2).getObject(5)).thenReturn(1, 1, 3);
    when(resultSets.get(2).getObject(6)).thenReturn(10, 10, 30);
    MergedResult actual = mergeEngine.merge();
    assertTrue(actual.next());
    assertThat((BigDecimal) actual.getValue(1, Object.class), is(new BigDecimal(10)));
    assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10));
    assertThat((Integer) actual.getValue(3, Object.class), is(1));
    assertThat((BigDecimal) actual.getValue(5, Object.class), is(new BigDecimal(1)));
    assertThat((BigDecimal) actual.getValue(6, Object.class), is(new BigDecimal(10)));
    assertTrue(actual.next());
    assertThat((BigDecimal) actual.getValue(1, Object.class), is(new BigDecimal(40)));
    assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10));
    assertThat((Integer) actual.getValue(3, Object.class), is(2));
    assertThat((BigDecimal) actual.getValue(5, Object.class), is(new BigDecimal(4)));
    assertThat((BigDecimal) actual.getValue(6, Object.class), is(new BigDecimal(40)));
    assertTrue(actual.next());
    assertThat((BigDecimal) actual.getValue(1, Object.class), is(new BigDecimal(60)));
    assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10));
    assertThat((Integer) actual.getValue(3, Object.class), is(3));
    assertThat((BigDecimal) actual.getValue(5, Object.class), is(new BigDecimal(6)));
    assertThat((BigDecimal) actual.getValue(6, Object.class), is(new BigDecimal(60)));
    assertTrue(actual.next());
    assertThat((BigDecimal) actual.getValue(1, Object.class), is(new BigDecimal(40)));
    assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10));
    assertThat((Integer) actual.getValue(3, Object.class), is(4));
    assertThat((BigDecimal) actual.getValue(5, Object.class), is(new BigDecimal(4)));
    assertThat((BigDecimal) actual.getValue(6, Object.class), is(new BigDecimal(40)));
    assertFalse(actual.next());
}
Also used : MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 32 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class GroupByStreamMergedResultTest method assertNextForResultSetsAllEmpty.

@Test
public void assertNextForResultSetsAllEmpty() throws SQLException {
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertFalse(actual.next());
}
Also used : MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Test(org.junit.Test)

Example 33 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class IteratorStreamMergedResultTest method assertNextForFirstResultSetsNotEmptyOnly.

@Test
public void assertNextForFirstResultSetsNotEmptyOnly() throws SQLException {
    when(queryResults.get(0).next()).thenReturn(true, false);
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertTrue(actual.next());
    assertFalse(actual.next());
}
Also used : MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Test(org.junit.Test)

Example 34 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class IteratorStreamMergedResultTest method assertNextForResultSetsAllNotEmpty.

@Test
public void assertNextForResultSetsAllNotEmpty() throws SQLException {
    for (QueryResult each : queryResults) {
        when(each.next()).thenReturn(true, false);
    }
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertTrue(actual.next());
    assertTrue(actual.next());
    assertTrue(actual.next());
    assertFalse(actual.next());
}
Also used : QueryResult(io.shardingjdbc.core.merger.QueryResult) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Test(org.junit.Test)

Example 35 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class IteratorStreamMergedResultTest method assertNextForMix.

@Test
public void assertNextForMix() throws SQLException {
    queryResults.add(new TestQueryResult(mock(ResultSet.class)));
    queryResults.add(new TestQueryResult(mock(ResultSet.class)));
    queryResults.add(new TestQueryResult(mock(ResultSet.class)));
    when(queryResults.get(1).next()).thenReturn(true, false);
    when(queryResults.get(3).next()).thenReturn(true, false);
    when(queryResults.get(5).next()).thenReturn(true, false);
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertTrue(actual.next());
    assertTrue(actual.next());
    assertTrue(actual.next());
    assertFalse(actual.next());
}
Also used : TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Test(org.junit.Test)

Aggregations

MergedResult (io.shardingjdbc.core.merger.MergedResult)42 Test (org.junit.Test)41 Limit (io.shardingjdbc.core.parsing.parser.context.limit.Limit)27 DQLMergeEngine (io.shardingjdbc.core.merger.dql.DQLMergeEngine)26 GroupByMemoryMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult)15 GroupByStreamMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByStreamMergedResult)15 IteratorStreamMergedResult (io.shardingjdbc.core.merger.dql.iterator.IteratorStreamMergedResult)15 OrderByStreamMergedResult (io.shardingjdbc.core.merger.dql.orderby.OrderByStreamMergedResult)15 LimitDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.LimitDecoratorMergedResult)15 RowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.RowNumberDecoratorMergedResult)15 TopAndRowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult)15 LimitValue (io.shardingjdbc.core.parsing.parser.context.limit.LimitValue)11 OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)9 AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)3 BigDecimal (java.math.BigDecimal)3 QueryResult (io.shardingjdbc.core.merger.QueryResult)2 TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)2 MySQLPacketQueryResult (io.shardingjdbc.proxy.backend.mysql.MySQLPacketQueryResult)1 DatabaseProtocolPacket (io.shardingjdbc.proxy.transport.common.packet.DatabaseProtocolPacket)1 ErrPacket (io.shardingjdbc.proxy.transport.mysql.packet.generic.ErrPacket)1