Search in sources :

Example 1 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class MemoryQueryResultRowTest method setUp.

@Before
public void setUp() throws SQLException {
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
    when(resultSetMetaData.getColumnCount()).thenReturn(1);
    when(resultSet.getObject(1)).thenReturn("value");
    memoryResultSetRow = new MemoryQueryResultRow(new TestQueryResult(resultSet));
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) Before(org.junit.Before)

Example 2 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class StreamMergedResultTest method setUp.

@Before
public void setUp() {
    streamMergedResult = new TestStreamMergedResult();
    streamMergedResult.setCurrentQueryResult(new TestQueryResult(resultSet));
}
Also used : TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) TestStreamMergedResult(io.shardingjdbc.core.merger.dql.common.fixture.TestStreamMergedResult) Before(org.junit.Before)

Example 3 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class GroupByMemoryMergedResultTest method setUp.

@Before
public void setUp() throws SQLException {
    resultSets = Lists.newArrayList(mockResultSet(), mockResultSet(), mockResultSet());
    queryResults = new ArrayList<>(resultSets.size());
    for (ResultSet each : resultSets) {
        queryResults.add(new TestQueryResult(each));
    }
    selectStatement = new SelectStatement();
    AggregationSelectItem aggregationSelectItem1 = new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent());
    aggregationSelectItem1.setIndex(1);
    AggregationSelectItem aggregationSelectItem2 = new AggregationSelectItem(AggregationType.AVG, "(num)", Optional.<String>absent());
    aggregationSelectItem2.setIndex(2);
    AggregationSelectItem derivedAggregationSelectItem1 = new AggregationSelectItem(AggregationType.COUNT, "(num)", Optional.of("AVG_DERIVED_COUNT_0"));
    aggregationSelectItem2.setIndex(4);
    aggregationSelectItem2.getDerivedAggregationSelectItems().add(derivedAggregationSelectItem1);
    AggregationSelectItem derivedAggregationSelectItem2 = new AggregationSelectItem(AggregationType.SUM, "(num)", Optional.of("AVG_DERIVED_SUM_0"));
    aggregationSelectItem2.setIndex(5);
    aggregationSelectItem2.getDerivedAggregationSelectItems().add(derivedAggregationSelectItem2);
    selectStatement.getItems().add(aggregationSelectItem1);
    selectStatement.getItems().add(aggregationSelectItem2);
    selectStatement.getGroupByItems().add(new OrderItem(3, OrderDirection.ASC, OrderDirection.ASC));
    selectStatement.getOrderByItems().add(new OrderItem(3, OrderDirection.DESC, OrderDirection.ASC));
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) ResultSet(java.sql.ResultSet) Before(org.junit.Before)

Example 4 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class GroupByRowComparatorTest method mockQueryResult.

private QueryResult mockQueryResult(final Object... values) throws SQLException {
    ResultSet result = mock(ResultSet.class);
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(result.getMetaData()).thenReturn(resultSetMetaData);
    when(resultSetMetaData.getColumnCount()).thenReturn(values.length);
    int index = 0;
    for (Object each : values) {
        when(result.getObject(++index)).thenReturn(each);
    }
    return new TestQueryResult(result);
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) ResultSet(java.sql.ResultSet)

Example 5 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class GroupByStreamMergedResultTest method setUp.

@Before
public void setUp() throws SQLException {
    resultSets = Lists.newArrayList(mockResultSet(), mockResultSet(), mockResultSet());
    queryResults = new ArrayList<>(resultSets.size());
    for (ResultSet each : resultSets) {
        queryResults.add(new TestQueryResult(each));
    }
    selectStatement = new SelectStatement();
    AggregationSelectItem aggregationSelectItem1 = new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent());
    aggregationSelectItem1.setIndex(1);
    AggregationSelectItem aggregationSelectItem2 = new AggregationSelectItem(AggregationType.AVG, "(num)", Optional.<String>absent());
    aggregationSelectItem2.setIndex(2);
    AggregationSelectItem derivedAggregationSelectItem1 = new AggregationSelectItem(AggregationType.COUNT, "(num)", Optional.of("AVG_DERIVED_COUNT_0"));
    aggregationSelectItem2.setIndex(5);
    aggregationSelectItem2.getDerivedAggregationSelectItems().add(derivedAggregationSelectItem1);
    AggregationSelectItem derivedAggregationSelectItem2 = new AggregationSelectItem(AggregationType.SUM, "(num)", Optional.of("AVG_DERIVED_SUM_0"));
    aggregationSelectItem2.setIndex(6);
    aggregationSelectItem2.getDerivedAggregationSelectItems().add(derivedAggregationSelectItem2);
    selectStatement.getItems().add(aggregationSelectItem1);
    selectStatement.getItems().add(aggregationSelectItem2);
    selectStatement.getGroupByItems().add(new OrderItem(3, OrderDirection.ASC, OrderDirection.ASC));
    selectStatement.getOrderByItems().add(new OrderItem(3, OrderDirection.ASC, OrderDirection.ASC));
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) ResultSet(java.sql.ResultSet) Before(org.junit.Before)

Aggregations

TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)22 Before (org.junit.Before)14 ResultSet (java.sql.ResultSet)13 ResultSetMetaData (java.sql.ResultSetMetaData)11 OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)9 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)8 Test (org.junit.Test)7 TestComplexKeysShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestComplexKeysShardingAlgorithm)2 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)2 TableRuleConfiguration (io.shardingjdbc.core.api.config.TableRuleConfiguration)2 ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)2 AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)2 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)2 MergedResult (io.shardingjdbc.core.merger.MergedResult)1 DQLMergeEngine (io.shardingjdbc.core.merger.dql.DQLMergeEngine)1 TestStreamMergedResult (io.shardingjdbc.core.merger.dql.common.fixture.TestStreamMergedResult)1