use of org.apache.geode.cache.query.internal.CompiledSortCriterion in project geode by apache.
the class CompactRangeIndex method evaluate.
private void evaluate(Object key, int operator, Collection results, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, Set keysToRemove, List projAttrib, SelectResults intermediateResults, boolean isIntersection, int limit, boolean applyOrderBy, List orderByAttribs) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
boolean multiColOrderBy = false;
if (keysToRemove == null) {
keysToRemove = new HashSet(0);
}
key = TypeUtils.indexKeyFor(key);
if (key == null) {
key = IndexManager.NULL;
}
boolean asc = true;
if (applyOrderBy) {
CompiledSortCriterion csc = (CompiledSortCriterion) orderByAttribs.get(0);
asc = !csc.getCriterion();
multiColOrderBy = orderByAttribs.size() > 1;
}
CloseableIterator<IndexStoreEntry> iterator = null;
try {
switch(operator) {
case OQLLexerTokenTypes.TOK_EQ:
assert keysToRemove.isEmpty();
iterator = indexStore.get(key);
addToResultsFromEntries(key, operator, iterator, results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
break;
case OQLLexerTokenTypes.TOK_LT:
{
if (asc) {
iterator = indexStore.iterator(null, true, key, false, keysToRemove);
} else {
iterator = indexStore.descendingIterator(null, true, key, false, keysToRemove);
}
addToResultsFromEntries(key, operator, iterator, results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
}
break;
case OQLLexerTokenTypes.TOK_LE:
{
if (asc) {
iterator = indexStore.iterator(null, true, key, true, keysToRemove);
} else {
iterator = indexStore.descendingIterator(null, true, key, true, keysToRemove);
}
addToResultsFromEntries(key, operator, iterator, results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
}
break;
case OQLLexerTokenTypes.TOK_GT:
{
if (asc) {
iterator = indexStore.iterator(key, false, keysToRemove);
} else {
iterator = indexStore.descendingIterator(key, false, keysToRemove);
}
addToResultsFromEntries(key, operator, iterator, results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
}
break;
case OQLLexerTokenTypes.TOK_GE:
{
if (asc) {
iterator = indexStore.iterator(key, true, keysToRemove);
} else {
iterator = indexStore.descendingIterator(key, true, keysToRemove);
}
addToResultsFromEntries(key, operator, iterator, results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
}
break;
case OQLLexerTokenTypes.TOK_NE_ALT:
case OQLLexerTokenTypes.TOK_NE:
{
keysToRemove.add(key);
if (asc) {
iterator = indexStore.iterator(keysToRemove);
} else {
iterator = indexStore.descendingIterator(keysToRemove);
}
addToResultsFromEntries(key, operator, iterator, results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
// If the key is not null, then add the nulls to the results as this is a not equals query
if (!IndexManager.NULL.equals(key)) {
// we pass in the operator TOK_EQ because we want to add results where the key is equal
// to NULL
addToResultsFromEntries(IndexManager.NULL, OQLLexerTokenTypes.TOK_EQ, indexStore.get(IndexManager.NULL), results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
}
// equals query
if (!QueryService.UNDEFINED.equals(key)) {
// we pass in the operator TOK_EQ because we want to add results where the key is equal
// to UNDEFINED
addToResultsFromEntries(QueryService.UNDEFINED, OQLLexerTokenTypes.TOK_EQ, indexStore.get(QueryService.UNDEFINED), results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
}
}
break;
default:
throw new AssertionError("Operator = " + operator);
}
// end switch
} catch (ClassCastException ex) {
if (operator == OQLLexerTokenTypes.TOK_EQ) {
// result is empty set
return;
} else if (operator == OQLLexerTokenTypes.TOK_NE || operator == OQLLexerTokenTypes.TOK_NE_ALT) {
// put all in result
keysToRemove.add(key);
try {
if (asc) {
iterator = indexStore.iterator(keysToRemove);
} else {
iterator = indexStore.descendingIterator(keysToRemove);
}
addToResultsFromEntries(key, OQLLexerTokenTypes.TOK_NE, iterator, results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
} finally {
if (iterator != null) {
iterator.close();
}
}
} else {
// otherwise throw exception
throw new TypeMismatchException("", ex);
}
} finally {
if (iterator != null) {
iterator.close();
}
}
}
use of org.apache.geode.cache.query.internal.CompiledSortCriterion in project geode by apache.
the class CompactRangeIndex method lockedQuery.
/** Method called while appropriate lock held on index */
void lockedQuery(Object lowerBoundKey, int lowerBoundOperator, Object upperBoundKey, int upperBoundOperator, Collection results, Set keysToRemove, ExecutionContext context) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
lowerBoundKey = TypeUtils.indexKeyFor(lowerBoundKey);
upperBoundKey = TypeUtils.indexKeyFor(upperBoundKey);
boolean lowerBoundInclusive = lowerBoundOperator == OQLLexerTokenTypes.TOK_GE;
boolean upperBoundInclusive = upperBoundOperator == OQLLexerTokenTypes.TOK_LE;
// LowerBound Key inclusive , Upper bound key exclusive
int limit = -1;
Boolean applyLimit = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_LIMIT_AT_INDEX);
if (applyLimit != null && applyLimit) {
limit = (Integer) context.cacheGet(CompiledValue.RESULT_LIMIT);
}
Boolean orderByClause = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_ORDER_BY_AT_INDEX);
List orderByAttrs;
boolean asc = true;
boolean multiColOrderBy = false;
if (orderByClause != null && orderByClause) {
orderByAttrs = (List) context.cacheGet(CompiledValue.ORDERBY_ATTRIB);
CompiledSortCriterion csc = (CompiledSortCriterion) orderByAttrs.get(0);
asc = !csc.getCriterion();
multiColOrderBy = orderByAttrs.size() > 1;
}
// return if the index map is still empty at this stage
if (isEmpty()) {
return;
}
lowerBoundKey = getPdxStringForIndexedPdxKeys(lowerBoundKey);
upperBoundKey = getPdxStringForIndexedPdxKeys(upperBoundKey);
if (keysToRemove == null) {
keysToRemove = new HashSet();
}
CloseableIterator<IndexStoreEntry> iterator = null;
try {
if (asc) {
iterator = indexStore.iterator(lowerBoundKey, lowerBoundInclusive, upperBoundKey, upperBoundInclusive, keysToRemove);
} else {
iterator = indexStore.descendingIterator(lowerBoundKey, lowerBoundInclusive, upperBoundKey, upperBoundInclusive, keysToRemove);
}
addToResultsFromEntries(lowerBoundKey, upperBoundKey, lowerBoundOperator, upperBoundOperator, iterator, results, null, null, context, null, null, true, multiColOrderBy ? -1 : limit);
} finally {
if (iterator != null) {
iterator.close();
}
}
}
use of org.apache.geode.cache.query.internal.CompiledSortCriterion in project geode by apache.
the class HashIndex method evaluate.
private void evaluate(Object key, int operator, Collection results, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, Set keysToRemove, List projAttrib, SelectResults intermediateResults, boolean isIntersection, int limit, boolean applyOrderBy, List orderByAttribs) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
boolean multiColOrderBy = false;
if (keysToRemove == null) {
keysToRemove = new HashSet(0);
}
key = TypeUtils.indexKeyFor(key);
if (key == null) {
key = IndexManager.NULL;
}
boolean asc = true;
if (applyOrderBy) {
CompiledSortCriterion csc = (CompiledSortCriterion) orderByAttribs.get(0);
asc = !csc.getCriterion();
multiColOrderBy = orderByAttribs.size() > 1;
}
try {
long iteratorCreationTime = GemFireCacheImpl.getInstance().cacheTimeMillis();
switch(operator) {
case OQLLexerTokenTypes.TOK_EQ:
assert keysToRemove.isEmpty();
addToResultsFromEntries(this.entriesSet.get(key), results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit, keysToRemove, applyOrderBy, asc, iteratorCreationTime);
break;
case OQLLexerTokenTypes.TOK_NE_ALT:
case OQLLexerTokenTypes.TOK_NE:
{
keysToRemove.add(key);
addToResultsFromEntries(this.entriesSet.getAllNotMatching(keysToRemove), results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit, keysToRemove, applyOrderBy, asc, iteratorCreationTime);
}
break;
default:
throw new AssertionError("Operator = " + operator);
}
// end switch
} catch (ClassCastException ex) {
if (operator == OQLLexerTokenTypes.TOK_EQ) {
// set
return;
} else if (operator == OQLLexerTokenTypes.TOK_NE || operator == OQLLexerTokenTypes.TOK_NE_ALT) {
// put
keysToRemove.add(key);
long iteratorCreationTime = GemFireCacheImpl.getInstance().cacheTimeMillis();
addToResultsFromEntries(this.entriesSet.getAllNotMatching(keysToRemove), results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit, keysToRemove, applyOrderBy, asc, iteratorCreationTime);
} else {
// otherwise throw exception
throw new TypeMismatchException("", ex);
}
}
}
use of org.apache.geode.cache.query.internal.CompiledSortCriterion in project geode by apache.
the class HashIndex method lockedQueryPrivate.
/** Method called while appropriate lock held on index */
private void lockedQueryPrivate(Object key, int operator, Collection results, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, Set keysToRemove, List projAttrib, SelectResults intermediateResults, boolean isIntersection) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
if (keysToRemove == null) {
keysToRemove = new HashSet(0);
}
int limit = -1;
Boolean applyLimit = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_LIMIT_AT_INDEX);
if (applyLimit != null && applyLimit) {
limit = (Integer) context.cacheGet(CompiledValue.RESULT_LIMIT);
}
Boolean orderByClause = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_ORDER_BY_AT_INDEX);
boolean applyOrderBy = false;
List orderByAttrs = null;
if (orderByClause != null && orderByClause) {
orderByAttrs = (List) context.cacheGet(CompiledValue.ORDERBY_ATTRIB);
CompiledSortCriterion csc = (CompiledSortCriterion) orderByAttrs.get(0);
applyOrderBy = true;
}
evaluate(key, operator, results, iterOps, runtimeItr, context, keysToRemove, projAttrib, intermediateResults, isIntersection, limit, applyOrderBy, orderByAttrs);
}
use of org.apache.geode.cache.query.internal.CompiledSortCriterion in project geode by apache.
the class RangeIndex method lockedQuery.
void lockedQuery(Object key, int operator, Collection results, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, List projAttrib, SelectResults intermediateResults, boolean isIntersection) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
int limit = -1;
Boolean applyLimit = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_LIMIT_AT_INDEX);
if (applyLimit != null && applyLimit) {
limit = (Integer) context.cacheGet(CompiledValue.RESULT_LIMIT);
}
Boolean orderByClause = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_ORDER_BY_AT_INDEX);
boolean multiColOrderBy = false;
List orderByAttrs = null;
boolean asc = true;
boolean applyOrderBy = false;
if (orderByClause != null && orderByClause) {
orderByAttrs = (List) context.cacheGet(CompiledValue.ORDERBY_ATTRIB);
CompiledSortCriterion csc = (CompiledSortCriterion) orderByAttrs.get(0);
asc = !csc.getCriterion();
multiColOrderBy = orderByAttrs.size() > 1;
applyOrderBy = true;
}
if (key == null) {
switch(operator) {
case OQLLexerTokenTypes.TOK_EQ:
{
nullMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_NE_ALT:
case OQLLexerTokenTypes.TOK_NE:
{
// add all btree values
NavigableMap sm = this.valueToEntriesMap;
if (!asc) {
sm = sm.descendingMap();
}
// keysToRemove should be null, meaning we aren't removing any keys
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
undefinedMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
default:
{
throw new IllegalArgumentException("Invalid Operator");
}
}
// end switch
} else if (key == QueryService.UNDEFINED) {
// do nothing
switch(operator) {
case OQLLexerTokenTypes.TOK_EQ:
{
undefinedMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_NE:
case OQLLexerTokenTypes.TOK_NE_ALT:
{
// add all btree values
NavigableMap sm = this.valueToEntriesMap;
if (!asc) {
sm = sm.descendingMap();
}
// keysToRemove should be null
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, multiColOrderBy ? -1 : limit);
nullMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
default:
{
throw new IllegalArgumentException("Invalid Operator");
}
}
// end switch
} else {
// return if the index map is still empty at this stage
if (isEmpty()) {
return;
}
key = getPdxStringForIndexedPdxKeys(key);
evaluate(key, operator, results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit, applyOrderBy, orderByAttrs);
}
// end else
}
Aggregations