use of io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow in project sharding-jdbc by shardingjdbc.
the class GroupByRowComparatorTest method assertCompareToForDecsWithOrderByItems.
@Test
public void assertCompareToForDecsWithOrderByItems() throws SQLException {
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
SelectStatement selectStatement = new SelectStatement();
selectStatement.getOrderByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
selectStatement.getGroupByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(2, OrderDirection.ASC, OrderDirection.ASC)));
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatement);
assertTrue(groupByRowComparator.compare(o1, o2) > 0);
}
use of io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow in project sharding-jdbc by shardingjdbc.
the class ShowTablesMergedResult method init.
private Iterator<MemoryQueryResultRow> init(final List<QueryResult> queryResults) throws SQLException {
List<MemoryQueryResultRow> result = new LinkedList<>();
for (QueryResult each : queryResults) {
while (each.next()) {
MemoryQueryResultRow memoryResultSetRow = new MemoryQueryResultRow(each);
String actualTableName = memoryResultSetRow.getCell(1).toString();
Optional<TableRule> tableRule = shardingRule.tryFindTableRuleByActualTable(actualTableName);
if (!tableRule.isPresent()) {
result.add(memoryResultSetRow);
} else if (tableNames.add(tableRule.get().getLogicTable())) {
memoryResultSetRow.setCell(1, tableRule.get().getLogicTable());
result.add(memoryResultSetRow);
}
}
}
if (!result.isEmpty()) {
setCurrentResultSetRow(result.get(0));
}
return result.iterator();
}
use of io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow in project sharding-jdbc by shardingjdbc.
the class GroupByMemoryMergedResult method initForFirstGroupByValue.
private void initForFirstGroupByValue(final QueryResult queryResult, final GroupByValue groupByValue, final Map<GroupByValue, MemoryQueryResultRow> dataMap, final Map<GroupByValue, Map<AggregationSelectItem, AggregationUnit>> aggregationMap) throws SQLException {
if (!dataMap.containsKey(groupByValue)) {
dataMap.put(groupByValue, new MemoryQueryResultRow(queryResult));
}
if (!aggregationMap.containsKey(groupByValue)) {
Map<AggregationSelectItem, AggregationUnit> map = Maps.toMap(selectStatement.getAggregationSelectItems(), new Function<AggregationSelectItem, AggregationUnit>() {
@Override
public AggregationUnit apply(final AggregationSelectItem input) {
return AggregationUnitFactory.create(input.getType());
}
});
aggregationMap.put(groupByValue, map);
}
}
use of io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow in project sharding-jdbc by shardingjdbc.
the class GroupByRowComparatorTest method assertCompareToForAscWithOrderByItems.
@Test
public void assertCompareToForAscWithOrderByItems() throws SQLException {
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
SelectStatement selectStatement = new SelectStatement();
selectStatement.getOrderByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(2, OrderDirection.ASC, OrderDirection.ASC)));
selectStatement.getGroupByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatement);
assertTrue(groupByRowComparator.compare(o1, o2) < 0);
}
use of io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow in project sharding-jdbc by shardingjdbc.
the class GroupByRowComparatorTest method assertCompareToForDecsWithGroupByItems.
@Test
public void assertCompareToForDecsWithGroupByItems() throws SQLException {
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
SelectStatement selectStatement = new SelectStatement();
selectStatement.getGroupByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatement);
assertTrue(groupByRowComparator.compare(o1, o2) > 0);
}
Aggregations