Exemple #1
0
def show_tables(request, database=None):
  if database is None:
    database = 'default' # Assume always 'default'

  if request.REQUEST.get("format", "html") == "json":
    db = dbms.get(request.user)

    try:
      databases = db.get_databases()

      if database not in databases:
        database = 'default'

      if request.method == 'POST':
        db_form = DbForm(request.POST, databases=databases)
        if db_form.is_valid():
          database = db_form.cleaned_data['database']
      else:
        db_form = DbForm(initial={'database': database}, databases=databases)

      search_filter = request.GET.get('filter', '')

      tables = db.get_tables_meta(database=database, table_names=search_filter) # SparkSql returns []
      table_names = [table['name'] for table in tables]
    except Exception, e:
      raise PopupException(_('Failed to retrieve tables for database: %s' % database), detail=e)

    resp = JsonResponse({
        'status': 0,
        'database_meta': db.get_database(database),
        'tables': tables,
        'table_names': table_names,
        'search_filter': search_filter
    })
Exemple #2
0
def show_tables(request, database=None):
  if database is None:
    database = 'default' # Assume always 'default'

  if request.REQUEST.get("format", "html") == "json":
    db = dbms.get(request.user)

    try:
      databases = db.get_databases()

      if database not in databases:
        database = 'default'

      if request.method == 'POST':
        db_form = DbForm(request.POST, databases=databases)
        if db_form.is_valid():
          database = db_form.cleaned_data['database']
      else:
        db_form = DbForm(initial={'database': database}, databases=databases)

      search_filter = request.GET.get('filter', '')

      tables = db.get_tables_meta(database=database, table_names=search_filter) # SparkSql returns []
      table_names = [table['name'] for table in tables]
    except Exception, e:
      raise PopupException(_('Failed to retrieve tables for database: %s' % database), detail=e)

    resp = JsonResponse({
        'status': 0,
        'database_meta': db.get_database(database),
        'tables': tables,
        'table_names': table_names,
        'search_filter': search_filter
    })
Exemple #3
0
def show_tables(request, database=None):
  if database is None:
    database = request.COOKIES.get('hueBeeswaxLastDatabase', 'default') # Assume always 'default'

  db = dbms.get(request.user)

  try:
    databases = db.get_databases()

    if database not in databases:
      database = 'default'

    if request.method == 'POST':
      db_form = DbForm(request.POST, databases=databases)
      if db_form.is_valid():
        database = db_form.cleaned_data['database']
    else:
      db_form = DbForm(initial={'database': database}, databases=databases)

    search_filter = request.GET.get('filter', '')

    tables = db.get_tables_meta(database=database, table_names=search_filter) # SparkSql returns []
    table_names = [table['name'] for table in tables]
  except Exception, e:
    raise PopupException(_('Failed to retrieve tables for database: %s' % database), detail=e)
Exemple #4
0
def show_tables(request, database=None):
  if database is None:
    database = request.COOKIES.get('hueBeeswaxLastDatabase', 'default') # Assume always 'default'

  db = dbms.get(request.user)

  databases = db.get_databases()

  if request.method == 'POST':
    db_form = DbForm(request.POST, databases=databases)
    if db_form.is_valid():
      database = db_form.cleaned_data['database']
  else:
    db_form = DbForm(initial={'database': database}, databases=databases)

  tables = db.get_tables(database=database)

  resp = render("tables.mako", request, {
    'breadcrumbs': [
      {
        'name': database,
        'url': reverse('metastore:show_tables', kwargs={'database': database})
      }
    ],
    'tables': tables,
    'db_form': db_form,
    'database': database,
    'tables_json': json.dumps(tables),
    'has_write_access': has_write_access(request.user),
  })
  resp.set_cookie("hueBeeswaxLastDatabase", database, expires=90)
  return resp
Exemple #5
0
def show_tables(request, database=None):
    if database is None:
        database = request.COOKIES.get("hueBeeswaxLastDatabase", "default")  # Assume always 'default'

    db = dbms.get(request.user)

    databases = db.get_databases()

    if database not in databases:
        database = "default"

    if request.method == "POST":
        db_form = DbForm(request.POST, databases=databases)
        if db_form.is_valid():
            database = db_form.cleaned_data["database"]
    else:
        db_form = DbForm(initial={"database": database}, databases=databases)

    tables = db.get_tables(database=database)

    resp = render(
        "tables.mako",
        request,
        {
            "breadcrumbs": [{"name": database, "url": reverse("metastore:show_tables", kwargs={"database": database})}],
            "tables": tables,
            "db_form": db_form,
            "database": database,
            "tables_json": json.dumps(tables),
            "has_write_access": has_write_access(request.user),
        },
    )
    resp.set_cookie("hueBeeswaxLastDatabase", database, expires=90)
    return resp
Exemple #6
0
def show_tables(request, database=None):
  if database is None:
    database = request.COOKIES.get('hueBeeswaxLastDatabase', 'default') # Assume always 'default'

  db = dbms.get(request.user)

  try:
    databases = db.get_databases()

    if database not in databases:
      database = 'default'

    if request.method == 'POST':
      db_form = DbForm(request.POST, databases=databases)
      if db_form.is_valid():
        database = db_form.cleaned_data['database']
    else:
      db_form = DbForm(initial={'database': database}, databases=databases)

    search_filter = request.GET.get('filter', '')

    table_names = db.get_tables(database=database, table_names=search_filter)
    tables = [{'name': table} for table in table_names]
    has_metadata = False

    if len(table_names) <= HS2_GET_TABLES_MAX.get():  # Only attempt to do a GetTables HS2 call for small result sets
      try:
        tables = db.get_tables_meta(database=database, table_names=search_filter)
        table_names = [table['name'] for table in tables]
        has_metadata = True
      except Exception, ex:
        LOG.exception('Unable to fetch table metadata')
  except Exception, e:
    raise PopupException(_('Failed to retrieve tables for database: %s' % database), detail=e)
Exemple #7
0
def show_tables(request, database=None):
  if database is None:
    database = request.COOKIES.get('hueBeeswaxLastDatabase', 'default') # Assume always 'default'

  db = dbms.get(request.user)

  databases = db.get_databases()

  if request.method == 'POST':
    db_form = DbForm(request.POST, databases=databases)
    if db_form.is_valid():
      database = db_form.cleaned_data['database']
  else:
    db_form = DbForm(initial={'database': database}, databases=databases)

  tables = db.get_tables(database=database)

  resp = render("tables.mako", request, {
    'breadcrumbs': [
      {
        'name': database,
        'url': reverse('metastore:show_tables', kwargs={'database': database})
      }
    ],
    'tables': tables,
    'db_form': db_form,
    'database': database,
    'tables_json': json.dumps(tables),
    'has_write_access': has_write_access(request.user),
  })
  resp.set_cookie("hueBeeswaxLastDatabase", database, expires=90)
  return resp
Exemple #8
0
def show_tables(request, database=None):
    if database is None:
        database = request.COOKIES.get('hueBeeswaxLastDatabase',
                                       'default')  # Assume always 'default'

    db = dbms.get(request.user)

    try:
        databases = db.get_databases()

        if database not in databases:
            database = 'default'

        if request.method == 'POST':
            db_form = DbForm(request.POST, databases=databases)
            if db_form.is_valid():
                database = db_form.cleaned_data['database']
        else:
            db_form = DbForm(initial={'database': database},
                             databases=databases)

        tables = db.get_tables_meta(database=database)
        table_names = [table['name'] for table in tables]
    except Exception, e:
        raise PopupException(_('Failed to retrieve tables for database: %s' %
                               database),
                             detail=e)
Exemple #9
0
def show_tables(request, database=None):
    cluster = json.loads(request.POST.get('cluster', '{}'))

    db = _get_db(user=request.user, cluster=cluster)

    if database is None:
        database = 'default'  # Assume always 'default'

    if request.GET.get("format", "html") == "json":
        try:
            databases = db.get_databases()

            if database not in databases:
                database = 'default'

            if request.method == 'POST':
                db_form = DbForm(request.POST, databases=databases)
                if db_form.is_valid():
                    database = db_form.cleaned_data['database']
            else:
                db_form = DbForm(initial={'database': database},
                                 databases=databases)

            search_filter = request.GET.get('filter', '')

            tables = db.get_tables_meta(
                database=database,
                table_names=search_filter)  # SparkSql returns []
            table_names = [table['name'] for table in tables]
        except Exception as e:
            raise PopupException(_(
                'Failed to retrieve tables for database: %s' % database),
                                 detail=e)

        resp = JsonResponse({
            'status': 0,
            'database_meta': db.get_database(database),
            'tables': tables,
            'table_names': table_names,
            'search_filter': search_filter
        })
    else:
        apps_list = _get_apps(request.user, '')
        resp = render(
            "metastore.mako", request, {
                'apps': apps_list,
                'breadcrumbs': [],
                'database': None,
                'partitions': [],
                'has_write_access': has_write_access(request.user),
                'is_optimizer_enabled': has_optimizer(),
                'is_navigator_enabled': has_catalog(request.user),
                'optimizer_url': get_optimizer_url(),
                'navigator_url': get_catalog_url(),
                'is_embeddable': request.GET.get('is_embeddable', False),
                'source_type': _get_servername(db),
            })

    return resp
Exemple #10
0
def show_tables(request, database=None):
    if database is None:
        database = request.COOKIES.get('hueBeeswaxLastDatabase',
                                       'default')  # Assume always 'default'

    db = dbms.get(request.user)

    try:
        databases = db.get_databases()

        if database not in databases:
            database = 'default'

        if request.method == 'POST':
            db_form = DbForm(request.POST, databases=databases)
            if db_form.is_valid():
                database = db_form.cleaned_data['database']
        else:
            db_form = DbForm(initial={'database': database},
                             databases=databases)

        search_filter = request.GET.get('filter', '')

        table_names = db.get_tables(database=database,
                                    table_names=search_filter)
        tables = [{'name': table} for table in table_names]

        has_metadata = False

        if len(table_names) <= HS2_GET_TABLES_MAX.get(
        ):  # Only attempt to do a GetTables HS2 call for small result sets
            try:
                tables_meta = db.get_tables_meta(
                    database=database,
                    table_names=search_filter)  # SparkSql returns []
                if tables_meta:
                    tables = tables_meta
                    table_names = [table['name'] for table in tables_meta]
                    has_metadata = True
            except Exception, ex:
                LOG.exception('Unable to fetch table metadata')
    except Exception, e:
        raise PopupException(_('Failed to retrieve tables for database: %s' %
                               database),
                             detail=e)
Exemple #11
0
def show_tables(request, database=None):
    if database is None:
        database = request.COOKIES.get("hueBeeswaxLastDatabase", "default")  # Assume always 'default'

    db = dbms.get(request.user)

    try:
        databases = db.get_databases()

        if database not in databases:
            database = "default"

        if request.method == "POST":
            db_form = DbForm(request.POST, databases=databases)
            if db_form.is_valid():
                database = db_form.cleaned_data["database"]
        else:
            db_form = DbForm(initial={"database": database}, databases=databases)

        tables = db.get_tables(database=database)
    except Exception, e:
        raise PopupException(_("Failed to retrieve tables for database: %s" % database), detail=e)
Exemple #12
0
def show_tables(request, database=None):
    if database is None:
        database = request.COOKIES.get("hueBeeswaxLastDatabase", "default")  # Assume always 'default'

    db = dbms.get(request.user)

    try:
        databases = db.get_databases()

        if database not in databases:
            database = "default"

        if request.method == "POST":
            db_form = DbForm(request.POST, databases=databases)
            if db_form.is_valid():
                database = db_form.cleaned_data["database"]
        else:
            db_form = DbForm(initial={"database": database}, databases=databases)

        search_filter = request.GET.get("filter", "")

        table_names = db.get_tables(database=database, table_names=search_filter)
        tables = [{"name": table} for table in table_names]

        has_metadata = False

        if (
            len(table_names) <= HS2_GET_TABLES_MAX.get()
        ):  # Only attempt to do a GetTables HS2 call for small result sets
            try:
                tables_meta = db.get_tables_meta(database=database, table_names=search_filter)  # SparkSql returns []
                if tables_meta:
                    tables = tables_meta
                    table_names = [table["name"] for table in tables_meta]
                    has_metadata = True
            except Exception, ex:
                LOG.exception("Unable to fetch table metadata")
    except Exception, e:
        raise PopupException(_("Failed to retrieve tables for database: %s" % database), detail=e)
Exemple #13
0
def show_tables(request, database=None):
    if database is None:
        database = "default"  # Assume always 'default'

    if request.REQUEST.get("format", "html") == "json":
        db = dbms.get(request.user)

        try:
            databases = db.get_databases()

            if database not in databases:
                database = "default"

            if request.method == "POST":
                db_form = DbForm(request.POST, databases=databases)
                if db_form.is_valid():
                    database = db_form.cleaned_data["database"]
            else:
                db_form = DbForm(initial={"database": database}, databases=databases)

            search_filter = request.GET.get("filter", "")

            tables = db.get_tables_meta(database=database, table_names=search_filter)  # SparkSql returns []
            table_names = [table["name"] for table in tables]
        except Exception, e:
            raise PopupException(_("Failed to retrieve tables for database: %s" % database), detail=e)

        resp = JsonResponse(
            {
                "status": 0,
                "database_meta": db.get_database(database),
                "tables": tables,
                "table_names": table_names,
                "search_filter": search_filter,
            }
        )