Example #1
0
def load_after_create(request, database):
    """
  Automatically load data into a newly created table.

  We get here from the create's on_success_url, and expect to find
  ``table`` and ``path`` from the parameters.
  """
    tablename = request.REQUEST.get("table")
    path = request.REQUEST.get("path")
    is_remove_header = request.REQUEST.get("removeHeader").lower() == "on" and not path.endswith("gz")

    if not tablename or not path:
        msg = _("Internal error: Missing needed parameter to load data into table.")
        LOG.error(msg)
        raise PopupException(msg)

    if is_remove_header:
        remove_header(request.fs, path)

    LOG.debug("Auto loading data from %s into table %s" % (path, tablename))
    hql = "LOAD DATA INPATH '%s' INTO TABLE `%s.%s`" % (path, database, tablename)
    query = hql_query(hql)

    on_success_url = reverse("metastore:describe_table", kwargs={"database": database, "table": tablename})

    return execute_directly(request, query, on_success_url=on_success_url)
Example #2
0
def load_after_create(request, database):
  """
  Automatically load data into a newly created table.

  We get here from the create's on_success_url, and expect to find
  ``table`` and ``path`` from the parameters.
  """
  tablename = request.REQUEST.get('table')
  path = request.REQUEST.get('path')

  if not tablename or not path:
    msg = _('Internal error: Missing needed parameter to load data into table.')
    LOG.error(msg)
    raise PopupException(msg)

  LOG.debug("Auto loading data from %s into table %s" % (path, tablename))
  hql = "LOAD DATA INPATH '%s' INTO TABLE `%s.%s`" % (path, database, tablename)
  query = hql_query(hql)

  on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': tablename})

  try:
    return execute_directly(request, query, on_success_url=on_success_url)
  except Exception, e:
    message = 'The table data could not be loaded'
    LOG.exception(message)
    detail = e.message if hasattr(e, 'message') and e.message else None
    raise PopupException(_(message), detail=detail)
Example #3
0
def _submit_create_and_load(request, create_hql, table_name, path, do_load):
    """
  Submit the table creation, and setup the load to happen (if ``do_load``).
  """
    on_success_params = {}

    if do_load:
        on_success_params["table"] = table_name
        on_success_params["path"] = path
        on_success_url = urlresolvers.reverse(load_after_create)
    else:
        on_success_url = urlresolvers.reverse(describe_table, kwargs={"table": table_name})

    query = hql_query(create_hql)
    return execute_directly(request, query, on_success_url=on_success_url, on_success_params=on_success_params)
Example #4
0
def _submit_create_and_load(request, create_hql, table_name, path, do_load):
  """
  Submit the table creation, and setup the load to happen (if ``do_load``).
  """
  on_success_params = { }
  if do_load:
    on_success_params['table'] = table_name
    on_success_params['path'] = path
    on_success_url = urlresolvers.reverse(beeswax.create_table.load_after_create)
  else:
    on_success_url = urlresolvers.reverse(describe_table, kwargs={'table': table_name})

  query_msg = make_beeswax_query(request, create_hql)
  return execute_directly(request, query_msg,
                          on_success_url=on_success_url,
                          on_success_params=on_success_params)
Example #5
0
def _submit_create_and_load(request, create_hql, table_name, path, do_load, database):
  """
  Submit the table creation, and setup the load to happen (if ``do_load``).
  """
  on_success_params = {}
  app_name = get_app_name(request)

  if do_load:
    on_success_params['table'] = table_name
    on_success_params['path'] = path
    on_success_url = reverse(app_name + ':load_after_create', kwargs={'database': database})
  else:
    on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': table_name})

  query = hql_query(create_hql, database=database)
  return execute_directly(request, query,
                          on_success_url=on_success_url,
                          on_success_params=on_success_params)
Example #6
0
def _submit_create_and_load(request, create_hql, table_name, path, load_data, database):
  """
  Submit the table creation, and setup the load to happen (if ``load_data`` == IMPORT).
  """
  on_success_params = QueryDict('', mutable=True)
  app_name = get_app_name(request)

  if load_data == 'IMPORT':
    on_success_params['table'] = table_name
    on_success_params['path'] = path
    on_success_url = reverse(app_name + ':load_after_create', kwargs={'database': database}) + '?' + on_success_params.urlencode()
  else:
    on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': table_name})

  query = hql_query(create_hql, database=database)
  return execute_directly(request, query,
                                on_success_url=on_success_url,
                                on_success_params=on_success_params)
Example #7
0
def create_database(request):

  if request.method == "POST":
    data = request.POST.copy()
    data.setdefault("use_default_location", False)
    form = CreateDatabaseForm(data)

    if form.is_valid():
      proposed_query = django_mako.render_to_string("create_database_statement.mako", {
        'database': form.cleaned_data,
      })
      query = hql_query(proposed_query)
      return execute_directly(request, query, on_success_url=reverse('metastore:databases'))
  else:
    form = CreateDatabaseForm()

  return render("create_database.mako", request, {
    'database_form': form,
  })
