Explorar o código

HUE-5661 [editor] Add skeleton of SQL assistant

Romain Rigaux %!s(int64=8) %!d(string=hai) anos
pai
achega
01c3947

+ 34 - 2
desktop/core/src/desktop/templates/assist.mako

@@ -2257,7 +2257,28 @@ from notebook.conf import ENABLE_QUERY_BUILDER
   </script>
 
   <script type="text/html" id="assistant-panel-template">
-    <pre data-bind="text: ko.mapping.toJSON(activeLocations)"></pre>
+    ${ _('Tables') }
+    <br/>
+    <ul data-bind="foreach: activeTables">
+      <li><span data-bind="text: $data"></span> <i class="fa fa-info"></i>
+    </ul>
+
+    <form class="form-horizontal">
+      <fieldset>
+        ${ _('Suggestions') }<br/>
+        <ul>
+          <li>Popular fields for the tables are: [code, salary, amount]</li>
+          <li>The query would run 2x faster by adding a WHERE date_f > '2017-01-01'</li>
+          <li>Parameterize the query?</li>
+        </ul>
+      </fieldset>
+    </form>
+
+    <!-- ko if: HAS_OPTIMIZER -->
+      <a href="javascript:void(0)" data-bind="click: function() { huePubSub.publish('editor.workload.upload'); }" title="${ _('Load past query history in order to improve recommendations') }">
+        <i class="fa fa-fw fa-cloud-upload"></i> ${_('Upload workload')}
+      </a>
+    <!-- /ko -->
   </script>
 
   <script type="text/javascript" charset="utf-8">
@@ -2272,7 +2293,18 @@ from notebook.conf import ENABLE_QUERY_BUILDER
         self.lastLocationsPerType = ko.observable({});
 
         self.activeLocations = ko.pureComputed(function () {
-          return self.lastLocationsPerType()[self.activeType()];
+          return self.lastLocationsPerType()[self.activeType()] ? self.lastLocationsPerType()[self.activeType()] : [];
+        });
+        self.activeTables = ko.pureComputed(function () {
+          var allTables = $.grep(self.activeLocations(), function(item) { return item.type == 'table'; });
+          var tables = [];
+          $.each(allTables, function(i, item) {
+            var tableName = item.identifierChain[item.identifierChain.length - 1].name;
+            if (tables.indexOf(tableName) == -1) {
+              tables.push(tableName);
+            }
+          });
+          return tables;
         });
 
         self.disposals.push(huePubSub.subscribe('active.snippet.type.changed', self.activeType).remove);

+ 5 - 1
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1444,6 +1444,10 @@ var EditorViewModel = (function() {
       });
     };
 
+    huePubSub.subscribe("editor.workload.upload", function () {
+      self.loadQueryHistory(10);
+    });
+
     self.loadQueryHistory = function (n) {
       logGA('load_query_history');
 
@@ -1452,7 +1456,7 @@ var EditorViewModel = (function() {
         sourcePlatform: self.type()
       }, function(data) {
         if (data.status == 0) {
-          $(document).trigger("info", "Queries uploaded successfully. Preparing them...");
+          $(document).trigger("info", "Queries uploaded successfully. Processing them...");
           self.watchUploadStatus(data.upload_history.status.workloadId);
         } else {
           $(document).trigger("error", data.message);

+ 1 - 6
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -2227,14 +2227,9 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
             <i class="fa fa-fw fa-comments"></i> ${_('Show similarities')}
           </a>
         </li>
-        <li>
-          <a href="javascript:void(0)" data-bind="click: function() { loadQueryHistory(null); }" title="${ _('Load past query history in order to improve recommendations') }">
-            <i class="fa fa-fw fa-cloud-upload"></i> ${_('Upload history')}
-          </a>
-        </li>
         <li>
           <a href="javascript:void(0)" data-bind="click: function() { loadQueryHistory(10); }" title="${ _('Load past query history in order to improve recommendations') }">
-            <i class="fa fa-fw fa-cloud-upload"></i> ${_('Upload last 10 history')}
+            <i class="fa fa-fw fa-cloud-upload"></i> ${_('Upload workload')}
           </a>
         </li>
         <!-- /ko -->

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

@@ -192,7 +192,7 @@ except ImportError, e:
         </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() { saveTarget('search-index'); savePath('__hue__'); trySaveResults(); }" 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('__hue__'); trySaveResults(); }" title="${ _('Explore result in a dashboard') }">
             <i class="fa fa-fw fa-area-chart"></i> ${ _('Dashboard') }
           </a>
         </li>