소스 검색

HUE-5857 [editor] Integrate automatic query compatibility check from any platform

Romain Rigaux 8 년 전
부모
커밋
87515178ea

+ 9 - 6
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -818,8 +818,15 @@ var EditorViewModel = (function() {
     self.complexityCheckRunning = ko.observable(false);
     self.complexityCheckRunning = ko.observable(false);
     self.compatibilityCheckRunning = ko.observable(false);
     self.compatibilityCheckRunning = ko.observable(false);
     self.compatibilitySourcePlatform = ko.observable(self.type());
     self.compatibilitySourcePlatform = ko.observable(self.type());
+    self.compatibilitySourcePlatform.subscribe(function(newValue) {
+      if (newValue != self.type()) {
+        self.hasSuggestion(null);
+        self.compatibilityTargetPlatform(self.type());
+        self.queryCompatibility();
+      }
+    });
     self.compatibilitySourcePlatforms = ko.observableArray([
     self.compatibilitySourcePlatforms = ko.observableArray([
-      {'name': 'Teradata', 'value': 'teradata'}, 
+      {'name': 'Teradata', 'value': 'teradata'},
       {'name': 'Oracle', 'value': 'oracle'},
       {'name': 'Oracle', 'value': 'oracle'},
       {'name': 'Netezza', 'value': 'netezza'},
       {'name': 'Netezza', 'value': 'netezza'},
       {'name': 'Impala', 'value': 'impala'},
       {'name': 'Impala', 'value': 'impala'},
@@ -1186,17 +1193,13 @@ var EditorViewModel = (function() {
       self.compatibilitySourcePlatform(self.type());
       self.compatibilitySourcePlatform(self.type());
       self.compatibilityTargetPlatform(self.type());
       self.compatibilityTargetPlatform(self.type());
 
 
-      self.queryCompatibility(); 
+      self.queryCompatibility();
     };
     };
 
 
     self.queryCompatibility = function (targetPlatform) {
     self.queryCompatibility = function (targetPlatform) {
       if (lastCompatibilityRequest && lastCompatibilityRequest.readyState < 4) {
       if (lastCompatibilityRequest && lastCompatibilityRequest.readyState < 4) {
         lastCompatibilityRequest.abort();
         lastCompatibilityRequest.abort();
       }
       }
-      
-      if (!targetPlatform) {
-      //  targetPlatform = self.compatibilityTargetPlatform(); 
-      }
 
 
       logGA('compatibility');
       logGA('compatibility');
       self.compatibilityCheckRunning(targetPlatform != self.type());
       self.compatibilityCheckRunning(targetPlatform != self.type());

+ 31 - 15
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1026,7 +1026,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
 
 <script type="text/html" id="code-editor-snippet-body">
 <script type="text/html" id="code-editor-snippet-body">
   <!-- ko if: HAS_OPTIMIZER -->
   <!-- ko if: HAS_OPTIMIZER -->
-  <div data-bind="css: { 'active': showOptimizer }, attr: { 'title': showOptimizer() ? '${ _ko('Close Validator') }' : '${ _ko('Open Validator') }'}">
+  <div data-bind="css: { 'active': showOptimizer }">
     <div class="round-icon empty">&nbsp;</div>
     <div class="round-icon empty">&nbsp;</div>
     <!-- ko if: hasSuggestion() == null -->
     <!-- ko if: hasSuggestion() == null -->
     <div class="round-icon idle">
     <div class="round-icon idle">
@@ -1037,40 +1037,56 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
     <!-- ko if: hasSuggestion() -->
     <!-- ko if: hasSuggestion() -->
       <!-- ko with: suggestion() -->
       <!-- ko with: suggestion() -->
         <!-- ko if: parseError -->
         <!-- ko if: parseError -->
-          <div class="round-icon error" data-bind="click: function(){ $parent.showOptimizer(! $parent.showOptimizer()) }">
-            <i class="fa fa-exclamation"></i>
-          </div>
-          <!-- ko if: $parent.showOptimizer -->
-          <span class="icon-explanation alert-error alert-neutral">${ _('The query has a parse error.') }</span>
+          <!-- ko if: $parent.compatibilityTargetPlatform() == $parent.type() && $parent.compatibilitySourcePlatform() == $parent.type() -->
+            <div class="round-icon error" data-bind="click: function(){ $parent.showOptimizer(! $parent.showOptimizer()) }, attr: { 'title': $parent.showOptimizer() ? '${ _ko('Close Validator') }' : '${ _ko('Open Validator') }'}">
+              <i class="fa fa-exclamation"></i>
+            </div>
+            <!-- ko if: $parent.showOptimizer -->
+              <span class="icon-explanation alert-error alert-neutral">${ _('The query has a parse error.') }</span>
+            <!-- /ko -->
+          <!-- /ko -->
+          ## Oracle, MySQL compatibility... as they return a parseError and not encounteredString.
+          <!-- ko if: $parent.compatibilityTargetPlatform() != $parent.type() || $parent.type() != $parent.compatibilitySourcePlatform() -->
+            <div class="round-icon warning" data-bind="click: function(){ $parent.showOptimizer(! $parent.showOptimizer()) }, attr: { 'title': $parent.showOptimizer() ? '${ _ko('Close Validator') }' : '${ _ko('Open Validator') }'}">
+              <i class="fa fa-exclamation"></i>
+            </div>
+            <!-- ko if: $parent.showOptimizer -->
+              <span class="icon-explanation alert-warning alert-neutral">${ _('This ') } <span data-bind="text: $parent.compatibilitySourcePlatform"></span> ${ _(' query is not compatible with ') } <span data-bind="text: $parent.compatibilityTargetPlatform"></span>.</span>
+            <!-- /ko -->
           <!-- /ko -->
           <!-- /ko -->
         <!-- /ko -->
         <!-- /ko -->
-        <!-- ko if: !parseError() && $parent.compatibilityTargetPlatform() != $parent.type() -->
+        <!-- ko if: !parseError() && ($parent.compatibilityTargetPlatform() != $parent.type() || $parent.compatibilitySourcePlatform() != $parent.type()) -->
           <!-- ko if: queryError.encounteredString().length == 0 -->
           <!-- ko if: queryError.encounteredString().length == 0 -->
-            <div class="round-icon success" data-bind="click: function(){ $parent.showOptimizer(! $parent.showOptimizer()) }">
+            <div class="round-icon success" data-bind="click: function(){ $parent.showOptimizer(! $parent.showOptimizer()) }, attr: { 'title': $parent.showOptimizer() ? '${ _ko('Close Validator') }' : '${ _ko('Open Validator') }'}">
               <i class="fa fa-check"></i>
               <i class="fa fa-check"></i>
             </div>
             </div>
             <!-- ko if: $parent.showOptimizer -->
             <!-- ko if: $parent.showOptimizer -->
             <span class="icon-explanation alert-success alert-neutral">
             <span class="icon-explanation alert-success alert-neutral">
               ${ _('The ') } <select data-bind="options: $parent.compatibilitySourcePlatforms, optionsText: 'name', value: $parent.compatibilitySourcePlatform, optionsValue: 'value'" class="input-medium"></select>
               ${ _('The ') } <select data-bind="options: $parent.compatibilitySourcePlatforms, optionsText: 'name', value: $parent.compatibilitySourcePlatform, optionsValue: 'value'" class="input-medium"></select>
-              ${ _(' query is compatible with ') } <select data-bind="options: $parent.compatibilityTargetPlatforms, optionsText: 'name', value: $parent.compatibilityTargetPlatform, optionsValue: 'value'" class="input-medium"></select>. 
-              <a href="javascript:void(0)" data-bind="click: function() { $parent.type($parent.compatibilityTargetPlatform()); }">${ _('Execute it with ') } <span data-bind="text: $parent.compatibilityTargetPlatform"></span></a>.
+              <!-- ko if: $parent.compatibilitySourcePlatform() == $parent.type() -->
+                ${ _(' query is compatible with ') } <span data-bind="text: $parent.compatibilityTargetPlatform"></span>.
+                <a href="javascript:void(0)" data-bind="click: function() { $parent.type($parent.compatibilityTargetPlatform()); }">${ _('Execute it with ') } <span data-bind="text: $parent.compatibilityTargetPlatform"></span></a>.
+              <!-- /ko -->
+              <!-- ko if: $parent.compatibilitySourcePlatform() != $parent.type() -->
+                ${ _(' query is compatible with ') } <span data-bind="text: $parent.compatibilityTargetPlatform"></span>.
+              <!-- /ko -->
             </span>
             </span>
           <!-- /ko -->
           <!-- /ko -->
         <!-- /ko -->
         <!-- /ko -->
         <!-- ko ifnot: queryError.encounteredString().length == 0 -->
         <!-- ko ifnot: queryError.encounteredString().length == 0 -->
-          <div class="round-icon warning" data-bind="click: function(){ $parent.showOptimizer(! $parent.showOptimizer()) }">
+          <div class="round-icon warning" data-bind="click: function(){ $parent.showOptimizer(! $parent.showOptimizer()) }, attr: { 'title': $parent.showOptimizer() ? '${ _ko('Close Validator') }' : '${ _ko('Open Validator') }'}">
             <i class="fa fa-exclamation"></i>
             <i class="fa fa-exclamation"></i>
           </div>
           </div>
           <!-- ko if: $parent.showOptimizer -->
           <!-- ko if: $parent.showOptimizer -->
-            <span class="icon-explanation alert-warning alert-neutral">${ _('This query is not compatible with Impala.') }</span>
+            <span class="icon-explanation alert-warning alert-neutral">${ _('This query is not compatible with ') } <span data-bind="text: $parent.compatibilityTargetPlatform"></span>.</span>
           <!-- /ko -->
           <!-- /ko -->
         <!-- /ko -->
         <!-- /ko -->
       <!-- /ko -->
       <!-- /ko -->
       <!-- /ko -->
       <!-- /ko -->
     <!-- /ko -->
     <!-- /ko -->
-    <!-- ko if: hasComplexity() && hasSuggestion() && compatibilityTargetPlatform() === type() && suggestion() && !suggestion().parseError() -->
+    <!-- ko if: hasComplexity() && hasSuggestion() && compatibilitySourcePlatform() === type() && compatibilityTargetPlatform() === type() && suggestion() && !suggestion().parseError() -->
       <!-- ko if: complexity() && complexity().risk() && (complexity().risk().length === 0 || complexity().risk() === 'low') -->
       <!-- ko if: complexity() && complexity().risk() && (complexity().risk().length === 0 || complexity().risk() === 'low') -->
-        <div class="round-icon success" data-bind="click: function(){ $root.showOptimizer(! $root.showOptimizer()) }">
+        <div class="round-icon success" data-bind="click: function(){ showOptimizer(! showOptimizer()) }, attr: { 'title': showOptimizer() ? '${ _ko('Close Validator') }' : '${ _ko('Open Validator') }'}">
           <i class="fa fa-check"></i>
           <i class="fa fa-check"></i>
         </div>
         </div>
         <!-- ko if: showOptimizer -->
         <!-- ko if: showOptimizer -->
@@ -1078,7 +1094,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         <!-- /ko -->
         <!-- /ko -->
       <!-- /ko -->
       <!-- /ko -->
       <!-- ko if: complexity() && complexity().risk() && complexity().risk() === 'high' -->
       <!-- ko if: complexity() && complexity().risk() && complexity().risk() === 'high' -->
-        <div class="round-icon error" data-bind="click: function(){ $root.showOptimizer(! $root.showOptimizer()) }">
+        <div class="round-icon error" data-bind="click: function(){ showOptimizer(! showOptimizer()) }">
           <i class="fa fa-exclamation"></i>
           <i class="fa fa-exclamation"></i>
         </div>
         </div>
         <!-- ko if: showOptimizer -->
         <!-- ko if: showOptimizer -->