Example #8
0
def load_after_create(request):
  """
  Automatically load data into a newly created table.

  We get here from the create's on_success_url, and expect to find
  ``table`` and ``path`` from the parameters.
  """
  tablename = request.REQUEST.get('table')
  path = request.REQUEST.get('path')
  if not tablename or not path:
    msg = 'Internal error: Missing needed parameter to load data into table'
    LOG.error(msg)
    raise PopupException(msg)

  LOG.debug("Auto loading data from %s into table %s" % (path, tablename))
  hql = "LOAD DATA INPATH '%s' INTO TABLE `%s`" % (path, tablename)
  query_msg = make_beeswax_query(request, hql)
  on_success_url = urlresolvers.reverse(describe_table, kwargs={'table': tablename})

  return execute_directly(request, query_msg, on_success_url=on_success_url)
Example #9
0
def _submit_create_and_load(request, create_hql, table_name, path, do_load, database):
    """
  Submit the table creation, and setup the load to happen (if ``do_load``).
  """
    on_success_params = QueryDict("", mutable=True)
    app_name = get_app_name(request)

    if do_load:
        on_success_params["table"] = table_name
        on_success_params["path"] = path
        on_success_params["removeHeader"] = request.POST.get("removeHeader")
        on_success_url = (
            reverse(app_name + ":load_after_create", kwargs={"database": database})
            + "?"
            + on_success_params.urlencode()
        )
    else:
        on_success_url = reverse("metastore:describe_table", kwargs={"database": database, "table": table_name})

    query = hql_query(create_hql, database=database)
    return execute_directly(request, query, on_success_url=on_success_url, on_success_params=on_success_params)
Example #10
0
def load_after_create(request, database):
  """
  Automatically load data into a newly created table.

  We get here from the create's on_success_url, and expect to find
  ``table`` and ``path`` from the parameters.
  """
  tablename = request.REQUEST.get('table')
  path = request.REQUEST.get('path')

  if not tablename or not path:
    msg = _('Internal error: Missing needed parameter to load data into table')
    LOG.error(msg)
    raise PopupException(msg)

  LOG.debug("Auto loading data from %s into table %s" % (path, tablename))
  hql = "LOAD DATA INPATH '%s' INTO TABLE `%s.%s`" % (path, database, tablename)
  query = hql_query(hql)
  app_name = get_app_name(request)
  on_success_url = reverse(app_name + ':describe_table', kwargs={'database': database, 'table': tablename})

  return execute_directly(request, query, on_success_url=on_success_url)
Example #11
0
def create_database(request):
  db = dbms.get(request.user)

  if request.method == "POST":
    data = request.POST.copy()
    data.setdefault("use_default_location", False)
    form = CreateDatabaseForm(data)

    if form.is_valid():
      proposed_query = django_mako.render_to_string("create_database_statement.mako", {
        'database': form.cleaned_data,
      })
      # Mako outputs bytestring in utf8
      proposed_query = proposed_query.decode('utf-8')
      query = hql_query(proposed_query)
      return execute_directly(request, query, on_success_url=reverse('catalog:show_databases'))
  else:
    form = CreateDatabaseForm()

  return render("create_database.mako", request, {
    'database_form': form,
  })
Example #12
0
def load_after_create(request, database):
  """
  Automatically load data into a newly created table.

  We get here from the create's on_success_url, and expect to find
  ``table`` and ``path`` from the parameters.
  """
  tablename = request.REQUEST.get('table')
  path = request.REQUEST.get('path')
  is_remove_header = request.REQUEST.get('removeHeader').lower() == 'on' and not path.endswith('gz')

  if not tablename or not path:
    msg = _('Internal error: Missing needed parameter to load data into table.')
    LOG.error(msg)
    raise PopupException(msg)

  if is_remove_header:
    try:
      remove_header(request.fs, path)
    except Exception, e:
      raise PopupException(_("The headers of the file could not be removed."), detail=e)

  LOG.debug("Auto loading data from %s into table %s" % (path, tablename))
  hql = "LOAD DATA INPATH '%s' INTO TABLE `%s.%s`" % (path, database, tablename)
  query = hql_query(hql)

  on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': tablename})

  return execute_directly(request, query, on_success_url=on_success_url)
Example #13
0
  ``table`` and ``path`` from the parameters.
  """
  tablename = request.REQUEST.get('table')
  path = request.REQUEST.get('path')
  is_remove_header = request.REQUEST.get('removeHeader').lower() == 'on' and not path.endswith('gz')

  if not tablename or not path:
    msg = _('Internal error: Missing needed parameter to load data into table.')
    LOG.error(msg)
    raise PopupException(msg)

  if is_remove_header:
    try:
      remove_header(request.fs, path)
    except Exception, e:
      raise PopupException(_("The headers of the file could not be removed."), detail=e)

  LOG.debug("Auto loading data from %s into table %s" % (path, tablename))
  hql = "LOAD DATA INPATH '%s' INTO TABLE `%s.%s`" % (path, database, tablename)
  query = hql_query(hql)

  on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': tablename})

  try:
    return execute_directly(request, query, on_success_url=on_success_url)
  except Exception, e:
    message = 'The table data could not be loaded'
    LOG.exception(message)
    detail = e.message if hasattr(e, 'message') and e.message else None
    raise PopupException(_(message), detail=detail)