فهرست منبع

HUE-2142 [editor] Convert saving to a directory of result data to the task framework

Romain Rigaux 8 سال پیش
والد
کامیت
ccdd711

+ 2 - 2
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -115,7 +115,7 @@ from filebrowser.conf import ENABLE_EXTRACT_UPLOADED_ARCHIVE
     </div>
     <div class="modal-footer">
       <a class="btn" data-dismiss="modal">${_('No')}</a>
-      <input type="submit" value="${_('Yes')}" class="btn btn-danger" data-bind="click: extractSelectedArchive"/>
+      <input type="submit" value="${_('Yes')}" class="btn btn-primary" data-bind="click: extractSelectedArchive"/>
     </div>
     <!-- /ko -->
   </div>
@@ -137,7 +137,7 @@ from filebrowser.conf import ENABLE_EXTRACT_UPLOADED_ARCHIVE
     </div>
     <div class="modal-footer">
       <a class="btn" data-dismiss="modal">${_('No')}</a>
-      <input type="submit" value="${_('Yes')}" class="btn btn-danger" data-bind="click: compressSelectedFiles"/>
+      <input type="submit" value="${_('Yes')}" class="btn btn-primary" data-bind="click: compressSelectedFiles"/>
     </div>
     <!-- /ko -->
   </div>

+ 18 - 5
desktop/core/src/desktop/templates/common_notebook_ko_components.mako

@@ -358,13 +358,26 @@ except ImportError, e:
             snippet: ko.mapping.toJSON(self.snippet.getContext()),
             format: ko.mapping.toJSON(self.saveTarget()),
             destination: ko.mapping.toJSON(self.savePath()),
-            overwrite: ko.mapping.toJSON(self.saveOverwrite())
+            overwrite: ko.mapping.toJSON(self.saveOverwrite()),
+            is_embedded: ko.mapping.toJSON(IS_HUE_4),
           },
-          function(data) {
-            if (data.status == 0) {
-              window.location.href = data.watch_url;
+          function(resp) {
+            if (resp.status == 0) {
+              if (IS_HUE_4) {
+                if (self.saveTarget() == '') {
+                  huePubSub.publish('open.fb.folder', resp.watch_url.replace(/\/filebrowser\/view=/g, ''));
+                } else {
+                  if (resp.history_uuid) {
+                    huePubSub.publish('notebook.task.submitted', resp.history_uuid);
+                  } else if (resp && resp.message) {
+                    $(document).trigger("error", resp.message);
+                  }
+                }
+              } else {
+                window.location.href = resp.watch_url;
+              }
             } else {
-              $(document).trigger('error', data.message);
+              $(document).trigger('error', resp.message);
             }
           }).fail(function (xhr, textStatus, errorThrown) {
             $(document).trigger("error", xhr.responseText);

+ 20 - 5
desktop/libs/notebook/src/notebook/api.py

@@ -31,7 +31,7 @@ from desktop.models import Document2, Document
 
 from notebook.connectors.base import get_api, Notebook, QueryExpired, SessionExpired, QueryError
 from notebook.decorators import api_error_handler, check_document_access_permission, check_document_modify_permission
-from notebook.models import escape_rows
+from notebook.models import escape_rows, make_notebook
 from notebook.views import upgrade_session_properties
 
 
@@ -622,10 +622,11 @@ def export_result(request):
   data_format = json.loads(request.POST.get('format', 'hdfs-file'))
   destination = json.loads(request.POST.get('destination', ''))
   overwrite = json.loads(request.POST.get('overwrite', False))
+  is_embedded = json.loads(request.POST.get('is_embedded', False))
 
   api = get_api(request, snippet)
 
-  if data_format == 'hdfs-file':
+  if data_format == 'hdfs-file': # Blocking operation, like downloading
     if request.fs.isdir(destination):
       if notebook.get('name'):
         destination += '/%(name)s.csv' % notebook
@@ -640,9 +641,23 @@ def export_result(request):
     response['watch_url'] = reverse('notebook:execute_and_watch') + '?action=save_as_table&notebook=' + str(notebook_id) + '&snippet=0&destination=' + destination
     response['status'] = 0
   elif data_format == 'hdfs-directory':
-    notebook_id = notebook['id'] or request.GET.get('editor', request.GET.get('notebook'))
-    response['watch_url'] = reverse('notebook:execute_and_watch') + '?action=insert_as_query&notebook=' + str(notebook_id) + '&snippet=0&destination=' + destination
-    response['status'] = 0
+    if is_embedded:
+      sql, success_url = api.export_large_data_to_hdfs(notebook, snippet, destination)
+
+      task = make_notebook(
+        name='Execute and watch',
+        editor_type=snippet['type'],
+        statement=sql,
+        status='ready-execute',
+        database=snippet['database'],
+        on_success_url=success_url,
+        is_task=True
+      )
+      response = task.execute(request)
+    else:
+      notebook_id = notebook['id'] or request.GET.get('editor', request.GET.get('notebook'))
+      response['watch_url'] = reverse('notebook:execute_and_watch') + '?action=insert_as_query&notebook=' + str(notebook_id) + '&snippet=0&destination=' + destination
+      response['status'] = 0
   elif data_format == 'search-index':
     notebook_id = notebook['id'] or request.GET.get('editor', request.GET.get('notebook'))
     response['watch_url'] = reverse('notebook:execute_and_watch') + '?action=index_query&notebook=' + str(notebook_id) + '&snippet=0&destination=' + destination