Search in sources :

Example 16 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.

the class GroupByRowComparatorTest method assertCompareToForDecsWithOrderByItems.

@Test
public void assertCompareToForDecsWithOrderByItems() throws SQLException {
    MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
    MemoryQueryResultRow o2 = new MemoryQueryResultRow(mockQueryResult("3", "4"));
    SelectStatement selectStatement = new SelectStatement();
    selectStatement.getOrderByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
    selectStatement.getGroupByItems().addAll(Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(2, OrderDirection.ASC, OrderDirection.ASC)));
    GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatement);
    assertTrue(groupByRowComparator.compare(o1, o2) > 0);
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) MemoryQueryResultRow(io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 17 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem 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)

Example 18 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.

the class GroupByValueTest method assertGroupByValueEquals.

@Test
public void assertGroupByValueEquals() throws SQLException {
    GroupByValue groupByValue1 = new GroupByValue(new TestQueryResult(resultSet), Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(3, OrderDirection.DESC, OrderDirection.ASC)));
    GroupByValue groupByValue2 = new GroupByValue(new TestQueryResult(resultSet), Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(3, OrderDirection.DESC, OrderDirection.ASC)));
    assertTrue(groupByValue1.equals(groupByValue2));
    assertTrue(groupByValue2.equals(groupByValue1));
    assertTrue(groupByValue1.hashCode() == groupByValue2.hashCode());
}
Also used : TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 19 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.

the class OrderByValueTest method assertCompareToForDesc.

@Test
public void assertCompareToForDesc() throws SQLException {
    OrderByValue orderByValue1 = new OrderByValue(new TestQueryResult(resultSet1), Arrays.asList(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
    assertTrue(orderByValue1.next());
    when(resultSet2.getObject(1)).thenReturn("3");
    when(resultSet2.getObject(2)).thenReturn("4");
    OrderByValue orderByValue2 = new OrderByValue(new TestQueryResult(resultSet2), Arrays.asList(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC), new OrderItem(2, OrderDirection.DESC, OrderDirection.ASC)));
    assertTrue(orderByValue2.next());
    assertTrue(orderByValue1.compareTo(orderByValue2) > 0);
    assertFalse(orderByValue1.getQueryResult().next());
    assertFalse(orderByValue2.getQueryResult().next());
}
Also used : TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 20 with OrderItem

use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.

the class GroupByAssert method assertGroupByItems.

/**
 * Assert group by items.
 *
 * @param actual actual group by items
 * @param expected expected group by items
 */
public void assertGroupByItems(final List<OrderItem> actual, final List<ExpectedGroupByColumn> expected) {
    assertThat(assertMessage.getFullAssertMessage("Group by items size error: "), actual.size(), is(expected.size()));
    int count = 0;
    for (OrderItem each : actual) {
        assertGroupByItem(each, expected.get(count));
        count++;
    }
}
Also used : OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem)

Aggregations

OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)42 Test (org.junit.Test)30 Limit (io.shardingjdbc.core.parsing.parser.context.limit.Limit)12 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)12 GroupByMemoryMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult)10 GroupByStreamMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByStreamMergedResult)10 OrderByStreamMergedResult (io.shardingjdbc.core.merger.dql.orderby.OrderByStreamMergedResult)10 MergedResult (io.shardingjdbc.core.merger.MergedResult)9 IteratorStreamMergedResult (io.shardingjdbc.core.merger.dql.iterator.IteratorStreamMergedResult)9 LimitDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.LimitDecoratorMergedResult)9 RowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.RowNumberDecoratorMergedResult)9 TopAndRowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult)9 TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)9 MemoryQueryResultRow (io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow)6 TableToken (io.shardingjdbc.core.parsing.parser.token.TableToken)4 LimitValue (io.shardingjdbc.core.parsing.parser.context.limit.LimitValue)3 OffsetToken (io.shardingjdbc.core.parsing.parser.token.OffsetToken)3 RowCountToken (io.shardingjdbc.core.parsing.parser.token.RowCountToken)3 ResultSet (java.sql.ResultSet)3 Before (org.junit.Before)3