private Collection coalesceOrderedResults(Collection<Collection> results, ExecutionContext context, CompiledSelect cs, int limit) { List<Collection> sortedResults = new ArrayList<Collection>(results.size()); // TODO :Asif : Deal with UNDEFINED for (Object o : results) { if (o instanceof Collection) { sortedResults.add((Collection) o); } } return new NWayMergeResults(sortedResults, cs.isDistinct(), limit, cs.getOrderByAttrs(), context, cs.getElementTypeForOrderByQueries()); }
/** * Applies order-by on the results returned from PR nodes and puts the results in the cumulative * result set. The order-by is applied by running a generated query on the each result returned by * the remote nodes. Example generated query: SELECT DISTINCT * FROM $1 p ORDER BY p.ID Where * results are passed as bind parameter. This is added as quick turn-around, this is added based * on most commonly used queries, needs to be investigated further. */ private SelectResults buildSortedResult(CompiledSelect cs, int limit) throws QueryException { try { ExecutionContext localContext = new QueryExecutionContext(this.parameters, this.pr.cache); List<Collection> allResults = new ArrayList<Collection>(); for (Collection<Collection> memberResults : this.resultsPerMember.values()) { for (Collection res : memberResults) { if (res != null) { allResults.add(res); } } } this.cumulativeResults = new NWayMergeResults(allResults, cs.isDistinct(), limit, cs.getOrderByAttrs(), localContext, cs.getElementTypeForOrderByQueries()); return this.cumulativeResults; } catch (Exception ex) { throw new QueryException( "Unable to apply order-by on the partition region cumulative results.", ex); } }
orderByAttribs = cs.getOrderByAttrs(); ObjectType resultType = cs.getElementTypeForOrderByQueries(); ExecutionContext context = new ExecutionContext(null, CacheUtils.getCache()); final OrderByComparator obc = new OrderByComparator(orderByAttribs, resultType, context);
@Before public void setup() throws Exception { localNode = new InternalDistributedMember("localhost", 8888); remoteNodeA = new InternalDistributedMember("localhost", 8889); remoteNodeB = new InternalDistributedMember("localhost", 8890); cache = Fakes.cache(); system = (InternalDistributedSystem) cache.getDistributedSystem(); allNodes.add(localNode); allNodes.add(remoteNodeA); allNodes.add(remoteNodeB); pr = mock(PartitionedRegion.class); dataStore = new ExtendedPartitionedRegionDataStore(); CompiledSelect select = mock(CompiledSelect.class); when(select.getType()).thenReturn(CompiledValue.COMPARISON); when(select.getElementTypeForOrderByQueries()).thenReturn(new ObjectTypeImpl(String.class)); query = mock(DefaultQuery.class); when(query.getSimpleSelect()).thenReturn(select); when(query.getLimit(any())).thenReturn(-1); when(pr.getCachePerfStats()).thenReturn(mock(CachePerfStats.class)); when(pr.getMyId()).thenReturn(localNode); when(pr.getDataStore()).thenReturn(dataStore); when(pr.getCache()).thenReturn(cache); }