Răsfoiți Sursa

HUE-3450 [editor] Plugin query compatibility API

Romain Rigaux 9 ani în urmă
părinte
comite
257cf6e3de

+ 8 - 3
desktop/libs/metadata/src/metadata/optimizer_api.py

@@ -121,9 +121,14 @@ def query_compatibility(request):
   query = request.POST.get('query')
   query = request.POST.get('query')
 
 
   api = OptimizerApi()
   api = OptimizerApi()
-
-  response['query_compatibility'] = api.query_compatibility(source_platform=source_platform, target_platform=target_platform, query=query)
-  response['status'] = 0
+  
+  data = api.query_compatibility(source_platform=source_platform, target_platform=target_platform, query=query)
+  
+  if data['status'] == 'success':
+    response['status'] = 0
+    response['query_compatibility'] = json.loads(data['details'])
+  else:
+    response['message'] = 'Optimizer: %s' % data['details']
 
 
   return JsonResponse(response)
   return JsonResponse(response)
 
 

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

@@ -372,6 +372,7 @@
     this.delayedStatement = ko.pureComputed(self.statement).extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 2000 } });
     this.delayedStatement = ko.pureComputed(self.statement).extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 2000 } });
     this.delayedStatement.subscribe(function (val) {
     this.delayedStatement.subscribe(function (val) {
       self.getComplexity();
       self.getComplexity();
+      self.hasSuggestion(false);
     }, this);
     }, this);
 
 
     self.result = new Result(snippet, snippet.result);
     self.result = new Result(snippet, snippet.result);
@@ -432,6 +433,9 @@
       return self.complexity().length > 0;
       return self.complexity().length > 0;
     });
     });
 
 
+    self.suggestion = ko.observable(typeof snippet.complexity != "undefined" && snippet.complexity != null ? snippet.complexity : '');
+    self.hasSuggestion = ko.observable(false);
+
     self.chartType = ko.observable(typeof snippet.chartType != "undefined" && snippet.chartType != null ? snippet.chartType : ko.HUE_CHARTS.TYPES.BARCHART);
     self.chartType = ko.observable(typeof snippet.chartType != "undefined" && snippet.chartType != null ? snippet.chartType : ko.HUE_CHARTS.TYPES.BARCHART);
     self.chartSorting = ko.observable(typeof snippet.chartSorting != "undefined" && snippet.chartSorting != null ? snippet.chartSorting : "none");
     self.chartSorting = ko.observable(typeof snippet.chartSorting != "undefined" && snippet.chartSorting != null ? snippet.chartSorting : "none");
     self.chartScatterGroup = ko.observable(typeof snippet.chartScatterGroup != "undefined" && snippet.chartScatterGroup != null ? snippet.chartScatterGroup : null);
     self.chartScatterGroup = ko.observable(typeof snippet.chartScatterGroup != "undefined" && snippet.chartScatterGroup != null ? snippet.chartScatterGroup : null);
@@ -664,13 +668,17 @@
     }
     }
 
 
     self.queryCompatibility = function () {
     self.queryCompatibility = function () {
+      logGA('compatibility');
+      self.suggestion(false);
+
       $.post("/metadata/api/optimizer_api/query_compatibility", {
       $.post("/metadata/api/optimizer_api/query_compatibility", {
         query: self.statement(),
         query: self.statement(),
         sourcePlatform: self.type(),
         sourcePlatform: self.type(),
         targetPlatform: 'impala'
         targetPlatform: 'impala'
       }, function(data) {
       }, function(data) {
         if (data.status == 0) {
         if (data.status == 0) {
-       	 $(document).trigger("info", data.query_compatibility);
+         self.suggestion(ko.mapping.fromJS(data.query_compatibility.platformCompilationStatus.Impala));	
+         self.hasSuggestion(true);
         } else {
         } else {
           $(document).trigger("error", data.message);
           $(document).trigger("error", data.message);
         }
         }

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

@@ -674,7 +674,39 @@ ${ hueIcons.symbols() }
         <use xlink:href="#hi-warning"></use>
         <use xlink:href="#hi-warning"></use>
       </svg>
       </svg>
     </div>
     </div>
-    <div style="margin-left: 30px; line-height:20px;vertical-align: middle;"><span style="margin-right:10px; font-weight: bold;" data-bind="text: complexityLevel"></span><span data-bind="text: complexity"></span></div>
+    <div style="margin-left: 30px; line-height:20px;vertical-align: middle;">
+      <span style="margin-right:10px; font-weight: bold;" data-bind="text: complexityLevel"></span><span data-bind="text: complexity"></span>
+    </div>
+  </div>
+  <div class="alert" data-bind="visible: hasSuggestion">
+    <div style="float:left;">
+      <svg class="hi" style="height: 20px; width: 20px;">
+        <use xlink:href="#hi-warning"></use>
+      </svg>
+    </div>
+    <div style="margin-left: 30px; line-height:20px;vertical-align: middle;">
+      <!-- ko if: hasSuggestion -->
+      <!-- ko with: suggestion() -->
+      <!-- ko if: queryStatus() == 'SUCCESS' -->
+        ${ _('The query is compatible! Click to') } <a href="">${ _('execute') }</a> ${ _('with Impala') }.
+      <!-- /ko -->
+      <!-- ko if: errorDetail.errorString -->
+        ${ _('Query is not compatible with Impala') }.
+        </br>
+        <span style="font-weight: bold;"></span><span data-bind="text: errorDetail.errorString"></span>
+      <!-- /ko -->
+      <!-- ko if: clauseStatus.From -->
+        </br>
+        <!-- ko if: clauseStatus.From.category -->
+          <span style="font-weight: bold;"></span><span data-bind="text: clauseStatus.From.category"></span>
+        <!-- /ko -->
+        <!-- ko if: clauseStatus.From.suggestedFix -->
+          <span style="font-weight: bold;"></span><span data-bind="text: clauseStatus.From.suggestedFix"></span>
+        <!-- /ko -->
+      <!-- /ko -->
+      <!-- /ko -->
+      <!-- /ko -->
+    </div>
   </div>
   </div>
   <div class="row-fluid" style="margin-bottom: 5px">
   <div class="row-fluid" style="margin-bottom: 5px">
     <div class="editor span12" data-bind="css: {'single-snippet-editor ace-container-resizable' : $root.editorMode }, clickForAceFocus: ace">
     <div class="editor span12" data-bind="css: {'single-snippet-editor ace-container-resizable' : $root.editorMode }, clickForAceFocus: ace">