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);
}
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));
}
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());
}
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());
}
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++;
}
}
Aggregations