Эх сурвалжийг харах

HUE-2961 [editor] Direct link to export SQL result to Dashboard

Romain Rigaux 9 жил өмнө
parent
commit
65ccc29

+ 4 - 0
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -286,3 +286,7 @@ class Api(object):
   def statement_compatibility(self, notebook, snippet, source_platform, target_platform): raise NotImplementedError()
 
   def statement_similarity(self, notebook, snippet, source_platform, target_platform): raise NotImplementedError()
+
+
+def _get_snippet_name(notebook):
+  return ('%(name)s' if notebook.get('name') else '%(type)s-%(id)s') % notebook

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

@@ -35,7 +35,7 @@ from desktop.lib.rest.http_client import RestException
 from desktop.models import DefaultConfiguration
 from metadata.optimizer_client import OptimizerApi
 
-from notebook.connectors.base import Api, QueryError, QueryExpired, OperationTimeout, OperationNotSupported
+from notebook.connectors.base import Api, QueryError, QueryExpired, OperationTimeout, OperationNotSupported, _get_snippet_name
 
 
 LOG = logging.getLogger(__name__)
@@ -350,10 +350,7 @@ class HS2Api(Api):
       # Test handle to verify if still valid
       db.fetch(handle, start_over=True, rows=1)
 
-      if notebook.get('name'):
-        file_name = '%(name)s' % notebook
-      else:
-        file_name = '%(type)s-%(id)s' % notebook
+      file_name = _get_snippet_name(notebook)
 
       return data_export.download(handle, format, db, id=snippet['id'], file_name=file_name)
     except Exception, e:

+ 6 - 6
desktop/libs/notebook/src/notebook/templates/notebook_ko_components.mako

@@ -190,18 +190,18 @@ except ImportError, e:
             <i class="fa fa-fw fa-file-excel-o"></i> ${ _('Excel') }
           </a>
         </li>
-        <li>
-          <a class="inactive-action download" href="javascript:void(0)" data-bind="click: function() { $('#saveResultsModal').modal('show'); }" title="${ _('Save the result in a file, a new table...') }">
-            <i class="fa fa-fw fa-save"></i> ${ _('Export') }
-          </a>
-        </li>
         % if hasattr(ENABLE_NEW_INDEXER, 'get') and ENABLE_NEW_INDEXER.get():
         <li>
-          <a class="inactive-action download" href="javascript:void(0)" data-bind="click: function() { $('#saveResultsModal').modal('show'); }" title="${ _('Explore the result in an analytic dashboard') }">
+          <a class="inactive-action download" href="javascript:void(0)" data-bind="click: function() { saveTarget('search-index'); savePath(''); trySaveResults(); }" title="${ _('Explore the result in an analytic dashboard') }">
             <i class="fa fa-fw fa-area-chart"></i> ${ _('Dashboard') }
           </a>
         </li>
         % endif
+        <li>
+          <a class="inactive-action download" href="javascript:void(0)" data-bind="click: function() { $('#saveResultsModal').modal('show'); }" title="${ _('Save the result in a file, a new table...') }">
+            <i class="fa fa-fw fa-save"></i> ${ _('Save') }
+          </a>
+        </li>
       </ul>
     </div>
 

+ 8 - 2
desktop/libs/notebook/src/notebook/views.py

@@ -32,7 +32,7 @@ from desktop.models import Document2, Document
 from metadata.conf import has_optimizer, has_navigator
 
 from notebook.conf import get_ordered_interpreters
-from notebook.connectors.base import Notebook, get_api
+from notebook.connectors.base import Notebook, get_api, _get_snippet_name
 from notebook.connectors.spark_shell import SparkApi
 from notebook.decorators import check_document_access_permission, check_document_modify_permission
 from notebook.management.commands.notebook_setup import Command
@@ -90,10 +90,12 @@ def notebook(request, is_embeddable=False):
       'is_yarn_mode': is_yarn_mode,
   })
 
+
 @check_document_access_permission()
 def notebook_embeddable(request):
   return notebook(request, True)
 
+
 @check_document_access_permission()
 def editor(request, is_mobile=False, is_embeddable=False):
   editor_id = request.GET.get('editor')
@@ -123,10 +125,12 @@ def editor(request, is_mobile=False, is_embeddable=False):
       })
   })
 
+
 @check_document_access_permission()
 def editor_embeddable(request):
   return editor(request, False, True)
 
+
 @check_document_access_permission()
 def editor_m(request):
   return editor(request, True)
@@ -174,12 +178,14 @@ def execute_and_watch(request):
     sql, success_url = api.export_large_data_to_hdfs(notebook, snippet, destination)
     editor = make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready-execute', database=snippet['database'])
   elif action == 'index_query':
+    if not destination:
+      destination = _get_snippet_name(notebook)
     sql, success_url = api.export_data_as_table(notebook, snippet, destination, is_temporary=True, location='')
     editor = make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready-execute')
 
     sample = get_api(request, snippet).fetch_result(notebook, snippet, 0, start_over=True)
 
-    from indexer.api3 import _index # Will ve moved to the lib in next commit
+    from indexer.api3 import _index # Will ve moved to the lib
     from indexer.file_format import HiveFormat
     from indexer.fields import Field