Search in sources :

Example 11 with MergeContext

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

the class IteratorResultSetTest method assertNext.

@Test
public void assertNext() throws SQLException {
    ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1), new MockResultSet<>(2, 4), new MockResultSet<Integer>()), new MergeContext());
    int count = 0;
    while (resultSet.next()) {
        count++;
    }
    assertThat(count, is(3));
}
Also used : ResultSet(java.sql.ResultSet) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext) Test(org.junit.Test)

Example 12 with MergeContext

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

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

the class ResultSetMergeContextTest method assertIsNotNeedMemorySortForOrderByWithoutOrderBy.

@Test
public void assertIsNotNeedMemorySortForOrderByWithoutOrderBy() throws SQLException {
    ResultSetMergeContext actual = new ResultSetMergeContext(new ShardingResultSets(Collections.singletonList(MergerTestUtil.mockResult(Collections.<String>emptyList()))), new MergeContext());
    assertFalse(actual.isNeedMemorySortForOrderBy());
}
Also used : MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext) Test(org.junit.Test)

Example 14 with MergeContext

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

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

MergeContext (com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext)17 Test (org.junit.Test)13 OrderByColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn)9 GroupByColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn)8 ResultSet (java.sql.ResultSet)5 MockResultSet (com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet)3 Limit (com.dangdang.ddframe.rdb.sharding.parser.result.merger.Limit)3 PreparedStatementExecutorWrapper (com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper)1 TestResultSetRow (com.dangdang.ddframe.rdb.sharding.merger.fixture.TestResultSetRow)1 Value (com.dangdang.ddframe.rdb.sharding.parser.jaxb.Value)1 AggregationColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.AggregationColumn)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 SQLExecutionUnit (com.dangdang.ddframe.rdb.sharding.router.SQLExecutionUnit)1 SQLRouteResult (com.dangdang.ddframe.rdb.sharding.router.SQLRouteResult)1 Function (com.google.common.base.Function)1 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1