> Persistence getPersistenceFromQueryOpt
* Called when using an index to order results, to determine if or how results within each bucket
* in that index should be sorted.
*
- *
+ *
* We must sort results within each bucket, when:
*
* -
@@ -899,9 +1119,9 @@ static > Persistence getPersistenceFromQueryOpt
*
*
*
- * @param allSortOrders The user-specified sort orders
+ * @param allSortOrders The user-specified sort orders
* @param attributeCanHaveMoreThanOneValue If the primary attribute used for sorting can return more than one value
- * @param index The index from which the bucket is accessed
+ * @param index The index from which the bucket is accessed
* @return A list of AttributeOrder objects representing the sort order to apply to objects in the bucket
*/
static List> determineAdditionalSortOrdersForIndexOrdering(List> allSortOrders, boolean attributeCanHaveMoreThanOneValue, Index index, QueryOptions queryOptions) {
@@ -919,8 +1139,7 @@ static , O> CloseableIterator> getKeysAnd
typedBounds.upperBound, typedBounds.upperInclusive,
queryOptions
).iterator();
- }
- else {
+ } else {
return index.getKeysAndValuesDescending(
typedBounds.lowerBound, typedBounds.lowerInclusive,
typedBounds.upperBound, typedBounds.upperInclusive,
@@ -949,9 +1168,8 @@ static , O> RangeBounds getBoundsFromQuery(Query quer
List> candidateRangeQueries = Collections.emptyList();
if (query instanceof SimpleQuery) {
candidateRangeQueries = Collections.>singletonList((SimpleQuery) query);
- }
- else if (query instanceof And) {
- And and = (And)query;
+ } else if (query instanceof And) {
+ And and = (And) query;
if (and.hasSimpleQueries()) {
candidateRangeQueries = and.getSimpleQueries();
}
@@ -963,14 +1181,12 @@ else if (query instanceof And) {
GreaterThan bound = (GreaterThan) candidate;
lowerBound = bound.getValue();
lowerInclusive = bound.isValueInclusive();
- }
- else if (candidate instanceof LessThan) {
+ } else if (candidate instanceof LessThan) {
@SuppressWarnings("unchecked")
LessThan bound = (LessThan) candidate;
upperBound = bound.getValue();
upperInclusive = bound.isValueInclusive();
- }
- else if (candidate instanceof Between) {
+ } else if (candidate instanceof Between) {
@SuppressWarnings("unchecked")
Between bound = (Between) candidate;
lowerBound = bound.getLowerValue();
@@ -1002,9 +1218,9 @@ else if (candidate instanceof Between) {
* object as appropriate for {@link And}, {@link Or}, {@link Not} respectively. These {@link ResultSet} objects
* will take care of performing intersections or unions etc. on the child {@link ResultSet}s.
*
- * @param query A query representing some assertions which sought objects must match
+ * @param query A query representing some assertions which sought objects must match
* @param queryOptions Optional parameters for the query
- * supplied specifying strategy {@link DeduplicationStrategy#LOGICAL_ELIMINATION}
+ * supplied specifying strategy {@link DeduplicationStrategy#LOGICAL_ELIMINATION}
* @return A {@link ResultSet} which provides objects matching the given query
*/
ResultSet retrieveRecursive(Query query, final QueryOptions queryOptions) {
@@ -1017,20 +1233,16 @@ ResultSet retrieveRecursive(Query query, final QueryOptions queryOptions)
return resultSetFromStandingQueryIndex;
}
// ..else no standing query index was available, process the query normally...
-
-
if (query instanceof SimpleQuery) {
// No deduplication required for a single SimpleQuery.
// Return the ResultSet from the index with the lowest retrieval cost which supports
// this query and the attribute on which it is based...
return retrieveSimpleQuery((SimpleQuery) query, queryOptions);
- }
- else if (query instanceof ComparativeQuery) {
+ } else if (query instanceof ComparativeQuery) {
// Return the ResultSet from the index with the lowest retrieval cost which supports
// this query and the attribute on which it is based...
return retrieveComparativeQuery((ComparativeQuery) query, queryOptions);
- }
- else if (query instanceof And) {
+ } else if (query instanceof And) {
final And and = (And) query;
// Check if we can process this And query from a compound index...
@@ -1066,12 +1278,19 @@ public ResultSet next() {
if (needToProcessSimpleQueries) {
needToProcessSimpleQueries = false;
// Retrieve results for simple queries from indexes...
- return retrieveIntersectionOfSimpleQueries(and.getSimpleQueries(), queryOptions, indexMergeStrategyEnabled);
+ ResultSet resultSetSimple = retrieveIntersectionOfSimpleQueries(and.getSimpleQueries(), queryOptions, indexMergeStrategyEnabled);
+ List resultFromSimple = StreamSupport.stream(resultSetSimple.spliterator(), false).collect(Collectors.toList());
+ log.info(String.format("ResultSet %s from retrieveIntersectionOfSimpleQueries for query and.getSimpleQueries(): %s ", resultFromSimple, and.getSimpleQueries()));
+ return resultSetSimple;
+
}
if (needToProcessComparativeQueries) {
needToProcessComparativeQueries = false;
// Retrieve results for comparative queries from indexes...
- return retrieveIntersectionOfComparativeQueries(and.getComparativeQueries(), queryOptions);
+ ResultSet comparativeQueryResultSet = retrieveIntersectionOfComparativeQueries(and.getComparativeQueries(), queryOptions);
+ List resultFromComparative = StreamSupport.stream(comparativeQueryResultSet.spliterator(), false).collect(Collectors.toList());
+ log.info(String.format("ResultSet %s from retrieveIntersectionOfComparativeQueries for query and.getComparativeQueries(): %s ", resultFromComparative, and.getComparativeQueries()));
+ return comparativeQueryResultSet;
}
// Recursively call this method for logical queries...
return retrieveRecursive(logicalQueriesIterator.next(), queryOptions);
@@ -1081,8 +1300,7 @@ public ResultSet next() {
};
boolean useIndexMergeStrategy = shouldUseIndexMergeStrategy(indexMergeStrategyEnabled, and.hasComparativeQueries(), resultSetsToMerge);
return new ResultSetIntersection(resultSetsToMerge, query, queryOptions, useIndexMergeStrategy);
- }
- else if (query instanceof Or) {
+ } else if (query instanceof Or) {
final Or or = (Or) query;
// If the Or query indicates child queries are disjoint,
// ignore any instruction to perform deduplication in the queryOptions supplied...
@@ -1097,8 +1315,7 @@ public Object get(Object key) {
return DeduplicationOption.class.equals(key) ? null : super.get(key);
}
};
- }
- else {
+ } else {
// Use the supplied queryOptions...
queryOptionsForOrUnion = queryOptions;
}
@@ -1140,8 +1357,7 @@ public ResultSet next() {
if (DeduplicationOption.isLogicalElimination(queryOptionsForOrUnion)) {
boolean useIndexMergeStrategy = shouldUseIndexMergeStrategy(indexMergeStrategyEnabled, or.hasComparativeQueries(), resultSetsToUnion);
union = new ResultSetUnion(resultSetsToUnion, query, queryOptions, useIndexMergeStrategy);
- }
- else {
+ } else {
union = new ResultSetUnionAll(resultSetsToUnion, query, queryOptions);
}
@@ -1163,16 +1379,14 @@ public boolean isValid(O object, QueryOptions queryOptions) {
};
}
return union;
- }
- else if (query instanceof Not) {
+ } else if (query instanceof Not) {
final Not not = (Not) query;
// No deduplication required for negation (the entire collection is a Set, contains no duplicates).
// Retrieve the ResultSet for the negated query, by calling this method recursively...
ResultSet resultSetToNegate = retrieveRecursive(not.getNegatedQuery(), queryOptions);
// Return the negation of this result set, by subtracting it from the entire collection of objects...
return new ResultSetDifference(getEntireCollectionAsResultSet(query, queryOptions), resultSetToNegate, query, queryOptions, indexMergeStrategyEnabled);
- }
- else {
+ } else {
throw new IllegalStateException("Unexpected type of query object: " + getClassNameNullSafe(query));
}
}
@@ -1206,7 +1420,7 @@ else if (query instanceof Not) {
* {@link Query#matches(Object, QueryOptions)} to test each object in the smallest set against queries which would match the
* more expensive sets, rather than perform several hash lookups and equality tests between multiple sets.
*
- * @param queries A collection of {@link SimpleQuery} objects to be retrieved and intersected
+ * @param queries A collection of {@link SimpleQuery} objects to be retrieved and intersected
* @param queryOptions Optional parameters for the query
* @return A {@link ResultSet} which provides objects matching the intersection of results for each of the
* {@link SimpleQuery}s
@@ -1221,7 +1435,7 @@ ResultSet retrieveIntersectionOfSimpleQueries(Collection> queriesTyped = (Collection>)(Collection extends Query>)queries;
+ Collection> queriesTyped = (Collection>) (Collection extends Query>) queries;
Query query = queriesTyped.size() == 1 ? queriesTyped.iterator().next() : new And(queriesTyped);
boolean useIndexMergeStrategy = indexMergeStrategyEnabled && indexesAvailableForAllResultSets(resultSets);
@@ -1242,7 +1456,7 @@ ResultSet retrieveIntersectionOfComparativeQueries(Collection> queriesTyped = (Collection>)(Collection extends Query>)queries;
+ Collection> queriesTyped = (Collection>) (Collection extends Query>) queries;
Query query = queriesTyped.size() == 1 ? queriesTyped.iterator().next() : new And(queriesTyped);
// We always use index merge strategy to merge results for comparative queries...
@@ -1268,9 +1482,9 @@ ResultSet retrieveIntersectionOfComparativeQueries(Collection> iterator() {
return new UnmodifiableIterator>() {
Iterator> queriesIterator = queries.iterator();
+
@Override
public boolean hasNext() {
return queriesIterator.hasNext();
@@ -1294,7 +1509,7 @@ public ResultSet next() {
}
};
@SuppressWarnings("unchecked")
- Collection> queriesTyped = (Collection>)(Collection extends Query>)queries;
+ Collection> queriesTyped = (Collection>) (Collection extends Query>) queries;
Query query = queriesTyped.size() == 1 ? queriesTyped.iterator().next() : new Or(queriesTyped);
// Perform deduplication as necessary...
if (DeduplicationOption.isLogicalElimination(queryOptions)) {
@@ -1302,8 +1517,7 @@ public ResultSet next() {
boolean indexMergeStrategyEnabled = isFlagEnabled(queryOptions, PREFER_INDEX_MERGE_STRATEGY);
boolean useIndexMergeStrategy = indexMergeStrategyEnabled && indexesAvailableForAllResultSets(resultSetsToUnion);
return new ResultSetUnion(resultSetsToUnion, query, queryOptions, useIndexMergeStrategy);
- }
- else {
+ } else {
return new ResultSetUnionAll(resultSetsToUnion, query, queryOptions);
}
}
@@ -1319,6 +1533,7 @@ public Iterator> iterator() {
return new UnmodifiableIterator>() {
Iterator> queriesIterator = queries.iterator();
+
@Override
public boolean hasNext() {
return queriesIterator.hasNext();
@@ -1332,14 +1547,13 @@ public ResultSet next() {
}
};
@SuppressWarnings("unchecked")
- Collection> queriesTyped = (Collection>)(Collection extends Query>)queries;
+ Collection> queriesTyped = (Collection>) (Collection extends Query>) queries;
Query query = queriesTyped.size() == 1 ? queriesTyped.iterator().next() : new Or