Skip to content

Commit

Permalink
Issue #1843 tests for "order by" when collection is sorted only parti…
Browse files Browse the repository at this point in the history
…ally by index were added.
  • Loading branch information
andrii0lomakin committed Feb 12, 2014
1 parent 52d08e6 commit 2b510a5
Show file tree
Hide file tree
Showing 4 changed files with 358 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public void getValuesMinor(Object toKey, boolean isInclusive, boolean ascSortOrd
}
}

private void getValuesMinorDescOrder(Object toKey, boolean isInclusive, ValuesTransformer<V> transformer,
private void getValuesMinorAscOrder(Object toKey, boolean isInclusive, ValuesTransformer<V> transformer,
ValuesResultListener valuesResultListener) {
final OMVRBTreeEntry<Object, V> lastEntry;

Expand All @@ -547,7 +547,7 @@ private void getValuesMinorDescOrder(Object toKey, boolean isInclusive, ValuesTr
}
}

private void getValuesMinorAscOrder(Object toKey, boolean isInclusive, ValuesTransformer<V> transformer,
private void getValuesMinorDescOrder(Object toKey, boolean isInclusive, ValuesTransformer<V> transformer,
ValuesResultListener valuesResultListener) {
final OMVRBTreeEntry<Object, V> firstEntry = map.getFirstEntry();
if (firstEntry == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ private void applyTailIndexes(final Object result, IndexValuesResultListener res

private Set<Comparable> convertResult(Object result, Class<?> targetType) {
final Set<Comparable> newKeys;
if (result instanceof Set) {
if (result instanceof Collection) {
newKeys = new TreeSet<Comparable>();
for (Object o : ((Set) result)) {
for (Object o : ((Collection) result)) {
newKeys.add((Comparable) OType.convert(o, targetType));
}
return newKeys;
Expand All @@ -369,8 +369,8 @@ private Set<Comparable> prepareKeys(OIndex<?> index, Object keys) {
private void applyMainIndex(Iterable<Comparable> currentKeys, IndexValuesResultListener resultListener) {
keysLoop: for (Comparable key : currentKeys) {
final T result = index.get(index.getDefinition().createValue(key));
if (result instanceof Set) {
for (T o : (Set<T>) result) {
if (result instanceof Collection) {
for (T o : (Collection<T>) result) {
if (!resultListener.addResult((OIdentifiable) o))
break keysLoop;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ public int compare(final OIndexSearchResult searchResultOne, final OIndexSearchR
}

Object result;
final boolean indexIsUsedInOrderBy = canBeUsedByOrderBy(indexDefinition);
final boolean indexIsUsedInOrderBy = canBeUsedByOrderBy(indexDefinition)
&& !(index.getInternal() instanceof OChainedIndexProxy);
try {
boolean ascSortOrder;
if (indexIsUsedInOrderBy)
Expand All @@ -706,8 +707,7 @@ public int compare(final OIndexSearchResult searchResultOne, final OIndexSearchR
if (fetchLimit < 0 && orderedFields.isEmpty())
resultListener = null;
else
resultListener = new IndexResultListener(indexIsUsedInOrderBy ? fetchLimit
: (orderedFields.isEmpty() ? fetchLimit : -1));
resultListener = new IndexResultListener(fullySortedByIndex ? fetchLimit : (orderedFields.isEmpty() ? fetchLimit : -1));

result = operator.executeIndexQuery(context, index, keyParams, ascSortOrder, resultListener, fetchLimit);
} catch (Exception e) {
Expand Down Expand Up @@ -1483,10 +1483,10 @@ public int compare(final OIndex<?> indexOne, final OIndex<?> indexTwo) {
final int result = firstParamCount - secondParamCount;

if (result == 0 && !orderedFields.isEmpty()) {
if (canBeUsedByOrderBy(definitionOne))
if (!(indexOne instanceof OChainedIndexProxy) && canBeUsedByOrderBy(definitionOne))
return 1;

if (canBeUsedByOrderBy(definitionTwo))
if (!(indexTwo instanceof OChainedIndexProxy) && canBeUsedByOrderBy(definitionTwo))
return -1;
}

Expand Down
Loading

0 comments on commit 2b510a5

Please sign in to comment.