CompiledSelect cs = this.query.getSimpleSelect();
CompiledSelect select = locQuery.getSimpleSelect(); if (select == null) { throw new UnsupportedOperationException(
InvocationTargetException { DefaultQuery q = (DefaultQuery) CacheUtils.getQueryService().newQuery(orderByQuery); CompiledSelect cs = q.getSimpleSelect(); List<CompiledSortCriterion> orderByAttribs = null; if (cs.getType() == CompiledValue.GROUP_BY_SELECT) {
private void executeSequentially(Collection<Collection> resultCollector, List buckets) throws QueryException, InterruptedException, ForceReattemptException { ExecutionContext context = new QueryExecutionContext(this.parameters, this.pr.getCache(), this.query); CompiledSelect cs = this.query.getSimpleSelect(); int limit = this.query.getLimit(parameters); if (cs != null && cs.isOrderBy()) { for (Integer bucketID : this._bucketsToQuery) { List<Integer> singleBucket = Collections.singletonList(bucketID); context.setBucketList(singleBucket); executeQueryOnBuckets(resultCollector, context); } Collection mergedResults = coalesceOrderedResults(resultCollector, context, cs, limit); resultCollector.clear(); resultCollector.add(mergedResults); } else { context.setBucketList(buckets); executeQueryOnBuckets(resultCollector, context); } }
List<CompiledSortCriterion> orderByAttribs = null; if (sender.getVersionObject().compareTo(Version.GFE_90) < 0) { CompiledSelect cs = this.query.getSimpleSelect(); if (cs != null && cs.isOrderBy()) { sortNeeded = true;
CompiledSelect select = getSimpleSelect(); if (select == null) { throw new UnsupportedOperationException(
@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); }
@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); }
/** * Returns parameterized query used by the server. This method replaces Region name with $1 and if * type is not specified in the query, looks for type from cqattributes and appends into the * query. * * @return String modified query. */ private Query constructServerSideQuery() throws QueryException { InternalCache cache = cqService.getInternalCache(); DefaultQuery locQuery = (DefaultQuery) cache.getLocalQueryService().newQuery(this.queryString); CompiledSelect select = locQuery.getSimpleSelect(); CompiledIteratorDef from = (CompiledIteratorDef) select.getIterators().get(0); // WARNING: ASSUMES QUERY WAS ALREADY VALIDATED FOR PROPER "FORM" ON CLIENT; // THIS VALIDATION WILL NEED TO BE DONE ON THE SERVER FOR NATIVE CLIENTS, // BUT IS NOT DONE HERE FOR JAVA CLIENTS. // The query was already checked on the client that the sole iterator is a // CompiledRegion this.regionName = ((CompiledRegion) from.getCollectionExpr()).getRegionPath(); from.setCollectionExpr(new CompiledBindArgument(1)); return locQuery; }
@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); }
/** * Should be constructed from DefaultQueryService * * @see QueryService#newQuery */ public DefaultQuery(String queryString, InternalCache cache, boolean isForRemote) { this.queryString = queryString; QCompiler compiler = new QCompiler(); this.compiledQuery = compiler.compileQuery(queryString); CompiledSelect cs = getSimpleSelect(); if (cs != null && !isForRemote && (cs.isGroupBy() || cs.isOrderBy())) { QueryExecutionContext ctx = new QueryExecutionContext(null, cache); try { cs.computeDependencies(ctx); } catch (QueryException qe) { throw new QueryInvalidException("", qe); } } this.traceOn = compiler.isTraceRequested() || QUERY_VERBOSE; this.cache = cache; this.stats = new DefaultQueryStatistics(); this.cancelationTask = Optional.empty(); }
CompiledSelect selectExpr = query.getSimpleSelect(); if (selectExpr == null) { throw new IllegalArgumentException(
cs = this.query.getSimpleSelect(); limit = this.query.getLimit(parameters); isDistinct = (cs != null) ? cs.isDistinct() : true;