当前位置: 首页>>代码示例>>Python>>正文


Python design.HQLdesign类代码示例

本文整理汇总了Python中beeswax.design.HQLdesign的典型用法代码示例。如果您正苦于以下问题:Python HQLdesign类的具体用法?Python HQLdesign怎么用?Python HQLdesign使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HQLdesign类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _run_parameterized_query

def _run_parameterized_query(request, design_id, explain):
    """
  Given a design and arguments to parameterize that design, runs the query.
  - explain is a boolean to determine whether to run as an explain or as an
  execute.

  This is an extra "step" in the flow from execute_query.
  """
    design = authorized_get_design(request, design_id, must_exist=True)

    # Reconstitute the form
    design_obj = beeswax.design.HQLdesign.loads(design.data)
    query_form = QueryForm()
    params = design_obj.get_query_dict()
    params.update(request.POST)

    databases = _get_db_choices(request)
    query_form.bind(params)
    query_form.query.fields["database"].choices = databases  # Could not do it in the form

    if not query_form.is_valid():
        raise PopupException(_("Query form is invalid: %s") % query_form.errors)

    query_str = query_form.query.cleaned_data["query"]
    app_name = get_app_name(request)
    query_server = get_query_server_config(app_name)
    query_type = SavedQuery.TYPES_MAPPING[app_name]

    parameterization_form_cls = make_parameterization_form(query_str)
    if not parameterization_form_cls:
        raise PopupException(_("Query is not parameterizable."))

    parameterization_form = parameterization_form_cls(request.REQUEST, prefix="parameterization")

    if parameterization_form.is_valid():
        real_query = substitute_variables(query_str, parameterization_form.cleaned_data)
        query = HQLdesign(query_form, query_type=query_type)
        query._data_dict["query"]["query"] = real_query
        try:
            if explain:
                return explain_directly(request, query, design, query_server)
            else:
                return execute_directly(request, query, query_server, design)
        except Exception, ex:
            db = dbms.get(request.user, query_server)
            error_message, log = expand_exception(ex, db)
            return render(
                "execute.mako",
                request,
                {
                    "action": reverse(get_app_name(request) + ":execute_query"),
                    "design": design,
                    "error_message": error_message,
                    "form": query_form,
                    "log": log,
                    "autocomplete_base_url": reverse(get_app_name(request) + ":autocomplete", kwargs={}),
                },
            )
开发者ID:jriv96,项目名称:hue,代码行数:58,代码来源:views.py

示例2: execute

def execute(request, design_id=None):
  response = {'status': -1, 'message': ''}

  if request.method != 'POST':
    response['message'] = _('A POST request is required.')

  app_name = get_app_name(request)
  query_server = get_query_server_config(app_name)
  query_type = beeswax.models.SavedQuery.TYPES_MAPPING[app_name]
  design = safe_get_design(request, query_type, design_id)

  try:
    query_form = get_query_form(request)

    if query_form.is_valid():
      query_str = query_form.query.cleaned_data["query"]
      explain = request.GET.get('explain', 'false').lower() == 'true'
      design = save_design(request, query_form, query_type, design, False)

      if query_form.query.cleaned_data['is_parameterized']:
        # Parameterized query
        parameterization_form_cls = make_parameterization_form(query_str)
        if parameterization_form_cls:
          parameterization_form = parameterization_form_cls(request.REQUEST, prefix="parameterization")

          if parameterization_form.is_valid():
            parameters = parameterization_form.cleaned_data
            real_query = substitute_variables(query_str, parameters)
            query = HQLdesign(query_form, query_type=query_type)
            query._data_dict['query']['query'] = real_query

            try:
              if explain:
                return explain_directly(request, query, design, query_server)
              else:
                return execute_directly(request, query, design, query_server, parameters=parameters)

            except Exception, ex:
              db = dbms.get(request.user, query_server)
              error_message, log = expand_exception(ex, db)
              response['message'] = error_message
              return JsonResponse(response)
          else:
            response['errors'] = parameterization_form.errors
            return JsonResponse(response)

      # Non-parameterized query
      query = HQLdesign(query_form, query_type=query_type)
      if request.GET.get('explain', 'false').lower() == 'true':
        return explain_directly(request, query, design, query_server)
      else:
        return execute_directly(request, query, design, query_server)
    else:
开发者ID:HaNeul-Kim,项目名称:hue,代码行数:53,代码来源:api.py

示例3: _run_parameterized_query

