• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.escape_rows函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: view_results

def view_results(request, id, first_row=0):
  """
  Returns the view for the results of the QueryHistory with the given id.

  The query results MUST be ready.
  To display query results, one should always go through the execute_query view.
  If the result set has has_result_set=False, display an empty result.

  If ``first_row`` is 0, restarts (if necessary) the query read.  Otherwise, just
  spits out a warning if first_row doesn't match the servers conception.
  Multiple readers will produce a confusing interaction here, and that's known.

  It understands the ``context`` GET parameter. (See execute_query().)
  """
  first_row = long(first_row)
  start_over = (first_row == 0)
  results = type('Result', (object,), {
                'rows': 0,
                'columns': [],
                'has_more': False,
                'start_row': 0,
            })
  data = []
  fetch_error = False
  error_message = ''
  log = ''
  columns = []
  app_name = get_app_name(request)

  query_history = authorized_get_query_history(request, id, must_exist=True)
  query_server = query_history.get_query_server_config()
  db = dbms.get(request.user, query_server)

  handle, state = _get_query_handle_and_state(query_history)
  context_param = request.GET.get('context', '')
  query_context = parse_query_context(context_param)

  # Update the status as expired should not be accessible
  expired = state == models.QueryHistory.STATE.expired

  # Retrieve query results or use empty result if no result set
  try:
    if query_server['server_name'] == 'impala' and not handle.has_result_set:
      downloadable = False
    else:
      results = db.fetch(handle, start_over, 100)

      # Materialize and HTML escape results
      data = escape_rows(results.rows())

      # We display the "Download" button only when we know that there are results:
      downloadable = first_row > 0 or data
      log = db.get_log(handle)
      columns = results.data_table.cols()

  except Exception, ex:
    LOG.exception('error fetching results')

    fetch_error = True
    error_message, log = expand_exception(ex, db, handle)
开发者ID:FashtimeDotCom,项目名称:hue,代码行数:60,代码来源:views.py


示例2: execute

def execute(request):
  response = {'status': -1}

  notebook = json.loads(request.POST.get('notebook', '{}'))
  snippet = json.loads(request.POST.get('snippet', '{}'))

  try:
    response['handle'] = get_api(request, snippet).execute(notebook, snippet)
  finally:
    if notebook['type'].startswith('query-'):
      _snippet = [s for s in notebook['snippets'] if s['id'] == snippet['id']][0]
      if 'handle' in response: # No failure
        _snippet['result']['handle'] = response['handle']
      else:
        _snippet['status'] = 'failed'
      history = _historify(notebook, request.user)
      response['history_id'] = history.id
      response['history_uuid'] = history.uuid
      if notebook['isSaved']: # Keep track of history of saved queries
        response['history_parent_uuid'] = history.dependencies.filter(type__startswith='query-').latest('last_modified').uuid

  # Materialize and HTML escape results
  if response['handle'].get('sync') and response['handle']['result'].get('data'):
    response['handle']['result']['data'] = escape_rows(response['handle']['result']['data'])

  response['status'] = 0

  return JsonResponse(response)
开发者ID:kevinhjk,项目名称:hue,代码行数:28,代码来源:api.py


示例3: execute

def execute(request):
  response = {'status': -1}

  notebook = json.loads(request.POST.get('notebook', '{}'))
  snippet = json.loads(request.POST.get('snippet', '{}'))

  try:
    response['handle'] = get_api(request, snippet).execute(notebook, snippet)
  finally:
    if notebook['type'].startswith('query-'):
      _snippet = [s for s in notebook['snippets'] if s['id'] == snippet['id']][0]
      if 'handle' in response: # No failure
        _snippet['result']['handle'] = response['handle']
        _snippet['result']['statements_count'] = response['handle']['statements_count']
      else:
        _snippet['status'] = 'failed'
      history = _historify(notebook, request.user)
      response['history_id'] = history.id
      response['history_uuid'] = history.uuid

  # Materialize and HTML escape results
  if response['handle'].get('sync') and response['handle']['result'].get('data'):
    response['handle']['result']['data'] = escape_rows(response['handle']['result']['data'])

  response['status'] = 0

  return JsonResponse(response)
开发者ID:OSUser,项目名称:hue,代码行数:27,代码来源:api.py


