use of org.apache.geode.cache.query.internal.CqEntry in project geode by apache.
the class CompactRangeIndex method addToResultsFromEntries.
/*
*
* @param lowerBoundKey the index key to match on for a lower bound on a ranged query, otherwise
* the key to match on
*
* @param upperBoundKey the index key to match on for an upper bound on a ranged query, otherwise
* null
*
* @param lowerBoundOperator the operator to use to determine a match against the lower bound
*
* @param upperBoundOperator the operator to use to determine a match against the upper bound
*/
private void addToResultsFromEntries(Object lowerBoundKey, Object upperBoundKey, int lowerBoundOperator, int upperBoundOperator, CloseableIterator<IndexStoreEntry> entriesIter, Collection result, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, List projAttrib, SelectResults intermediateResults, boolean isIntersection, int limit) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
QueryObserver observer = QueryObserverHolder.getInstance();
boolean limitApplied = false;
if (entriesIter == null || (limitApplied = verifyLimit(result, limit))) {
if (limitApplied) {
if (observer != null) {
observer.limitAppliedAtIndexLevel(this, limit, result);
}
}
return;
}
Set seenKey = null;
if (IndexManager.IS_TEST_EXPANSION) {
seenKey = new HashSet();
}
while (entriesIter.hasNext()) {
try {
// Check if query execution on this thread is canceled.
QueryMonitor.isQueryExecutionCanceled();
if (IndexManager.testHook != null) {
if (this.region.getCache().getLogger().fineEnabled()) {
this.region.getCache().getLogger().fine("IndexManager TestHook is set in addToResultsFromEntries.");
}
IndexManager.testHook.hook(11);
}
IndexStoreEntry indexEntry = null;
try {
indexEntry = entriesIter.next();
} catch (NoSuchElementException ignore) {
// Continue from while.
continue;
}
Object value = indexEntry.getDeserializedValue();
if (IndexManager.IS_TEST_EXPANSION) {
Object rk = indexEntry.getDeserializedRegionKey();
if (seenKey.contains(rk)) {
continue;
}
seenKey.add(rk);
List expandedResults = expandValue(context, lowerBoundKey, upperBoundKey, lowerBoundOperator, upperBoundOperator, value);
Iterator iterator = ((Collection) expandedResults).iterator();
while (iterator.hasNext()) {
value = iterator.next();
if (value != null) {
boolean ok = true;
if (runtimeItr != null) {
runtimeItr.setCurrent(value);
}
if (ok && runtimeItr != null && iterOps != null) {
ok = QueryUtils.applyCondition(iterOps, context);
}
if (ok) {
if (context != null && context.isCqQueryContext()) {
result.add(new CqEntry(indexEntry.getDeserializedRegionKey(), value));
} else {
applyProjection(projAttrib, context, result, value, intermediateResults, isIntersection);
}
if (verifyLimit(result, limit)) {
observer.limitAppliedAtIndexLevel(this, limit, result);
return;
}
}
}
}
} else {
if (value != null) {
boolean ok = true;
if (indexEntry.isUpdateInProgress() || TEST_ALWAYS_UPDATE_IN_PROGRESS) {
IndexInfo indexInfo = (IndexInfo) context.cacheGet(CompiledValue.INDEX_INFO);
if (runtimeItr == null) {
runtimeItr = getRuntimeIteratorForThisIndex(context, indexInfo);
if (runtimeItr == null) {
// could not match index with iterator
throw new QueryInvocationTargetException("Query alias's must be used consistently");
}
}
runtimeItr.setCurrent(value);
// Verify index key in region entry value.
ok = evaluateEntry((IndexInfo) indexInfo, context, null);
}
if (runtimeItr != null) {
runtimeItr.setCurrent(value);
}
if (ok && runtimeItr != null && iterOps != null) {
ok = QueryUtils.applyCondition(iterOps, context);
}
if (ok) {
if (context != null && context.isCqQueryContext()) {
result.add(new CqEntry(indexEntry.getDeserializedRegionKey(), value));
} else {
if (IndexManager.testHook != null) {
IndexManager.testHook.hook(200);
}
applyProjection(projAttrib, context, result, value, intermediateResults, isIntersection);
}
if (verifyLimit(result, limit)) {
observer.limitAppliedAtIndexLevel(this, limit, result);
return;
}
}
}
}
} catch (ClassCastException | EntryDestroyedException ignore) {
// ignore it
}
}
}
use of org.apache.geode.cache.query.internal.CqEntry in project geode by apache.
the class HashIndex method addValueToResultSet.
private void addValueToResultSet(RegionEntry re, Collection result, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, List projAttrib, SelectResults intermediateResults, boolean isIntersection, int limit, QueryObserver observer, long iteratorCreationTime) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
Object value = getTargetObject(re);
if (value != null) {
boolean ok = true;
// we will reevaluate to be sure the value still matches the key
if (re.isUpdateInProgress() || IndexManager.needsRecalculation(iteratorCreationTime, re.getLastModified())) {
IndexInfo indexInfo = (IndexInfo) context.cacheGet(CompiledValue.INDEX_INFO);
if (runtimeItr == null) {
runtimeItr = getRuntimeIteratorForThisIndex(context, indexInfo);
if (runtimeItr == null) {
// could not match index with iterator
throw new QueryInvocationTargetException("Query alias's must be used consistently");
}
}
runtimeItr.setCurrent(value);
// Verify index key in region entry value.
ok = evaluateEntry(indexInfo, context, null);
}
if (runtimeItr != null) {
runtimeItr.setCurrent(value);
}
if (ok && runtimeItr != null && iterOps != null) {
ok = QueryUtils.applyCondition(iterOps, context);
}
if (ok) {
if (context != null && context.isCqQueryContext()) {
result.add(new CqEntry(re.getKey(), value));
} else {
applyProjection(projAttrib, context, result, value, intermediateResults, isIntersection);
}
if (limit != -1 && result.size() == limit) {
observer.limitAppliedAtIndexLevel(this, limit, result);
return;
}
}
}
}
use of org.apache.geode.cache.query.internal.CqEntry in project geode by apache.
the class BaseCommandQuery method sendResultsAsObjectArray.
private void sendResultsAsObjectArray(SelectResults selectResults, int numberOfChunks, ServerConnection servConn, boolean isStructs, CollectionType collectionType, String queryString, ServerCQ cqQuery, boolean sendCqResultsWithKey, boolean sendResults) throws IOException {
int resultIndex = 0;
// For CQ only as we dont want CQEntries which have null values.
int cqResultIndex = 0;
Object[] objs = selectResults.toArray();
for (int j = 0; j < numberOfChunks; j++) {
boolean incompleteArray = false;
if (logger.isTraceEnabled()) {
logger.trace("{}: Creating chunk: {}", servConn.getName(), j);
}
Object[] results = new Object[MAXIMUM_CHUNK_SIZE];
for (int i = 0; i < MAXIMUM_CHUNK_SIZE; i++) {
if ((resultIndex) == selectResults.size()) {
incompleteArray = true;
break;
}
if (logger.isTraceEnabled()) {
logger.trace("{}: Adding entry [{}] to query results: {}", servConn.getName(), resultIndex, objs[resultIndex]);
}
if (cqQuery != null) {
CqEntry e = (CqEntry) objs[resultIndex];
// The value may have become null because of entry invalidation.
if (e.getValue() == null) {
resultIndex++;
// i will get incremented anyway so we need to decrement it back so
// that results[i] is not null.
i--;
continue;
}
// need to update the Results cache.
if (!cqQuery.isPR()) {
cqQuery.addToCqResultKeys(e.getKey());
}
// Add to the Results object array.
if (sendCqResultsWithKey) {
results[i] = e.getKeyValuePair();
} else {
results[i] = e.getValue();
}
} else {
// instance check added to fix bug 40516.
if (isStructs && (objs[resultIndex] instanceof Struct)) {
results[i] = ((Struct) objs[resultIndex]).getFieldValues();
} else {
results[i] = objs[resultIndex];
}
}
resultIndex++;
cqResultIndex++;
}
// number of entries in the result set.
if (incompleteArray) {
Object[] newResults;
if (cqQuery != null) {
newResults = new Object[cqResultIndex % MAXIMUM_CHUNK_SIZE];
} else {
newResults = new Object[resultIndex % MAXIMUM_CHUNK_SIZE];
}
for (int i = 0; i < newResults.length; i++) {
newResults[i] = results[i];
}
results = newResults;
}
if (sendResults) {
writeQueryResponseChunk(results, collectionType, (resultIndex == selectResults.size()), servConn);
if (logger.isDebugEnabled()) {
logger.debug("{}: Sent chunk ({} of {}) of query response for query: {}", servConn.getName(), (j + 1), numberOfChunks, queryString);
}
}
// break out of loop here only.
if (resultIndex == selectResults.size()) {
break;
}
}
}
use of org.apache.geode.cache.query.internal.CqEntry in project geode by apache.
the class BaseCommandQuery method sendResultsAsObjectPartList.
private void sendResultsAsObjectPartList(int numberOfChunks, ServerConnection servConn, List objs, boolean isStructs, CollectionType collectionType, String queryString, ServerCQ cqQuery, boolean sendCqResultsWithKey, boolean sendResults) throws IOException {
int resultIndex = 0;
Object result = null;
for (int j = 0; j < numberOfChunks; j++) {
if (logger.isTraceEnabled()) {
logger.trace("{}: Creating chunk: {}", servConn.getName(), j);
}
ObjectPartList serializedObjs = new ObjectPartList(MAXIMUM_CHUNK_SIZE, false);
for (int i = 0; i < MAXIMUM_CHUNK_SIZE; i++) {
if ((resultIndex) == objs.size()) {
break;
}
if (logger.isTraceEnabled()) {
logger.trace("{}: Adding entry [{}] to query results: {}", servConn.getName(), resultIndex, objs.get(resultIndex));
}
if (cqQuery != null) {
CqEntry e = (CqEntry) objs.get(resultIndex);
// The value may have become null because of entry invalidation.
if (e.getValue() == null) {
resultIndex++;
continue;
}
// need to update the Results cache.
if (!cqQuery.isPR()) {
cqQuery.addToCqResultKeys(e.getKey());
}
// Add to the Results object array.
if (sendCqResultsWithKey) {
result = e.getKeyValuePair();
} else {
result = e.getValue();
}
} else {
result = objs.get(resultIndex);
}
if (sendResults) {
addToObjectPartList(serializedObjs, result, collectionType, false, servConn, isStructs);
}
resultIndex++;
}
if (sendResults) {
writeQueryResponseChunk(serializedObjs, collectionType, ((j + 1) == numberOfChunks), servConn);
if (logger.isDebugEnabled()) {
logger.debug("{}: Sent chunk ({} of {}) of query response for query: {}", servConn.getName(), (j + 1), numberOfChunks, queryString);
}
}
}
}
Aggregations