def _run_parameterized_query(request, design_id, explain):
  """
  Given a design and arguments to parameterize that design, runs the query.
  - explain is a boolean to determine whether to run as an explain or as an
  execute.

  This is an extra "step" in the flow from execute_query.
  """
  design = authorized_get_design(request, design_id, must_exist=True)

  # Reconstitute the form
  design_obj = beeswax.design.HQLdesign.loads(design.data)
  query_form = QueryForm()
  params = design_obj.get_query_dict()
  params.update(request.POST)
  query_form.bind(params)
  assert query_form.is_valid()

  query_str = query_form.query.cleaned_data["query"]
  query_server = get_query_server_config(get_app_name(request))

  parameterization_form_cls = make_parameterization_form(query_str)
  if not parameterization_form_cls:
    raise PopupException(_("Query is not parameterizable."))

  parameterization_form = parameterization_form_cls(request.REQUEST, prefix="parameterization")

  if parameterization_form.is_valid():
    real_query = substitute_variables(query_str, parameterization_form.cleaned_data)
    query = HQLdesign(query_form)
    query._data_dict['query']['query'] = real_query
    try:
      if explain:
        return explain_directly(request, query, design, query_server)
      else:
        return execute_directly(request, query, query_server, design)
    except Exception, ex:
      db = dbms.get(request.user, query_server)
      error_message, log = expand_exception(ex, db)
      return render('execute.mako', request, {
        'action': reverse(get_app_name(request) + ':execute_query'),
        'design': design,
        'error_message': error_message,
        'form': query_form,
        'log': log,
        'autocomplete': json.dumps({}),
      })
开发者ID:yjkim,项目名称:hue,代码行数:47,代码来源:views.py

示例4: execute_query

def execute_query(request, design_id=None, table=None):
  authorized_get_design(request, design_id)
  error_message, log = None, None
  form = query_form()
  action = request.path
  design = safe_get_design(request, SavedQuery.HQL, design_id)
  on_success_url = request.REQUEST.get('on_success_url')

  for _ in range(1):
    if request.method == 'POST':
      form.bind(request.POST)
      to_explain = request.POST.has_key('button-explain')
      to_submit = request.POST.has_key('button-submit')
      # Always validate the saveform, which will tell us whether it needs explicit saving
      if not form.is_valid():
        break
      to_save = form.saveform.cleaned_data['save']
      to_saveas = form.saveform.cleaned_data['saveas']
      if to_saveas and not design.is_auto:
        # Save As only affects a previously saved query
        design = design.clone()
      if to_submit or to_save or to_saveas or to_explain:
        explicit_save = to_save or to_saveas
        design = save_design(request, form, SavedQuery.HQL, design, explicit_save)
        action = urlresolvers.reverse(execute_query, kwargs=dict(design_id=design.id))

      # We're not going to process the form. Simply re-render it.
      if not to_explain and not to_submit:
        break

      query_str = _strip_trailing_semicolon(form.query.cleaned_data["query"])
      query_server = db_utils.get_query_server(form.query_servers.cleaned_data["server"])
      # (Optional) Parameterization.
      parameterization = get_parameterization(request, query_str, form, design, to_explain)
      if parameterization:
        return parameterization

      query_msg = make_beeswax_query(request, query_str, form)
      try:
        if to_explain:
          return expl_d(request, query_str, query_msg, design, query_server)
        else:
          notify = form.query.cleaned_data.get('email_notify', False)
          return e_d(request, query_msg, design=design,
            on_success_url=on_success_url,
            notify=notify)
      except BeeswaxException, ex:
        error_message, log = expand_exception(ex)
        # Fall through to re-render the execute form.
    else:
      # GET request
      if design.id is not None:
        data = HQLdesign.loads(design.data).get_query_dict()
        form.bind(data)
        form.saveform.set_data(design.name, design.desc)
      else:
        # New design
        form.bind()
开发者ID:DatalakeInc,项目名称:hortonworks-sandbox,代码行数:58,代码来源:views.py

示例5: design_to_dict

def design_to_dict(design):
  hql_design = HQLdesign.loads(design.data)
  return {
    'id': design.id,
    'query': hql_design.hql_query,
    'name': design.name,
    'desc': design.desc,
    'database': hql_design.query.get('database', None),
    'settings': hql_design.settings,
    'file_resources': hql_design.file_resources,
    'functions': hql_design.functions,
    'is_parameterized': hql_design.query.get('is_parameterized', True),
    'email_notify': hql_design.query.get('email_notify', True)
  }
开发者ID:fhferreira,项目名称:hue,代码行数:14,代码来源:api.py

示例6: HQLdesign

        try:
          query = HQLdesign(form)
          if to_explain:
            return explain_directly(request, query, design, query_server)
          else:
            notify = form.query.cleaned_data.get('email_notify', False)
            return execute_directly(request, query, query_server, design, on_success_url=on_success_url, notify=notify)
        except BeeswaxException, ex:
          print ex.errorCode
          print ex.SQLState
          db = dbms.get(request.user, query_server)
          error_message, log = expand_exception(ex, db)
  else:
    if design.id is not None:
      data = HQLdesign.loads(design.data).get_query_dict()
      form.bind(data)
      form.saveform.set_data(design.name, design.desc)
    else:
      # New design
      form.bind()

  return render('execute.mako', request, {
    'action': action,
    'design': design,
    'error_message': error_message,
    'form': form,
    'log': log,
    'on_success_url': on_success_url,
  })
开发者ID:chanshik,项目名称:hue,代码行数:29,代码来源:views.py

示例7: get_design

 def get_design(self):
   try:
     return HQLdesign.loads(self.data)
   except ValueError:
     # data is empty
     pass
开发者ID:QLGu,项目名称:hue,代码行数:6,代码来源:models.py

示例8: get_design

 def get_design(self):
   return HQLdesign.loads(self.data)
开发者ID:agibsonccc,项目名称:hue,代码行数:2,代码来源:models.py


注:本文中的beeswax.design.HQLdesign类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。