Bläddra i källkod

HUE-7 [metastore] Add support for creating database via the importer

Romain Rigaux 9 år sedan
förälder
incheckning
b4780b7181

+ 7 - 1
apps/metastore/src/metastore/templates/metastore.mako

@@ -552,7 +552,13 @@ ${ components.menubar() }
   <div class="inline-block pull-right">
     <a class="inactive-action" href="javascript:void(0)" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: function () { huePubSub.publish('assist.db.refresh', { sourceType: 'hive' }); }"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : $root.reloading }" title="${_('Refresh')}"></i></a>
     % if has_write_access:
-    <a class="inactive-action margin-left-10" data-bind="tooltip: { placement: 'bottom', delay: 750 }" href="${ url('beeswax:create_database') }" title="${_('Create a new database')}"><i class="fa fa-plus"></i></a>
+      % if is_embeddable:
+        <a class="inactive-action margin-left-10" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: function () { onePageViewModel.currentApp('importer') }" title="${_('Create a new database')}"><i class="fa fa-plus"></i></a>
+      % elif ENABLE_NEW_CREATE_TABLE.get():
+        <a class="inactive-action margin-left-10" data-bind="tooltip: { placement: 'bottom', delay: 750 }, attr: { 'href': '${ url('indexer:importer_prefill', source_type='manual', target_type='database') }' }" title="${_('Create a new database')}"><i class="fa fa-plus"></i></a>
+      % else:
+        <a class="inactive-action margin-left-10" data-bind="tooltip: { placement: 'bottom', delay: 750 }" href="${ url('beeswax:create_database') }" title="${_('Create a new database')}"><i class="fa fa-plus"></i></a>
+      % endif
     % endif
   </div>
 </script>

+ 3 - 3
desktop/libs/indexer/src/indexer/api3.py

@@ -325,10 +325,10 @@ def _create_table_from_a_file(request, source, destination):
         'table_name': table_name
     }
 
-    editor_type = 'impala' if table_format == 'kudu' else 'hive'
-    on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': table_name})
+  editor_type = 'impala' if table_format == 'kudu' else 'hive'
+  on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': table_name})
 
-    return make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready', database=database, on_success_url=on_success_url)
+  return make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready', database=database, on_success_url=on_success_url)
 
 
 def _index(request, file_format, collection_name, query=None):

+ 15 - 5
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -325,7 +325,7 @@ ${ assist.assistPanel() }
         </label>
 
         <label for="collectionName" class="control-label"><div>${ _('Name') }</div>
-          <!-- ko if: ouputFormat() != 'table' || ouputFormat() != 'database' -->
+          <!-- ko if: ouputFormat() != 'table' && ouputFormat() != 'database' -->
             <input type="text" class="form-control input-xlarge" id="collectionName" data-bind="value: name, valueUpdate: 'afterkeydown'" placeholder="${ _('Name') }">
           <!-- /ko -->
 
@@ -882,6 +882,9 @@ ${ assist.assistPanel() }
             {'value': 'file', 'name': 'File'},
             {'value': 'manual', 'name': 'Manually'},
         ]);
+        if (wizard.prefill.source_type() == 'manual') {
+          self.inputFormat(wizard.prefill.source_type());
+        }
       }
 
       // File
@@ -964,12 +967,14 @@ ${ assist.assistPanel() }
           if (self.query()) {
             name = val.name();
           }
+        } else if (self.inputFormat() == 'manual') {
+          name = '.';
         }
 
         return name.replace(' ', '_');
       });
       self.defaultName.subscribe(function(newVal) {
-        var prefix = wizard.prefill.target_path ? wizard.prefill.target_path() + '.' : '';
+        var prefix = wizard.prefill.target_path ? wizard.prefill.target_path() + (newVal == '.' ? '' : '.') : '';
         vm.createWizard.destination.name(prefix + newVal);
       });
     };
@@ -998,6 +1003,12 @@ ${ assist.assistPanel() }
           return true;
         })
       });
+      if (wizard.prefill.target_type) {
+        self.ouputFormat(wizard.prefill.target_type());
+        if (wizard.prefill.target_type() == 'database') {
+          vm.currentStep(2);
+        };
+      }
 
       self.format = ko.observable();
       self.columns = ko.observableArray();
@@ -1012,7 +1023,6 @@ ${ assist.assistPanel() }
           {'value': 'orc', 'name': 'ORC'},
           {'value': 'avro', 'name': 'Avro'}
       ]);
-      self.ouputFormat = ko.observable('table');
 
       self.partitionColumns = ko.observableArray();
       self.kuduPartitionColumns = ko.observableArray();
@@ -1294,12 +1304,12 @@ ${ assist.assistPanel() }
       });
       self.nextStep = function () {
         if (self.nextStepVisible()){
-          self.currentStep(self.currentStep()+1);
+          self.currentStep(self.currentStep() + 1);
         }
       }
       self.previousStep = function () {
         if (self.previousStepVisible()){
-          self.currentStep(self.currentStep()-1);
+          self.currentStep(self.currentStep() - 1);
         }
       }