Search in sources :

Example 11 with OrderByColumn

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;
}
Also used : MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext) OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn)

Example 12 with OrderByColumn

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)));
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) TreeMap(java.util.TreeMap) OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 13 with OrderByColumn

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());
}
Also used : MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext) GroupByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn) OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn) Test(org.junit.Test)

Example 14 with OrderByColumn

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());
}
Also used : MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext) GroupByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn) OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn) Test(org.junit.Test)

Example 15 with OrderByColumn

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"));
}
Also used : MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext) GroupByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn) OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn) Test(org.junit.Test)

Aggregations

OrderByColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn)16 GroupByColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn)10 MergeContext (com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext)9 Test (org.junit.Test)8 AggregationColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.AggregationColumn)3 ArrayList (java.util.ArrayList)3 MockResultSet (com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet)2 Limit (com.dangdang.ddframe.rdb.sharding.parser.result.merger.Limit)2 Value (com.dangdang.ddframe.rdb.sharding.parser.jaxb.Value)1 Condition (com.dangdang.ddframe.rdb.sharding.parser.result.router.Condition)1 Column (com.dangdang.ddframe.rdb.sharding.parser.result.router.Condition.Column)1 ConditionContext (com.dangdang.ddframe.rdb.sharding.parser.result.router.ConditionContext)1 Table (com.dangdang.ddframe.rdb.sharding.parser.result.router.Table)1 Function (com.google.common.base.Function)1 ResultSet (java.sql.ResultSet)1 Calendar (java.util.Calendar)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ReflectionEquals (org.mockito.internal.matchers.apachecommons.ReflectionEquals)1