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;
}
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"));
}
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)));
}
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;
}
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;
}
Aggregations