Search in sources :

Example 1 with ResultsSet

use of org.apache.geode.cache.query.internal.ResultsSet in project geode by apache.

the class DummyQRegion method getKeys.

@Override
public SelectResults getKeys() {
    if (keys == null) {
        keys = new ResultsSet();
        keys.setElementType(keyType);
    }
    keys.clear();
    keys.add(entry.getKey());
    return keys;
}
Also used : ResultsSet(org.apache.geode.cache.query.internal.ResultsSet)

Example 2 with ResultsSet

use of org.apache.geode.cache.query.internal.ResultsSet in project geode by apache.

the class PartitionedRegion method doExecuteQuery.

/**
   * If ForceReattemptException is thrown then the caller must loop and call us again.
   * 
   * @throws ForceReattemptException if one of the buckets moved out from under us
   */
private Object doExecuteQuery(DefaultQuery query, Object[] parameters, Set buckets) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException, ForceReattemptException {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing query :{}", query);
    }
    HashSet<Integer> allBuckets = new HashSet<Integer>();
    if (buckets == null) {
        // remote buckets
        final Iterator remoteIter = getRegionAdvisor().getBucketSet().iterator();
        try {
            while (remoteIter.hasNext()) {
                allBuckets.add((Integer) remoteIter.next());
            }
        } catch (NoSuchElementException ignore) {
        }
    } else {
        // local buckets
        Iterator localIter = null;
        if (this.dataStore != null) {
            localIter = buckets.iterator();
        } else {
            localIter = Collections.emptySet().iterator();
        }
        try {
            while (localIter.hasNext()) {
                allBuckets.add((Integer) localIter.next());
            }
        } catch (NoSuchElementException ignore) {
        }
    }
    if (allBuckets.size() == 0) {
        if (logger.isDebugEnabled()) {
            logger.debug("No bucket storage allocated. PR has no data yet.");
        }
        ResultsSet resSet = new ResultsSet();
        resSet.setElementType(new ObjectTypeImpl(this.getValueConstraint() == null ? Object.class : this.getValueConstraint()));
        return resSet;
    }
    CompiledSelect selectExpr = query.getSimpleSelect();
    if (selectExpr == null) {
        throw new IllegalArgumentException(LocalizedStrings.PartitionedRegion_QUERY_MUST_BE_A_SELECT_EXPRESSION_ONLY.toLocalizedString());
    }
    // this can return a BAG even if it's a DISTINCT select expression,
    // since the expectation is that the duplicates will be removed at the end
    SelectResults results = selectExpr.getEmptyResultSet(parameters, getCache(), query);
    PartitionedRegionQueryEvaluator prqe = new PartitionedRegionQueryEvaluator(this.getSystem(), this, query, parameters, results, allBuckets);
    for (; ; ) {
        this.getCancelCriterion().checkCancelInProgress(null);
        boolean interrupted = Thread.interrupted();
        try {
            results = prqe.queryBuckets(null);
            break;
        } catch (InterruptedException ignore) {
            interrupted = true;
        } catch (FunctionDomainException e) {
            throw e;
        } catch (TypeMismatchException e) {
            throw e;
        } catch (NameResolutionException e) {
            throw e;
        } catch (QueryInvocationTargetException e) {
            throw e;
        } catch (QueryException qe) {
            throw new QueryInvocationTargetException(LocalizedStrings.PartitionedRegion_UNEXPECTED_QUERY_EXCEPTION_OCCURRED_DURING_QUERY_EXECUTION_0.toLocalizedString(qe.getMessage()), qe);
        } finally {
            if (interrupted) {
                Thread.currentThread().interrupt();
            }
        }
    }
    // for
    // Drop Duplicates if this is a DISTINCT query
    boolean allowsDuplicates = results.getCollectionType().allowsDuplicates();
    // be exactly matching the limit
    if (selectExpr.isDistinct()) {
        // don't just convert to a ResultsSet (or StructSet), since
        // the bags can convert themselves to a Set more efficiently
        ObjectType elementType = results.getCollectionType().getElementType();
        if (selectExpr.getOrderByAttrs() != null) {
        // Set limit also, its not applied while building the final result set as order by is
        // involved.
        } else if (allowsDuplicates) {
            results = new ResultsCollectionWrapper(elementType, results.asSet());
        }
        if (selectExpr.isCount() && (results.isEmpty() || selectExpr.isDistinct())) {
            // Constructor with elementType not visible.
            SelectResults resultCount = new ResultsBag(getCachePerfStats());
            resultCount.setElementType(new ObjectTypeImpl(Integer.class));
            ((Bag) resultCount).addAndGetOccurence(results.size());
            return resultCount;
        }
    }
    return results;
}
Also used : ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Bag(org.apache.geode.cache.query.internal.Bag) ResultsBag(org.apache.geode.cache.query.internal.ResultsBag) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectType(org.apache.geode.cache.query.types.ObjectType) QueryException(org.apache.geode.cache.query.QueryException) SelectResults(org.apache.geode.cache.query.SelectResults) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) ResultsCollectionWrapper(org.apache.geode.cache.query.internal.ResultsCollectionWrapper) PREntriesIterator(org.apache.geode.internal.cache.partitioned.PREntriesIterator) Iterator(java.util.Iterator) CompiledSelect(org.apache.geode.cache.query.internal.CompiledSelect) ResultsBag(org.apache.geode.cache.query.internal.ResultsBag) NoSuchElementException(java.util.NoSuchElementException) HashSet(java.util.HashSet)

