Search in sources :

Example 6 with GroupByColumn

use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn 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 7 with GroupByColumn

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

the class GroupByResultSetRowTest method createGroupByColumn.

private GroupByColumn createGroupByColumn(final String columnName, final int columnIndex) {
    GroupByColumn result = new GroupByColumn(Optional.<String>absent(), columnName, Optional.<String>absent(), OrderByColumn.OrderByType.ASC);
    result.setColumnIndex(columnIndex);
    return result;
}
Also used : GroupByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn)

Example 8 with GroupByColumn

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

the class ResultSetMergeContextTest method assertIsNeedMemorySortForOrderByWithGroupByAndOrderBySame.

@Test
public void assertIsNeedMemorySortForOrderByWithGroupByAndOrderBySame() throws SQLException {
    MergeContext mergeContext = new MergeContext();
    mergeContext.getOrderByColumns().add(new OrderByColumn("col", OrderByColumn.OrderByType.ASC));
    mergeContext.getGroupByColumns().add(new GroupByColumn(Optional.<String>absent(), "col", Optional.<String>absent(), OrderByColumn.OrderByType.ASC));
    ResultSetMergeContext actual = new ResultSetMergeContext(new ShardingResultSets(Collections.singletonList(MergerTestUtil.mockResult(Collections.singletonList("col")))), mergeContext);
    assertFalse(actual.isNeedMemorySortForOrderBy());
}
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 9 with GroupByColumn

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

the class ResultSetMergeContextTest method assertIsNeedMemorySortForOrderByWithGroupByAndOrderByDifferent.

@Test
public void assertIsNeedMemorySortForOrderByWithGroupByAndOrderByDifferent() 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();
    assertTrue(actual.isNeedMemorySortForOrderBy());
}
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 10 with GroupByColumn

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

the class ResultSetMergeContextTest method assertSetGroupByKeysToCurrentOrderByKeys.

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

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