Search in sources :

Example 6 with MemoryQueryResultRow

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);
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) MemoryQueryResultRow(io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 7 with MemoryQueryResultRow

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();
}
Also used : TableRule(io.shardingjdbc.core.rule.TableRule) QueryResult(io.shardingjdbc.core.merger.QueryResult) MemoryQueryResultRow(io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow) LinkedList(java.util.LinkedList)

Example 8 with MemoryQueryResultRow

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);
    }
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) MemoryQueryResultRow(io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow) AggregationUnit(io.shardingjdbc.core.merger.dql.groupby.aggregation.AggregationUnit)

Example 9 with MemoryQueryResultRow

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);
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) MemoryQueryResultRow(io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 10 with MemoryQueryResultRow

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);
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) MemoryQueryResultRow(io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Aggregations

MemoryQueryResultRow (io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow)10 OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)6 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)6 Test (org.junit.Test)6 QueryResult (io.shardingjdbc.core.merger.QueryResult)3 TableRule (io.shardingjdbc.core.rule.TableRule)2 LinkedList (java.util.LinkedList)2 AggregationUnit (io.shardingjdbc.core.merger.dql.groupby.aggregation.AggregationUnit)1 SQLParsingEngine (io.shardingjdbc.core.parsing.SQLParsingEngine)1 AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1