示例4: _get_sample_data

def _get_sample_data(db, database, table):
  table_obj = db.get_table(database, table)
  sample_data = db.get_sample(database, table_obj)
  response = {'status': -1}

  if sample_data:
    response['status'] = 0
    response['headers'] = sample_data.cols()
    response['rows'] = escape_rows(sample_data.rows(), nulls_only=True)
  else:
    response['message'] = _('Failed to get sample data.')

  return response
开发者ID:dgs414,项目名称:hue,代码行数:13,代码来源:api.py


示例5: get_indexes

def get_indexes(request, database, table):
  query_server = dbms.get_query_server_config(get_app_name(request))
  db = dbms.get(request.user, query_server)
  response = {'status': -1, 'error_message': ''}

  indexes = db.get_indexes(database, table)
  if indexes:
    response['status'] = 0
    response['headers'] = indexes.cols()
    response['rows'] = escape_rows(indexes.rows(), nulls_only=True)
  else:
    response['error_message'] = _('Index data took too long to be generated')

  return JsonResponse(response)
开发者ID:dimonge,项目名称:hue,代码行数:14,代码来源:api.py


示例6: get_indexes

def get_indexes(request, database, table):
  query_server = dbms.get_query_server_config(get_app_name(request))
  db = dbms.get(request.user, query_server)
  response = {'status': -1}

  indexes = db.get_indexes(database, table)
  if indexes:
    response['status'] = 0
    response['headers'] = indexes.cols()
    response['rows'] = escape_rows(indexes.rows(), nulls_only=True)
  else:
    response['message'] = _('Failed to get indexes.')

  return JsonResponse(response)
开发者ID:HaNeul-Kim,项目名称:hue,代码行数:14,代码来源:api.py


示例7: execute

def execute(request):
    response = {"status": -1}

    notebook = json.loads(request.POST.get("notebook", "{}"))
    snippet = json.loads(request.POST.get("snippet", "{}"))

    response["handle"] = get_api(request.user, snippet, request.fs, request.jt).execute(notebook, snippet)

    # Materialize and HTML escape results
    if response["handle"].get("sync") and response["handle"]["result"].get("data"):
        response["handle"]["result"]["data"] = escape_rows(response["handle"]["result"]["data"])

    response["status"] = 0

    return JsonResponse(response)
开发者ID:shobull,项目名称:hue,代码行数:15,代码来源:api.py


示例8: execute

def execute(request):
  response = {'status': -1}

  notebook = json.loads(request.POST.get('notebook', '{}'))
  snippet = json.loads(request.POST.get('snippet', '{}'))

  response['handle'] = get_api(request, snippet).execute(notebook, snippet)

  # Materialize and HTML escape results
  if response['handle'].get('sync') and response['handle']['result'].get('data'):
    response['handle']['result']['data'] = escape_rows(response['handle']['result']['data'])

  response['status'] = 0

  return JsonResponse(response)
开发者ID:bmannava-invn,项目名称:hue,代码行数:15,代码来源:api.py


示例9: get_sample_data

def get_sample_data(request, database, table):
  query_server = dbms.get_query_server_config(get_app_name(request))
  db = dbms.get(request.user, query_server)
  response = {'status': -1}

  table_obj = db.get_table(database, table)
  sample_data = db.get_sample(database, table_obj)
  if sample_data:
    response['status'] = 0
    response['headers'] = sample_data.cols()
    response['rows'] = escape_rows(sample_data.rows(), nulls_only=True)
  else:
    response['message'] = _('Failed to get sample data.')

  return JsonResponse(response)
开发者ID:HaNeul-Kim,项目名称:hue,代码行数:15,代码来源:api.py


示例10: get_functions

def get_functions(request):
  query_server = dbms.get_query_server_config(get_app_name(request))
  db = dbms.get(request.user, query_server)
  response = {'status': -1}

  prefix = request.GET.get('prefix', None)
  functions = db.get_functions(prefix)
  if functions:
    response['status'] = 0
    rows = escape_rows(functions.rows(), nulls_only=True)
    response['functions'] = [row[0] for row in rows]
  else:
    response['message'] = _('Failed to get functions.')

  return JsonResponse(response)
开发者ID:HaNeul-Kim,项目名称:hue,代码行数:15,代码来源:api.py


