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()); }
/** * set keepSerialized flag for remote queries of type 'select *' having independent operators */ void keepResultsSerialized(CompiledSelect cs, ExecutionContext context) { if (isRemoteQuery()) { // for dependent iterators, deserialization is required if (cs.getIterators().size() == context.getAllIndependentIteratorsOfCurrentScope().size() && cs.getWhereClause() == null && cs.getProjectionAttributes() == null && !cs.isDistinct() && cs.getOrderByAttrs() == null) { setKeepSerialized(); } } }
/** * 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); } }
List orderBys = select.getOrderByAttrs(); if (orderBys != null) { throw new UnsupportedOperationException(
orderByAttribs = (List<CompiledSortCriterion>) originalOrderByMethod.get(cs); } else { orderByAttribs = cs.getOrderByAttrs();
if (cs != null && cs.isOrderBy()) { sortNeeded = true; orderByAttribs = cs.getOrderByAttrs();
List<CompiledSortCriterion> orderBys = select.getOrderByAttrs(); if (orderBys != null) { for (CompiledSortCriterion orderBy : orderBys) {
@Test public void testOrderByWithColumnAlias_Bug52041_1() throws Exception { Region region = createRegion("portfolio", Portfolio.class); for (int i = 1; i < 200; ++i) { Portfolio pf = new Portfolio(i); pf.shortID = (short) ((short) i / 5); pf.status = "active"; region.put("" + i, pf); } String queryStr = "select distinct p.status, p.shortID as short_id from /portfolio p where p.ID >= 0 " + "order by short_id asc"; QueryService qs = CacheUtils.getQueryService(); Query query = qs.newQuery(queryStr); SelectResults<Struct> results = (SelectResults<Struct>) query.execute(); Iterator<Struct> iter = results.asList().iterator(); int counter = 0; while (iter.hasNext()) { Struct str = iter.next(); assertEquals(counter, ((Short) str.get("short_id")).intValue()); ++counter; } assertEquals(39, counter - 1); CompiledSelect cs = ((DefaultQuery) query).getSimpleSelect(); List<CompiledSortCriterion> orderbyAtts = cs.getOrderByAttrs(); assertEquals(orderbyAtts.get(0).getColumnIndex(), 1); }
@Test public void testOrderByWithColumnAlias_Bug52041_2() throws Exception { Region region = createRegion("portfolio", Portfolio.class); for (int i = 0; i < 200; ++i) { Portfolio pf = new Portfolio(i); pf.shortID = (short) ((short) i / 5); pf.status = "active"; region.put("" + i, pf); } String queryStr = "select distinct p.ID as _id, p.shortID as short_id from /portfolio p where p.ID >= 0 " + "order by short_id asc, p.ID desc"; QueryService qs = CacheUtils.getQueryService(); Query query = qs.newQuery(queryStr); SelectResults<Struct> results = (SelectResults<Struct>) query.execute(); Iterator<Struct> iter = results.asList().iterator(); int counter = 0; int k = 0; while (iter.hasNext()) { k = ((counter) / 5 + 1) * 5 - 1; Struct str = iter.next(); assertEquals(counter / 5, ((Short) str.get("short_id")).intValue()); assertEquals(k - (counter) % 5, ((Integer) str.get("_id")).intValue()); ++counter; } CompiledSelect cs = ((DefaultQuery) query).getSimpleSelect(); List<CompiledSortCriterion> orderbyAtts = cs.getOrderByAttrs(); assertEquals(orderbyAtts.get(0).getColumnIndex(), 1); assertEquals(orderbyAtts.get(1).getColumnIndex(), 0); }
if (selectExpr.getOrderByAttrs() != null) {
} else { if (this.cumulativeResults.getCollectionType().isOrdered() && cs.getOrderByAttrs() != null) {