Example 3 with ResultsSet

use of org.apache.geode.cache.query.internal.ResultsSet in project geode by apache.

the class PerfQuery method getMissHandQuery.

private Query getMissHandQuery(String queryString) {
    return new HandQuery(queryString) {

        public Object execute() {
            Region region = PerfQuery.this.cache.getRegion("/portfolios");
            SelectResults results = new ResultsSet();
            for (Iterator itr = region.values().iterator(); itr.hasNext(); ) {
                Portfolio ptflo = (Portfolio) itr.next();
                if ("miss".equals(ptflo.getType())) {
                    results.add(ptflo);
                }
            }
            return results;
        }
    };
}
Also used : ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) Portfolio(org.apache.geode.cache.query.data.Portfolio) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region)

Example 4 with ResultsSet

use of org.apache.geode.cache.query.internal.ResultsSet in project geode by apache.

the class PerfQuery method getType1HandQuery.

// --------------------------------------------------------
// Hand-Coded Queries
private Query getType1HandQuery(String queryString) {
    return new HandQuery(queryString) {

        public Object execute() {
            Region region = PerfQuery.this.cache.getRegion("/portfolios");
            SelectResults results = new ResultsSet();
            for (Iterator itr = region.values().iterator(); itr.hasNext(); ) {
                Portfolio ptflo = (Portfolio) itr.next();
                if ("type1".equals(ptflo.getType())) {
                    results.add(ptflo);
                }
            }
            return results;
        }
    };
}
Also used : ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) Portfolio(org.apache.geode.cache.query.data.Portfolio) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region)

Example 5 with ResultsSet

use of org.apache.geode.cache.query.internal.ResultsSet in project geode by apache.

the class DummyQRegion method getEntries.

@Override
public SelectResults getEntries() {
    if (entries == null) {
        entries = new ResultsSet();
        entries.setElementType(TypeUtils.getRegionEntryType(getRegion()));
    }
    entries.clear();
    // return collection of Region.Entry, not (dotless) RegionEntry
    Region rgn = getRegion();
    // unwrap until we get the LocalRegion
    while (!(rgn instanceof LocalRegion)) {
        rgn = ((QRegion) TypeUtils.checkCast(rgn, QRegion.class)).getRegion();
    }
    entries.add(((LocalRegion) rgn).new NonTXEntry(entry));
    return entries;
}
Also used : ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) QRegion(org.apache.geode.cache.query.internal.QRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Aggregations

ResultsSet (org.apache.geode.cache.query.internal.ResultsSet)5 Iterator (java.util.Iterator)3 Region (org.apache.geode.cache.Region)3 Portfolio (org.apache.geode.cache.query.data.Portfolio)2 HashSet (java.util.HashSet)1 NoSuchElementException (java.util.NoSuchElementException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)1 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)1 QueryException (org.apache.geode.cache.query.QueryException)1 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)1 SelectResults (org.apache.geode.cache.query.SelectResults)1 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)1 Bag (org.apache.geode.cache.query.internal.Bag)1 CompiledSelect (org.apache.geode.cache.query.internal.CompiledSelect)1 QRegion (org.apache.geode.cache.query.internal.QRegion)1 ResultsBag (org.apache.geode.cache.query.internal.ResultsBag)1 ResultsCollectionWrapper (org.apache.geode.cache.query.internal.ResultsCollectionWrapper)1 ObjectTypeImpl (org.apache.geode.cache.query.internal.types.ObjectTypeImpl)1 ObjectType (org.apache.geode.cache.query.types.ObjectType)1