示例11: get_sample_data

def get_sample_data(request, database, table):
  query_server = dbms.get_query_server_config(get_app_name(request))
  db = dbms.get(request.user, query_server)
  response = {'status': -1, 'error_message': ''}

  table_obj = db.get_table(database, table)
  sample_data = db.get_sample(database, table_obj)
  if sample_data:
    response['status'] = 0
    response['headers'] = sample_data.cols()
    response['rows'] = escape_rows(sample_data.rows(), nulls_only=True)
  else:
    response['error_message'] = _('Sample data took too long to be generated')

  return JsonResponse(response)
开发者ID:dimonge,项目名称:hue,代码行数:15,代码来源:api.py


示例12: get_sample_data

def get_sample_data(request, database, table):
  db = dbms.get(request.user)
  response = {'status': -1, 'error_message': ''}

  try:
    table_obj = db.get_table(database, table)
    sample_data = db.get_sample(database, table_obj)
    if sample_data:
      response['status'] = 0
      response['headers'] = sample_data.cols()
      response['rows'] = escape_rows(sample_data.rows(), nulls_only=True)
    else:
      response['error_message'] = _('Sample data took too long to be generated')
  except Exception, ex:
    error_message, logs = dbms.expand_exception(ex, db)
    response['error_message'] = error_message
开发者ID:shobull,项目名称:hue,代码行数:16,代码来源:api.py


示例13: get_indexes

def get_indexes(request, database, table):
  query_server = dbms.get_query_server_config(get_app_name(request))
  db = dbms.get(request.user, query_server)
  response = {'status': -1, 'error_message': ''}

  try:
    indexes = db.get_indexes(database, table)
    if indexes:
      response['status'] = 0
      response['headers'] = indexes.cols()
      response['rows'] = escape_rows(indexes.rows(), nulls_only=True)
    else:
      response['error_message'] = _('Index data took too long to be generated')
  except Exception, ex:
    error_message, logs = dbms.expand_exception(ex, db)
    response['error_message'] = error_message
开发者ID:vmax-feihu,项目名称:hue,代码行数:16,代码来源:api.py


示例14: fetch_result_data

def fetch_result_data(request):
    response = {"status": -1}

    notebook = json.loads(request.POST.get("notebook", "{}"))
    snippet = json.loads(request.POST.get("snippet", "{}"))
    rows = json.loads(request.POST.get("rows", 100))
    start_over = json.loads(request.POST.get("startOver", False))

    response["result"] = get_api(request, snippet).fetch_result(notebook, snippet, rows, start_over)

    # Materialize and HTML escape results
    if response["result"].get("data") and response["result"].get("type") == "table":
        response["result"]["data"] = escape_rows(response["result"]["data"])

    response["status"] = 0

    return JsonResponse(response)
开发者ID:fangxingli,项目名称:hue,代码行数:17,代码来源:api.py


示例15: fetch_result_data

def fetch_result_data(request):
  response = {'status': -1}

  notebook = json.loads(request.POST.get('notebook', '{}'))
  snippet = json.loads(request.POST.get('snippet', '{}'))
  rows = json.loads(request.POST.get('rows', 100))
  start_over = json.loads(request.POST.get('startOver', False))

  response['result'] = get_api(request, snippet).fetch_result(notebook, snippet, rows, start_over)

  # Materialize and HTML escape results
  if response['result'].get('data') and response['result'].get('type') == 'table':
    response['result']['data'] = escape_rows(response['result']['data'])

  response['status'] = 0

  return JsonResponse(response)
开发者ID:heshunwq,项目名称:hue,代码行数:17,代码来源:api.py


示例16: _get_sample_data

def _get_sample_data(db, database, table, column):
  table_obj = db.get_table(database, table)
  sample_data = db.get_sample(database, table_obj, column)
  response = {'status': -1}

  if sample_data:
    sample = escape_rows(sample_data.rows(), nulls_only=True)
    if column:
      sample = set([row[0] for row in sample])
      sample = [[item] for item in sorted(list(sample))]

    response['status'] = 0
    response['headers'] = sample_data.cols()
    response['rows'] = sample
  else:
    response['message'] = _('Failed to get sample data.')

  return response
开发者ID:Andrea1988,项目名称:hue,代码行数:18,代码来源:api.py


