Search in sources :

Example 1 with TestResultSetRow

use of com.dangdang.ddframe.rdb.sharding.merger.fixture.TestResultSetRow in project sharding-jdbc by dangdangdotcom.

the class AggregationResultSetTest method assertNext.

@Test
public void assertNext() throws SQLException {
    MergeContext mergeContext = new MergeContext();
    mergeContext.getAggregationColumns().add(MergerTestUtil.createAggregationColumn(aggregationType, columnNames.get(0), null, 1));
    ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.asList(MergerTestUtil.mockResult(columnNames, Collections.<ResultSetRow>singletonList(new TestResultSetRow(resultSetData1))), MergerTestUtil.mockResult(columnNames, Collections.<ResultSetRow>singletonList(new TestResultSetRow(resultSetData2))), MergerTestUtil.mockResult(Collections.<String>emptyList())), mergeContext);
    assertTrue(resultSet.next());
    if (AggregationType.AVG == aggregationType) {
        assertThat(resultSet.getDouble(1), is(result));
        assertThat(resultSet.getDouble(columnNames.get(0)), is(result));
    } else {
        assertThat(resultSet.getInt(1), is(result));
        assertThat(resultSet.getInt(columnNames.get(0)), is(result));
    }
    assertFalse(resultSet.next());
}
Also used : ResultSet(java.sql.ResultSet) TestResultSetRow(com.dangdang.ddframe.rdb.sharding.merger.fixture.TestResultSetRow) MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext) Test(org.junit.Test)

Example 2 with TestResultSetRow

use of com.dangdang.ddframe.rdb.sharding.merger.fixture.TestResultSetRow in project sharding-jdbc by dangdangdotcom.

the class GroupByResultSetRowTest method assertGetGroupByValues.

@Test
public void assertGetGroupByValues() throws SQLException {
    ResultSet resultSet = MergerTestUtil.mockResult(Arrays.asList("group_col_1", "group_col_2", "other_col"), Collections.<ResultSetRow>singletonList(new TestResultSetRow("group_1", "group_2", "other")));
    List<Object> actual = new GroupByResultSetRow(resultSet, Arrays.asList(createGroupByColumn("group_col_1", 1), createGroupByColumn("group_col_2", 2)), Collections.singletonList(new AggregationColumn("SUM(0)", AggregationColumn.AggregationType.SUM, Optional.<String>absent(), Optional.<String>absent()))).getGroupByValues();
    assertThat(actual.size(), is(2));
    assertThat(actual.get(0).toString(), is("group_1"));
    assertThat(actual.get(1).toString(), is("group_2"));
}
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) Test(org.junit.Test)

Example 3 with TestResultSetRow

use of com.dangdang.ddframe.rdb.sharding.merger.fixture.TestResultSetRow 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)

Aggregations

TestResultSetRow (com.dangdang.ddframe.rdb.sharding.merger.fixture.TestResultSetRow)3 ResultSet (java.sql.ResultSet)3 Test (org.junit.Test)3 AggregationColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.AggregationColumn)2 GroupByColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.GroupByColumn)1 MergeContext (com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext)1