use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.
the class OrderByAssert method assertOrderByItems.
/**
* Assert order by items.
*
* @param actual actual order by items
* @param expected expected order by items
*/
public void assertOrderByItems(final List<OrderItem> actual, final List<ExpectedOrderByColumn> expected) {
assertThat(assertMessage.getFullAssertMessage("Order by items size error: "), actual.size(), is(expected.size()));
int count = 0;
for (OrderItem each : actual) {
assertOrderByItem(each, expected.get(count));
count++;
}
}
use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.
the class GroupByRowComparator method compare.
private int compare(final MemoryQueryResultRow o1, final MemoryQueryResultRow o2, final List<OrderItem> orderItems) {
for (OrderItem each : orderItems) {
Object orderValue1 = o1.getCell(each.getIndex());
Preconditions.checkState(null == orderValue1 || orderValue1 instanceof Comparable, "Order by value must implements Comparable");
Object orderValue2 = o2.getCell(each.getIndex());
Preconditions.checkState(null == orderValue2 || orderValue2 instanceof Comparable, "Order by value must implements Comparable");
int result = CompareUtil.compareTo((Comparable) orderValue1, (Comparable) orderValue2, each.getOrderDirection(), each.getNullOrderDirection());
if (0 != result) {
return result;
}
}
return 0;
}
use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.
the class OrderByValue method compareTo.
@Override
public int compareTo(final OrderByValue o) {
for (int i = 0; i < orderByItems.size(); i++) {
OrderItem thisOrderBy = orderByItems.get(i);
int result = CompareUtil.compareTo(orderValues.get(i), o.orderValues.get(i), thisOrderBy.getOrderDirection(), thisOrderBy.getNullOrderDirection());
if (0 != result) {
return result;
}
}
return 0;
}
use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.
the class GroupByClauseParser method addGroupByItem.
private void addGroupByItem(final SQLExpression sqlExpression, final SelectStatement selectStatement) {
lexerEngine.unsupportedIfEqual(getUnsupportedKeywordBeforeGroupByItem());
OrderDirection orderDirection = OrderDirection.ASC;
if (lexerEngine.equalAny(DefaultKeyword.ASC)) {
lexerEngine.nextToken();
} else if (lexerEngine.skipIfEqual(DefaultKeyword.DESC)) {
orderDirection = OrderDirection.DESC;
}
OrderItem orderItem;
if (sqlExpression instanceof SQLPropertyExpression) {
SQLPropertyExpression sqlPropertyExpression = (SQLPropertyExpression) sqlExpression;
orderItem = new OrderItem(SQLUtil.getExactlyValue(sqlPropertyExpression.getOwner().getName()), SQLUtil.getExactlyValue(sqlPropertyExpression.getName()), orderDirection, OrderDirection.ASC, selectStatement.getAlias(SQLUtil.getExactlyValue(sqlPropertyExpression.getOwner().getName() + "." + SQLUtil.getExactlyValue(sqlPropertyExpression.getName()))));
} else if (sqlExpression instanceof SQLIdentifierExpression) {
SQLIdentifierExpression sqlIdentifierExpression = (SQLIdentifierExpression) sqlExpression;
orderItem = new OrderItem(SQLUtil.getExactlyValue(sqlIdentifierExpression.getName()), orderDirection, OrderDirection.ASC, selectStatement.getAlias(SQLUtil.getExactlyValue(sqlIdentifierExpression.getName())));
} else if (sqlExpression instanceof SQLIgnoreExpression) {
SQLIgnoreExpression sqlIgnoreExpression = (SQLIgnoreExpression) sqlExpression;
orderItem = new OrderItem(sqlIgnoreExpression.getExpression(), orderDirection, OrderDirection.ASC, selectStatement.getAlias(sqlIgnoreExpression.getExpression()));
} else {
return;
}
selectStatement.getGroupByItems().add(orderItem);
}
use of io.shardingjdbc.core.parsing.parser.context.OrderItem in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildGroupByMemoryMergedResultWithSQLServerLimit.
@Test
public void assertBuildGroupByMemoryMergedResultWithSQLServerLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
selectStatement.getGroupByItems().add(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC));
selectStatement.getGroupByItems().add(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class));
}
Aggregations