Search in sources :

Example 11 with GroupByColumn

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

the class ResultSetMergeContextTest method assertIsNeedMemorySortForGroupByWithGroupByAndOrderByDifferent.

@Test
public void assertIsNeedMemorySortForGroupByWithGroupByAndOrderByDifferent() 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);
    assertTrue(actual.isNeedMemorySortForGroupBy());
}
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 12 with GroupByColumn

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

the class GroupByResultSetRowTest method assertToString.

@Test
public void assertToString() throws Exception {
    ResultSet rs = MergerTestUtil.mockResult(Arrays.asList("user_id", "number"), Arrays.<ResultSetRow>asList(new TestResultSetRow(1, 10), new TestResultSetRow(1, 20)));
    assertTrue(rs.next());
    GroupByColumn groupByColumn = new GroupByColumn(Optional.<String>absent(), "user_id", Optional.<String>absent(), OrderByColumn.OrderByType.ASC);
    groupByColumn.setColumnIndex(1);
    AggregationColumn aggregationColumn = new AggregationColumn("SUM(0)", AggregationColumn.AggregationType.SUM, Optional.<String>absent(), Optional.<String>absent());
    aggregationColumn.setColumnIndex(2);
    GroupByResultSetRow row = new GroupByResultSetRow(rs, Collections.singletonList(groupByColumn), Collections.singletonList(aggregationColumn));
    row.aggregate();
    assertTrue(rs.next());
    row.aggregate();
    row.generateResult();
    assertFalse(rs.next());
}
Also used : AggregationColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.AggregationColumn) ResultSet(java.sql.ResultSet) TestResultSetRow(com.dangdang.ddframe.rdb.sharding.merger.fixture.TestResultSetRow) GroupByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn) Test(org.junit.Test)

Example 13 with GroupByColumn

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

the class ParseContext method addGroupByColumns.

/**
     * 将分组列加入解析上下文.
     * 
     * @param owner 列拥有者
     * @param name 列名称
     * @param orderByType 排序类型
     */
public void addGroupByColumns(final Optional<String> owner, final String name, final OrderByType orderByType) {
    String rawName = SQLUtil.getExactlyValue(name);
    parsedResult.getMergeContext().getGroupByColumns().add(new GroupByColumn(owner, rawName, getAlias(rawName), orderByType));
}
Also used : GroupByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn)

Aggregations

GroupByColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn)13 OrderByColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn)10 MergeContext (com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext)8 Test (org.junit.Test)7 AggregationColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.AggregationColumn)4 Limit (com.dangdang.ddframe.rdb.sharding.parser.result.merger.Limit)2 TestResultSetRow (com.dangdang.ddframe.rdb.sharding.merger.fixture.TestResultSetRow)1 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 ReflectionEquals (org.mockito.internal.matchers.apachecommons.ReflectionEquals)1