use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.
the class OrderByResultSetTest method createMergeContext.
private MergeContext createMergeContext(final OrderByType orderType) {
MergeContext result = new MergeContext();
result.getOrderByColumns().add(new OrderByColumn("name", orderType));
return result;
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.
the class MemoryOrderByResultSetTest method assertSortMultiColumn.
@Test
public void assertSortMultiColumn() throws SQLException {
Map<String, Object> rs1 = new LinkedHashMap<>();
Calendar cal = Calendar.getInstance();
cal.set(2016, Calendar.JANUARY, 11);
rs1.put("name", "name");
rs1.put("time", cal.getTime());
rs1.put("id", 11);
Map<String, Object> rs2 = new LinkedHashMap<>();
cal.set(2016, Calendar.JANUARY, 9);
rs2.put("name", "dbc");
rs2.put("time", cal.getTime());
rs2.put("id", 12);
Map<String, Object> rs3 = new LinkedHashMap<>();
cal.set(2016, Calendar.JANUARY, 8);
rs3.put("name", "dbc");
rs3.put("time", cal.getTime());
rs3.put("id", 13);
OrderByColumn orderByColumn1 = new OrderByColumn("name", OrderByColumn.OrderByType.ASC);
orderByColumn1.setColumnIndex(1);
OrderByColumn orderByColumn2 = new OrderByColumn("time", OrderByColumn.OrderByType.DESC);
orderByColumn2.setColumnIndex(2);
AbstractMemoryOrderByResultSet rs = new AbstractMemoryOrderByResultSet(Collections.<ResultSet>singletonList(new MockResultSet<>(Arrays.asList(rs1, rs2, rs3))), Arrays.asList(orderByColumn1, orderByColumn2)) {
};
List<Map<String, Object>> actualList = new ArrayList<>();
while (rs.next()) {
Map<String, Object> map = new TreeMap<>();
map.put("name", rs.getObject("name"));
map.put("time", rs.getObject("time"));
map.put("id", rs.getObject("id"));
actualList.add(map);
}
assertThat(actualList, is(Arrays.asList(rs2, rs3, rs1)));
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.
the class ResultSetMergeContextTest method assertIsNeedMemorySortForOrderByWithGroupByAndOrderBySame.
@Test
public void assertIsNeedMemorySortForOrderByWithGroupByAndOrderBySame() throws SQLException {
MergeContext mergeContext = new MergeContext();
mergeContext.getOrderByColumns().add(new OrderByColumn("col", OrderByColumn.OrderByType.ASC));
mergeContext.getGroupByColumns().add(new GroupByColumn(Optional.<String>absent(), "col", Optional.<String>absent(), OrderByColumn.OrderByType.ASC));
ResultSetMergeContext actual = new ResultSetMergeContext(new ShardingResultSets(Collections.singletonList(MergerTestUtil.mockResult(Collections.singletonList("col")))), mergeContext);
assertFalse(actual.isNeedMemorySortForOrderBy());
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.
the class ResultSetMergeContextTest method assertIsNeedMemorySortForOrderByWithGroupByAndOrderByDifferent.
@Test
public void assertIsNeedMemorySortForOrderByWithGroupByAndOrderByDifferent() throws SQLException {
MergeContext mergeContext = new MergeContext();
mergeContext.getOrderByColumns().add(new OrderByColumn("order_col", OrderByColumn.OrderByType.ASC));
mergeContext.getGroupByColumns().add(new GroupByColumn(Optional.<String>absent(), "group_col", Optional.<String>absent(), OrderByColumn.OrderByType.ASC));
ResultSetMergeContext actual = new ResultSetMergeContext(new ShardingResultSets(Collections.singletonList(MergerTestUtil.mockResult(Arrays.asList("order_col", "group_col")))), mergeContext);
actual.setGroupByKeysToCurrentOrderByKeys();
assertTrue(actual.isNeedMemorySortForOrderBy());
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.
the class ResultSetMergeContextTest method assertSetGroupByKeysToCurrentOrderByKeys.
@Test
public void assertSetGroupByKeysToCurrentOrderByKeys() throws SQLException {
MergeContext mergeContext = new MergeContext();
mergeContext.getOrderByColumns().add(new OrderByColumn("order_col", OrderByColumn.OrderByType.ASC));
mergeContext.getGroupByColumns().add(new GroupByColumn(Optional.<String>absent(), "group_col", Optional.<String>absent(), OrderByColumn.OrderByType.ASC));
ResultSetMergeContext actual = new ResultSetMergeContext(new ShardingResultSets(Collections.singletonList(MergerTestUtil.mockResult(Arrays.asList("order_col", "group_col")))), mergeContext);
actual.setGroupByKeysToCurrentOrderByKeys();
assertThat(actual.getCurrentOrderByKeys().size(), is(1));
assertThat(actual.getCurrentOrderByKeys().get(0).getColumnName().get(), is("group_col"));
}
Aggregations