private OrganizedOperands organizeOperandsForAndJunction(ExecutionContext context)
      throws FunctionDomainException, TypeMismatchException,
      NameResolutionException, QueryInvocationTargetException {
    List evalOperands = new ArrayList(_operands.length);
    int evalCount = 0;
    int lessCondnOp = -1;
    int greaterCondnOp = -1;
    CompiledComparison lessCondnOperand = null;
    CompiledComparison greaterCondnOperand = null;
    CompiledComparison equalCondnOperand = null;
    Object equalCondKey = null;
    Object lessCondnKey = null;
    Object greaterCondnKey = null;
    boolean emptyResults = false;
    Set notEqualTypeKeys = null;
    boolean possibleRangeFilter = false;
    IndexInfo indxInfo = null;
    for (CompiledValue operand : _operands) {
      if (operand.getPlanInfo(context).evalAsFilter) {
        Indexable cc = (Indexable) operand;
        if (indxInfo == null) {
          indxInfo = cc.getIndexInfo(context)[0];
        }
        // TODO: Asif :Try to ensure that a CompiledUndefined never
        // goes in the RangeJunction. That means modify the
        // CompiledJunction code to avoid CompiledUndefined's inclusion
        // That way we can ensure that CompiledComparison only become part
        // of RangeJunction
        if (!cc.isRangeEvaluatable()) {
          evalCount++;
          evalOperands.add(0, operand);
          continue;
        }
        CompiledValue ccKey = ((CompiledComparison) cc).getKey(context);
        Object evaluatedCCKey = ccKey.evaluate(context);
        int operator = ((CompiledComparison) cc).reflectOnOperator(ccKey);
        if (evaluatedCCKey == null) {
          evalCount++;
          evalOperands.add(0, operand);
          continue;
        }
        if (equalCondnOperand != null) {
          emptyResults = !isConditionSatisfied(equalCondKey, evaluatedCCKey, operator);
          if (emptyResults) {
            break;
          } else {
            continue;
          }
        }

        switch (operator) {
          case TOK_EQ:
            possibleRangeFilter = false;
            equalCondnOperand = (CompiledComparison) cc;
            equalCondKey = evaluatedCCKey;
            break;
          case TOK_NE:
          case TOK_NE_ALT:
            possibleRangeFilter = true;
            if (notEqualTypeKeys == null) {
              notEqualTypeKeys = new HashSet(_operands.length);
            }
            evaluatedCCKey = TypeUtils.indexKeyFor(evaluatedCCKey);
            notEqualTypeKeys.add(evaluatedCCKey);
            break;
          case TOK_GE:
          case TOK_GT:
            possibleRangeFilter = true;
            if (greaterCondnOperand == null) {
              greaterCondnOperand = (CompiledComparison) cc;
              greaterCondnKey = evaluatedCCKey;
              greaterCondnOp = operator;
            } else {
              if (isConditionSatisfied(evaluatedCCKey, greaterCondnKey, greaterCondnOp)) {
                greaterCondnKey = evaluatedCCKey;
                greaterCondnOperand = (CompiledComparison) cc;
                greaterCondnOp = operator;
              }
            }
            break;
          case TOK_LE:
          case TOK_LT:
            // Asif: if there exists a previous equal Operand & current
            // condition's value is greater than the equal operand's value, it
            // will be empty results
            possibleRangeFilter = true;
            if (lessCondnOperand == null) {
              lessCondnOperand = (CompiledComparison) cc;
              lessCondnKey = evaluatedCCKey;
              lessCondnOp = operator;
            } else {
              if (isConditionSatisfied(evaluatedCCKey, lessCondnKey, lessCondnOp)) {
                lessCondnKey = evaluatedCCKey;
                lessCondnOperand = (CompiledComparison) cc;
                lessCondnOp = operator;
              }
            }
            break;
        }

      } else if (!operand.isDependentOnCurrentScope(context)) {
        // TODO: Asif :Remove this Assert & else if condition after successful
        // testing of the build
        Support.assertionFailed(
            "An independentoperand should not ever be present as operand inside a GroupJunction as it should always be present only in CompiledJunction");
      } else {
        evalOperands.add(operand);
      }
    }
    if (!emptyResults) {
      Filter filter = null;
      if (equalCondnOperand != null) {
        // Check if any of the preceding inequality operands, that have not been
        // checked against the equality operand , are not able to satisfy the
        // equality.
        if (lessCondnOperand != null
            && !isConditionSatisfied(equalCondKey, lessCondnKey, lessCondnOp)) {
          emptyResults = true;
        } else if (greaterCondnOperand != null
            && !isConditionSatisfied(equalCondKey, greaterCondnKey, greaterCondnOp)) {
          emptyResults = true;
        } else if (notEqualTypeKeys != null) {
          Iterator itr = notEqualTypeKeys.iterator();
          while (itr.hasNext() && !emptyResults) {
            emptyResults =
                !isConditionSatisfied(equalCondKey, itr.next(), OQLLexerTokenTypes.TOK_NE);
          }
        }
        if (!emptyResults) {
          filter = equalCondnOperand;
        }
      } else if (possibleRangeFilter) {
        if (lessCondnOperand != null && greaterCondnOperand != null) {
          emptyResults = !checkForRangeBoundednessAndTrimNotEqualKeyset(notEqualTypeKeys,
              lessCondnKey, lessCondnOp, greaterCondnKey, greaterCondnOp);
          if (!emptyResults) {
            filter = new DoubleCondnRangeJunctionEvaluator(lessCondnOp, lessCondnKey,
                greaterCondnOp, greaterCondnKey,
                (notEqualTypeKeys == null || notEqualTypeKeys.isEmpty()) ? null : notEqualTypeKeys,
                indxInfo);
          }
        } else if (greaterCondnOperand != null) {
          filter = generateSingleCondnEvaluatorIfRequired(notEqualTypeKeys, greaterCondnOperand,
              greaterCondnOp, greaterCondnKey, indxInfo);
        } else if (lessCondnOperand != null) {
          filter = generateSingleCondnEvaluatorIfRequired(notEqualTypeKeys, lessCondnOperand,
              lessCondnOp, lessCondnKey, indxInfo);
        } else {
          assert notEqualTypeKeys != null && !notEqualTypeKeys.isEmpty();
          // TODO:Asif Ideally if there is a single NotEqualKey we should
          // not create NotEqualCondnEvaluator instead just add the
          // CompiledComparison
          // operand to the eval operands list. But since we do retain the
          // operand
          // correponding to the NotEqualKey in this function , we are creating
          // the NotEqualCondnEvaluator
          filter = new NotEqualConditionEvaluator(notEqualTypeKeys, indxInfo);
        }

      }
      if (emptyResults) {
        evalOperands.clear();
        evalCount = 1;
        evalOperands.add(new CompiledLiteral(Boolean.FALSE));
      } else if (filter != null) {
        evalCount++;
        evalOperands.add(0, filter);
      }
    } else {
      // Asif: Create a new CompiledLiteral with boolean false
      evalOperands.clear();
      evalCount = 1;
      evalOperands.add(new CompiledLiteral(Boolean.FALSE));
    }

    // If no hints were provided, we continue with our single index solution
    if (!(context instanceof QueryExecutionContext)
        || !((QueryExecutionContext) context).hasMultiHints()) {
      // At the end check if the unevaluatedIterOperand
      // are null or not. This could be the case only if at top level
      // GroupJunction is formed having multiple RangeJunctions & other
      // iter operands & then only one RangeJunction is treated as filter
      // rest all as iter operands. In that case , the only iter operand is
      // that which is added externally to RangeJunction. If the top
      // level was a RangeJunction then the iter operands would have been
      // part of it at the time of creation of RangeJunction & we would not have
      // to add it externally.
      if (getIterOperands() != null) {
        // Commented the assert for CompiledLike which creates 2 or 3 CompiledComparisons
        // for the same operand. The protGetPlanInfo in CompiledLike could return evalAsFilter
        // as true the first time and false the next time for the same operand.
        // Hence the evalOperands could contain CompiledComparisons more than number of indexes.

        // Support.Assert(evalOperands.size() == evalCount);
        evalOperands.add(getIterOperands());
      }
    }
    return createOrganizedOperandsObject(evalCount, evalOperands);

  }
For the filter evaluatable conditions , it creates the appropriate JunctionEvaluator (
NotEqualConditionEvaluator or SingleCondnEvaluator or DoubleCondnRangeJunctionEvaluator ). The
junction Evaluator itself is filter evaluatable. The operands which are of type != null , ==
null , != undefined, == undefined are left as it is & are not combined into a Junction
Evaluator. Thus the organized operand of RangeJunction may created atmost one Condition
Evaluator, will retain the operands containing null ,undefined conditions. In case there is a
equality condition , then it may result in a filter having just that condition assuming other
conditions satisfy the equality. In case it turns out that the conditions are mutually
exclusive then the organized operand would just contain a single filter evaluatable
CompiledLiteral (false) ( indicating empty resultset).
geode-core/src/main/java/org/apache/geode/cache/query/internal/RangeJunction.java