class CompiledComparison extends AbstractCompiledValue implements Negatable, OQLLexerTokenTypes, Indexable {

  @Override
  public Object evaluate(ExecutionContext context) throws FunctionDomainException,
      TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    Object left = _left.evaluate(context);
    Object right = _right.evaluate(context);

    if (context.isCqQueryContext() && left instanceof Region.Entry) {
      try {
        left = ((Region.Entry<?, ?>) left).getValue();
      } catch (EntryDestroyedException ex) {
        left = null;
      }
    }
    if (context.isCqQueryContext() && right instanceof Region.Entry) {
      try {
        right = ((Region.Entry<?, ?>) right).getValue();
      } catch (EntryDestroyedException ex) {
        right = null;
      }
    }

    if (left == null || right == null) {
      return TypeUtils.compare(left, right, _operator);
    }

    // if read-serialized is not set, deserialize the pdx instance for comparison
    // only if it is of the same class as that of the object being compared
    if (!context.getCache().getPdxReadSerialized()) {
      if (left instanceof PdxInstance && !(right instanceof PdxInstance)
          && ((PdxInstance) left).getClassName().equals(right.getClass().getName())) {
        left = ((PdxInstance) left).getObject();
      } else if (right instanceof PdxInstance && !(left instanceof PdxInstance)
          && ((PdxInstance) right).getClassName().equals(left.getClass().getName())) {
        right = ((PdxInstance) right).getObject();
      }
    }

    if (left instanceof PdxString) {
      if (right instanceof String) {
        switch (_right.getType()) {
          case LITERAL:
            right = ((CompiledLiteral) _right).getSavedPdxString();
            break;
          case QUERY_PARAM:
            right = ((CompiledBindArgument) _right).getSavedPdxString(context);
            break;
          case FUNCTION:
          case PATH:
            right = new PdxString((String) right);
        }
      }
    } else if (right instanceof PdxString) {
      switch (_left.getType()) {
        case LITERAL:
          left = ((CompiledLiteral) _left).getSavedPdxString();
          break;
        case QUERY_PARAM:
          left = ((CompiledBindArgument) _left).getSavedPdxString(context);
          break;
        case FUNCTION:
        case PATH:
          left = new PdxString((String) left);
      }
    }
    return TypeUtils.compare(left, right, _operator);
  }

    CompiledComparison(CompiledValue left, CompiledValue right, int op);

}