use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithSQLServerLimit.
@Test
public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithSQLServerLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
selectStatement.getItems().add(new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent()));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class));
}
use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildGroupByStreamMergedResultWithSQLServerLimit.
@Test
public void assertBuildGroupByStreamMergedResultWithSQLServerLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
selectStatement.getGroupByItems().add(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC));
selectStatement.getOrderByItems().add(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class));
}
use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithMySQLLimit.
@Test
public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithMySQLLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.MySQL));
selectStatement.getItems().add(new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent()));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class));
}
use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLimit.
@Test
public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.Oracle));
selectStatement.getItems().add(new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent()));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class));
}
use of io.shardingjdbc.core.merger.MergedResult 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());
}
Aggregations