Search in sources :

Example 6 with OrderByColumn

use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.

the class ResultSetMergeContextTest method createMergeContext.

private MergeContext createMergeContext() {
    MergeContext result = new MergeContext();
    result.getOrderByColumns().add(new OrderByColumn("order_col", OrderByColumn.OrderByType.ASC));
    result.getGroupByColumns().add(new GroupByColumn(Optional.<String>absent(), "group_col", Optional.<String>absent(), OrderByColumn.OrderByType.ASC));
    result.getAggregationColumns().add(MergerTestUtil.createAggregationColumn(AggregationColumn.AggregationType.COUNT, "count_col", "count_col", -1));
    result.getAggregationColumns().add(MergerTestUtil.createAggregationColumn(AggregationColumn.AggregationType.AVG, "avg_col", "avg_col", -1));
    return result;
}
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)

Example 7 with OrderByColumn

use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.

the class ResultSetMergeContextTest method assertSetOrderByKeysToCurrentOrderByKeys.

@Test
public void assertSetOrderByKeysToCurrentOrderByKeys() 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();
    actual.setOrderByKeysToCurrentOrderByKeys();
    assertThat(actual.getCurrentOrderByKeys().size(), is(1));
    assertThat(actual.getCurrentOrderByKeys().get(0).getColumnName().get(), is("order_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)

Example 8 with OrderByColumn

use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.

the class MemoryOrderByResultSetTest method assertSort.

@Test
public void assertSort() throws SQLException {
    AbstractMemoryOrderByResultSet rs = new AbstractMemoryOrderByResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1, 3, 5, 6, 6), new MockResultSet<>(8, 6, 4, 2)), Collections.singletonList(new OrderByColumn(1, OrderByColumn.OrderByType.ASC))) {
    };
    List<Integer> actualList = new ArrayList<>();
    while (rs.next()) {
        actualList.add(rs.getInt(1));
    }
    assertThat(actualList, is(Arrays.asList(1, 2, 3, 4, 5, 6, 6, 6, 8)));
    rs.close();
    assertThat(rs.isClosed(), is(true));
    rs = new AbstractMemoryOrderByResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1, 3, 5, 6, 6), new MockResultSet<>(8, 6, 4, 2)), Collections.singletonList(new OrderByColumn(1, OrderByColumn.OrderByType.DESC))) {
    };
    actualList.clear();
    while (rs.next()) {
        actualList.add(rs.getInt("nAmE"));
    }
    assertThat(actualList, is(Arrays.asList(8, 6, 6, 6, 5, 4, 3, 2, 1)));
}
Also used : ArrayList(java.util.ArrayList) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) ResultSet(java.sql.ResultSet) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn) Test(org.junit.Test)

Example 9 with OrderByColumn

use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.

the class OrderByResultSetRow method loadOrderByValues.

private List<Comparable<?>> loadOrderByValues() {
    List<Comparable<?>> result = new ArrayList<>(orderByColumns.size());
    for (OrderByColumn each : orderByColumns) {
        Object value = getCell(each.getColumnIndex());
        Preconditions.checkState(value instanceof Comparable, "Sharding-JDBC: order by value must extends Comparable");
        result.add((Comparable<?>) value);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn)

Example 10 with OrderByColumn

use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn in project sharding-jdbc by dangdangdotcom.

the class OrderByResultSetRow method compareTo.

@Override
public int compareTo(final OrderByResultSetRow otherOrderByValue) {
    for (int i = 0; i < orderByColumns.size(); i++) {
        OrderByColumn thisOrderByColumn = orderByColumns.get(i);
        int result = ResultSetUtil.compareTo(orderByValues.get(i), otherOrderByValue.orderByValues.get(i), thisOrderByColumn.getOrderByType());
        if (0 != result) {
            return result;
        }
    }
    return 0;
}
Also used : OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn)

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