示例17: get_sample_data

  def get_sample_data(self, database, table, column=None):
    if column is None:
      column = ', '.join([col['name'] for col in self.get_columns(database, table)])

    snippet = {
        'database': table,
        'statement': 'SELECT %s FROM %s LIMIT 250' % (column, table)
    }
    res = self.api.execute(None, snippet)

    response = {'status': -1}

    if res:
      response['status'] = 0
      response['headers'] = [col['name'] for col in res['result']['meta']]
      response['rows'] = escape_rows(res['result']['data'], nulls_only=True)
    else:
      response['message'] = _('Failed to get sample data.')

    return response
开发者ID:infect2,项目名称:hue,代码行数:20,代码来源:solr.py


示例18: execute

def execute(request):
  response = {'status': -1}

  notebook = json.loads(request.POST.get('notebook', '{}'))
  snippet = json.loads(request.POST.get('snippet', '{}'))

  try:
    response['handle'] = get_api(request, snippet).execute(notebook, snippet)
  finally:
    if notebook['type'].startswith('query-'):
      history = _historify(notebook, request.user)
      response['history_id'] = history.id

  # Materialize and HTML escape results
  if response['handle'].get('sync') and response['handle']['result'].get('data'):
    response['handle']['result']['data'] = escape_rows(response['handle']['result']['data'])

  response['status'] = 0

  return JsonResponse(response)
开发者ID:biddyweb,项目名称:hue,代码行数:20,代码来源:api.py


示例19: execute

def execute(request):
  response = {'status': -1}
  result = None

  notebook = json.loads(request.POST.get('notebook', '{}'))
  snippet = json.loads(request.POST.get('snippet', '{}'))

  try:
    response['handle'] = get_api(request, snippet).execute(notebook, snippet)

    # Retrieve and remove the result from the handle
    if response['handle'].get('sync'):
      result = response['handle'].pop('result')
  finally:
    if notebook['type'].startswith('query-'):
      _snippet = [s for s in notebook['snippets'] if s['id'] == snippet['id']][0]
      if 'handle' in response: # No failure
        _snippet['result']['handle'] = response['handle']
        _snippet['result']['statements_count'] = response['handle'].get('statements_count', 1)
        _snippet['result']['statement_id'] = response['handle'].get('statement_id', 0)
        _snippet['result']['handle']['statement'] = response['handle'].get('statement', snippet['statement']) # For non HS2, as non multi query yet
      else:
        _snippet['status'] = 'failed'
      history = _historify(notebook, request.user)
      response['history_id'] = history.id
      response['history_uuid'] = history.uuid
      if notebook['isSaved']: # Keep track of history of saved queries
        response['history_parent_uuid'] = history.dependencies.filter(type__startswith='query-').latest('last_modified').uuid

  # Inject and HTML escape results
  if result is not None:
    response['result'] = result
    response['result']['data'] = escape_rows(result['data'])

  response['status'] = 0

  return JsonResponse(response)
开发者ID:heshunwq,项目名称:hue,代码行数:37,代码来源:api.py


示例20: make_notebook

    response['status'] = 0
    if async:
      notebook = make_notebook(
          name=_('Table sample for `%(database)s`.`%(table)s`.`%(column)s`') % {'database': database, 'table': table, 'column': column},
          editor_type=_get_servername(db),
          statement=sample_data,
          status='ready-execute',
          skip_historify=True,
          is_task=False,
          compute=cluster if cluster else None
      )
      response['result'] = notebook.execute(request=MockedDjangoRequest(user=db.client.user), batch=False)
      if table_obj.is_impala_only:
        response['result']['type'] = 'impala'
    else:
      sample = escape_rows(sample_data.rows(), nulls_only=True)
      if column:
        sample = set([row[0] for row in sample])
        sample = [[item] for item in sorted(list(sample))]

      response['headers'] = sample_data.cols()
      response['full_headers'] = sample_data.full_cols()
      response['rows'] = sample
  else:
    response['message'] = _('Failed to get sample data.')

  return response


@error_handler
def get_indexes(request, database, table):
开发者ID:cloudera,项目名称:hue,代码行数:31,代码来源:api.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python nbextensions.install_nbextension函数代码示例发布时间:2022-05-27
下一篇:
Python github.GithubClient类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap