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)
def test_show_tables(self): # Set max limit to 3 resets = [HS2_GET_TABLES_MAX.set_for_testing(3)] try: hql = """ CREATE TABLE test_show_tables_1 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_2 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_3 (a int) COMMENT 'Test for show_tables'; """ resp = _make_query(self.client, hql, database=self.db_name) resp = wait_for_query_to_finish(self.client, resp, max=30.0) # Table should have been created response = self.client.get( "/metastore/tables/%s?filter=show_tables" % self.db_name) assert_equal(200, response.status_code) assert_equal(len(response.context['tables']), 3) assert_equal(response.context['has_metadata'], True) assert_true('name' in response.context["tables"][0]) assert_true('comment' in response.context["tables"][0]) assert_true('type' in response.context["tables"][0]) hql = """ CREATE TABLE test_show_tables_4 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_5 (a int) COMMENT 'Test for show_tables'; """ resp = _make_query(self.client, hql, database=self.db_name) resp = wait_for_query_to_finish(self.client, resp, max=30.0) # Table should have been created response = self.client.get( "/metastore/tables/%s?filter=show_tables" % self.db_name) assert_equal(200, response.status_code) assert_equal(len(response.context['tables']), 5) assert_equal(response.context['has_metadata'], False) assert_true('name' in response.context["tables"][0]) assert_false('comment' in response.context["tables"][0], response.context["tables"]) assert_false('type' in response.context["tables"][0]) hql = """ CREATE INDEX test_index ON TABLE test_show_tables_1 (a) AS 'COMPACT' WITH DEFERRED REBUILD; """ resp = _make_query(self.client, hql, wait=True, local=False, max=30.0, database=self.db_name) # By default, index table should not appear in show tables view response = self.client.get("/metastore/tables/%s" % self.db_name) assert_equal(200, response.status_code) assert_false('test_index' in response.context['tables']) finally: for reset in resets: reset()
def test_show_tables(self): # Set max limit to 3 resets = [ HS2_GET_TABLES_MAX.set_for_testing(3) ] try: hql = """ CREATE TABLE test_show_tables_1 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_2 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_3 (a int) COMMENT 'Test for show_tables'; """ resp = _make_query(self.client, hql, database=self.db_name) resp = wait_for_query_to_finish(self.client, resp, max=30.0) # Table should have been created response = self.client.get("/metastore/tables/%s?filter=show_tables" % self.db_name) assert_equal(200, response.status_code) assert_equal(len(response.context['tables']), 3) assert_equal(response.context['has_metadata'], True) assert_true('name' in response.context["tables"][0]) assert_true('comment' in response.context["tables"][0]) assert_true('type' in response.context["tables"][0]) hql = """ CREATE TABLE test_show_tables_4 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_5 (a int) COMMENT 'Test for show_tables'; """ resp = _make_query(self.client, hql, database=self.db_name) resp = wait_for_query_to_finish(self.client, resp, max=30.0) # Table should have been created response = self.client.get("/metastore/tables/%s?filter=show_tables" % self.db_name) assert_equal(200, response.status_code) assert_equal(len(response.context['tables']), 5) assert_equal(response.context['has_metadata'], False) assert_true('name' in response.context["tables"][0]) assert_false('comment' in response.context["tables"][0], response.context["tables"]) assert_false('type' in response.context["tables"][0]) hql = """ CREATE INDEX test_index ON TABLE test_show_tables_1 (a) AS 'COMPACT' WITH DEFERRED REBUILD; """ resp = _make_query(self.client, hql, wait=True, local=False, max=30.0, database=self.db_name) # By default, index table should not appear in show tables view response = self.client.get("/metastore/tables/%s" % self.db_name) assert_equal(200, response.status_code) assert_false('test_index' in response.context['tables']) finally: for reset in resets: reset()
def test_show_tables(self): if is_live_cluster(): raise SkipTest('HUE-2902: Test is not re-entrant') # Set max limit to 3 resets = [HS2_GET_TABLES_MAX.set_for_testing(3)] try: hql = """ CREATE TABLE test_show_tables_1 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_2 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_3 (a int) COMMENT 'Test for show_tables'; """ resp = _make_query(self.client, hql, database=self.db_name) resp = wait_for_query_to_finish(self.client, resp, max=30.0) # Table should have been created response = self.client.get( "/metastore/tables/%s?filter=show_tables" % self.db_name) assert_equal(200, response.status_code) assert_equal(len(response.context['tables']), 3) assert_equal(response.context['has_metadata'], True) assert_true('name' in response.context["tables"][0]) assert_true('comment' in response.context["tables"][0]) assert_true('type' in response.context["tables"][0]) hql = """ CREATE TABLE test_show_tables_4 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_5 (a int) COMMENT 'Test for show_tables'; """ resp = _make_query(self.client, hql, database=self.db_name) resp = wait_for_query_to_finish(self.client, resp, max=30.0) # Table should have been created response = self.client.get( "/metastore/tables/%s?filter=show_tables" % self.db_name) assert_equal(200, response.status_code) assert_equal(len(response.context['tables']), 5) assert_equal(response.context['has_metadata'], False) assert_true('name' in response.context["tables"][0]) assert_false('comment' in response.context["tables"][0], response.context["tables"]) assert_false('type' in response.context["tables"][0]) finally: for reset in resets: reset()
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)
def test_show_tables(self): if is_live_cluster(): raise SkipTest('HUE-2902: Test is not re-entrant') # Set max limit to 3 resets = [ HS2_GET_TABLES_MAX.set_for_testing(3) ] try: hql = """ CREATE TABLE test_show_tables_1 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_2 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_3 (a int) COMMENT 'Test for show_tables'; """ resp = _make_query(self.client, hql, database=self.db_name) resp = wait_for_query_to_finish(self.client, resp, max=30.0) # Table should have been created response = self.client.get("/metastore/tables/%s?filter=show_tables" % self.db_name) assert_equal(200, response.status_code) assert_equal(len(response.context['tables']), 3) assert_equal(response.context['has_metadata'], True) assert_true('name' in response.context["tables"][0]) assert_true('comment' in response.context["tables"][0]) assert_true('type' in response.context["tables"][0]) hql = """ CREATE TABLE test_show_tables_4 (a int) COMMENT 'Test for show_tables'; CREATE TABLE test_show_tables_5 (a int) COMMENT 'Test for show_tables'; """ resp = _make_query(self.client, hql, database=self.db_name) resp = wait_for_query_to_finish(self.client, resp, max=30.0) # Table should have been created response = self.client.get("/metastore/tables/%s?filter=show_tables" % self.db_name) assert_equal(200, response.status_code) assert_equal(len(response.context['tables']), 5) assert_equal(response.context['has_metadata'], False) assert_true('name' in response.context["tables"][0]) assert_false('comment' in response.context["tables"][0], response.context["tables"]) assert_false('type' in response.context["tables"][0]) finally: for reset in resets: reset()
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)