@error_handler
def explain_query(request):
  response = {'status': -1, 'message': ''}

  if request.method != 'POST':
    response['message'] = _('A POST request is required.')
  
  app_name = get_app_name(request)
  query_type = beeswax_models.SavedQuery.TYPES_MAPPING[app_name]

  try:
    form = get_query_form(request)

    if form.is_valid():
      query = SQLdesign(form, query_type=query_type)
      query_server = dbms.get_query_server_config(request.POST.get('server'))
      db = dbms.get(request.user, query_server)

      try:
        db.use(form.cleaned_data['database'])
        datatable = db.explain(query)
        results = db.client.create_result(datatable)

        response['status'] = 0
        response['results'] = results_to_dict(results)
      except Exception, e:
        response['status'] = -1
        response['message'] = str(e)

    else:
      response['message'] = _('There was an error with your query.')
      response['errors'] = form.errors
  except __HOLE__, e:
    response['message']= str(e)

  return JsonResponse(response)
dataset/ETHPy150Open cloudera/hue/apps/rdbms/src/rdbms/api.py/explain_query