فهرست منبع

HUE-9150 [editor] Filter out tables not compatible with selected dialect

Romain 5 سال پیش
والد
کامیت
a8683ec696

+ 18 - 9
apps/beeswax/src/beeswax/management/commands/beeswax_install_examples.py

@@ -94,15 +94,20 @@ class Command(BaseCommand):
     table_list = json.load(table_file)
     table_file.close()
 
+    table_list = [table_dict for table_dict in table_list if dialect in table_dict.get('dialects', [dialect])]
+
+    if not table_list:
+      raise InstallException(_('No %s tables are available as samples') % dialect)
+
     for table_dict in table_list:
-      if dialect in table_dict.get('dialects', [dialect]):
-        try:
-          table = SampleTable(table_dict, dialect, db_name, interpreter=interpreter, request=request)
-          table.install(django_user)
-        except Exception as ex:
-          msg = str(ex)
-          LOG.error(msg)
-          raise InstallException(_('Could not install table %s: %s') % (table_dict['table_name'], msg))
+      try:
+        table = SampleTable(table_dict, dialect, db_name, interpreter=interpreter, request=request)
+        table.install(django_user)
+      except Exception as ex:
+        msg = str(ex)
+        LOG.error(msg)
+        raise InstallException(_('Could not install table %s: %s') % (table_dict['table_name'], msg))
+
 
   def _install_queries(self, django_user, dialect, interpreter=None):
     design_file = open(os.path.join(LOCAL_EXAMPLES_DATA_DIR.get(), 'queries.json'))
@@ -159,6 +164,10 @@ class SampleTable(object):
 
 
   def install(self, django_user):
+    if not (has_concurrency_support() and self.is_transactional) and not cluster.get_hdfs():
+      LOG.warn('Skipping table %s as requiring a File System to load its data' % self.name)
+      return
+
     self.create(django_user)
 
     if self.partition_files:
@@ -188,7 +197,7 @@ class SampleTable(object):
       job.execute_and_wait(self.request)
     except Exception as ex:
       if 'already exists' in str(ex):
-        LOG.warn('Table %s already exists' % self.name)
+        LOG.warn('Table %s.%s already exists' % (self.db_name, self.name))
       else:
         raise ex
 

+ 18 - 1
apps/beeswax/src/beeswax/management/commands/beeswax_install_examples_tests.py

@@ -84,7 +84,7 @@ class TestStandardTables():
 
 
 
-class TestBeswaxHiveTables():
+class TestHiveServer2():
 
   def setUp(self):
     self.client = make_logged_in_client(username="test", groupname="default", recreate=True, is_superuser=False)
@@ -122,6 +122,23 @@ class TestBeswaxHiveTables():
         assert_equal('query-hive', query.type)
 
 
+  def test_create_table_load_data_but_no_fs(self):
+    table_data =   {
+      "data_file": "sample_07.csv",
+      "create_sql": "CREATE TABLE `sample_07` (\n  `code` string ,\n  `description` string ,\n  `total_emp` int ,\n  `salary` int )\nSTORED AS parquet\nTBLPROPERTIES ('transactional'='true', 'transactional_properties'='insert_only')\n",
+      "table_name": "sample_07",
+    }
+
+    with patch('beeswax.management.commands.beeswax_install_examples.make_notebook') as make_notebook:
+      with patch('beeswax.management.commands.beeswax_install_examples.has_concurrency_support') as has_concurrency_support:
+        has_concurrency_support.return_value = True
+
+        SampleTable(table_data, 'hive', 'default').install(self.user)
+
+        make_notebook.assert_not_called()
+
+
+
 class TestTransactionalTables():
 
   def setUp(self):

+ 5 - 2
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -295,8 +295,11 @@ class Notebook(object):
       Check status until it finishes or timeouts.
       """
       handle = self.execute(request, batch=False)
-      operation_id = handle['history_uuid']
 
+      if handle['status'] != 0:
+        raise QueryError(e, message='SQL statement failed.', handle=handle)
+
+      operation_id = handle['history_uuid']
       curr = time.time()
       end = curr + timeout_sec
 
@@ -310,7 +313,7 @@ class Notebook(object):
         time.sleep(sleep_interval)
         curr = time.time()
 
-      # Query timed out
+      # TODO
       # msg = "The query timed out after %(timeout)d seconds, canceled query." % {'timeout': timeout_sec}
       # LOG.warning(msg)
       # try:

+ 2 - 2
desktop/libs/notebook/src/notebook/connectors/sql_alchemy.py

@@ -153,11 +153,11 @@ class SqlAlchemyApi(Api):
 
     return {
       'sync': False,
-      'has_result_set': True,
+      'has_result_set': result.cursor != None,
       'modified_row_count': 0,
       'guid': guid,
       'result': {
-        'has_more': True,
+        'has_more': result.cursor != None,
         'data': [],
         'meta': cache['meta'],
         'type': 'table'