Search in sources :

Example 1 with DQLMergeEngine

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

the class GroupByStreamMergedResultTest method assertNextForSomeResultSetsEmpty.

@Test
public void assertNextForSomeResultSetsEmpty() 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(4)).thenReturn(new Date(0L));
    when(resultSets.get(0).getObject(5)).thenReturn(2);
    when(resultSets.get(0).getObject(6)).thenReturn(20);
    when(resultSets.get(2).next()).thenReturn(true, true, false);
    when(resultSets.get(2).getObject(1)).thenReturn(20, 30);
    when(resultSets.get(2).getObject(2)).thenReturn(0);
    when(resultSets.get(2).getObject(3)).thenReturn(2, 2, 3);
    when(resultSets.get(2).getObject(4)).thenReturn(new Date(0L));
    when(resultSets.get(2).getObject(5)).thenReturn(2, 2, 3);
    when(resultSets.get(2).getObject(6)).thenReturn(20, 20, 30);
    MergedResult actual = mergeEngine.merge();
    assertTrue(actual.next());
    assertThat((BigDecimal) actual.getValue(1, Object.class), is(new BigDecimal(40)));
    assertThat((BigDecimal) actual.getValue("COUNT(*)", Object.class), is(new BigDecimal(40)));
    assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10));
    assertThat(((BigDecimal) actual.getValue("avg(NUM)", Object.class)).intValue(), is(10));
    assertThat((Integer) actual.getValue(3, Object.class), is(2));
    assertThat((Integer) actual.getValue("ID", Object.class), is(2));
    assertThat((Date) actual.getCalendarValue(4, Date.class, Calendar.getInstance()), is(new Date(0L)));
    assertThat((Date) actual.getCalendarValue("date", Date.class, Calendar.getInstance()), is(new Date(0L)));
    assertThat((BigDecimal) actual.getValue(5, Object.class), is(new BigDecimal(4)));
    assertThat((BigDecimal) actual.getValue("AVG_DERIVED_COUNT_0", Object.class), is(new BigDecimal(4)));
    assertThat((BigDecimal) actual.getValue(6, Object.class), is(new BigDecimal(40)));
    assertThat((BigDecimal) actual.getValue("Avg_Derived_Sum_0", Object.class), is(new BigDecimal(40)));
    assertTrue(actual.next());
    assertThat((BigDecimal) actual.getValue(1, Object.class), is(new BigDecimal(30)));
    assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10));
    assertThat((Integer) actual.getValue(3, Object.class), is(3));
    assertThat((Date) actual.getCalendarValue(4, Date.class, Calendar.getInstance()), is(new Date(0L)));
    assertThat((Date) actual.getCalendarValue("date", Date.class, Calendar.getInstance()), is(new Date(0L)));
    assertThat((BigDecimal) actual.getValue(5, Object.class), is(new BigDecimal(3)));
    assertThat((BigDecimal) actual.getValue(6, Object.class), is(new BigDecimal(30)));
    assertFalse(actual.next());
}
Also used : MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with DQLMergeEngine

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

the class IteratorStreamMergedResultTest 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 3 with DQLMergeEngine

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

the class IteratorStreamMergedResultTest method assertNextForMiddleResultSetsNotEmpty.

@Test
public void assertNextForMiddleResultSetsNotEmpty() throws SQLException {
    when(queryResults.get(1).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 4 with DQLMergeEngine

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

the class OrderByStreamMergedResultTest 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 5 with DQLMergeEngine

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

the class OrderByStreamMergedResultTest method assertNextForMix.

@Test
public void assertNextForMix() throws SQLException {
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    when(queryResults.get(0).next()).thenReturn(true, false);
    when(queryResults.get(0).getValue(1, Object.class)).thenReturn("2");
    when(queryResults.get(1).next()).thenReturn(true, true, true, false);
    when(queryResults.get(1).getValue(1, Object.class)).thenReturn("2", "2", "3", "3", "4", "4");
    when(queryResults.get(2).next()).thenReturn(true, true, false);
    when(queryResults.get(2).getValue(1, Object.class)).thenReturn("1", "1", "3", "3");
    MergedResult actual = mergeEngine.merge();
    assertTrue(actual.next());
    assertThat(actual.getValue(1, Object.class).toString(), is("1"));
    assertTrue(actual.next());
    assertThat(actual.getValue(1, Object.class).toString(), is("2"));
    assertTrue(actual.next());
    assertThat(actual.getValue(1, Object.class).toString(), is("2"));
    assertTrue(actual.next());
    assertThat(actual.getValue(1, Object.class).toString(), is("3"));
    assertTrue(actual.next());
    assertThat(actual.getValue(1, Object.class).toString(), is("3"));
    assertTrue(actual.next());
    assertThat(actual.getValue(1, Object.class).toString(), is("4"));
    assertFalse(actual.next());
}
Also used : MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Test(org.junit.Test)

Aggregations

MergedResult (io.shardingjdbc.core.merger.MergedResult)26 DQLMergeEngine (io.shardingjdbc.core.merger.dql.DQLMergeEngine)26 Test (org.junit.Test)26 Limit (io.shardingjdbc.core.parsing.parser.context.limit.Limit)12 LimitValue (io.shardingjdbc.core.parsing.parser.context.limit.LimitValue)11 BigDecimal (java.math.BigDecimal)3 TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)2 QueryResult (io.shardingjdbc.core.merger.QueryResult)1 Date (java.util.Date)1