Przeglądaj źródła

HUE-4031 [editor] Warn when an unknown table is found in the query

Johan Ahlen 8 lat temu
rodzic
commit
0b18470

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue.css


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue3-extra.css


+ 1 - 1
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -1315,7 +1315,7 @@ var ApiHelper = (function () {
     var self = this;
     var identifierChainClone = options.identifierChain.concat();
     var path = [];
-    if (! self.containsDatabase(options.sourceType, identifierChainClone[0].name)) {
+    if (identifierChainClone.length === 0 || ! self.containsDatabase(options.sourceType, identifierChainClone[0].name)) {
       path.push(options.defaultDatabase);
     } else {
       path.push(identifierChainClone.shift().name)

+ 60 - 4
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -3568,7 +3568,7 @@
     AceLocationHandler.prototype.clearMarkedErrors = function () {
       var self = this;
       for (var marker in self.editor.session.$backMarkers) {
-        if (self.editor.session.$backMarkers[marker].clazz === 'hue-ace-syntax-error') {
+        if (self.editor.session.$backMarkers[marker].clazz.indexOf('hue-ace-syntax-') === 0) {
           var token = self.editor.session.$backMarkers[marker].token;
           delete token.syntaxError;
           self.editor.session.removeMarker(self.editor.session.$backMarkers[marker].id);
@@ -3622,6 +3622,52 @@
       self.clearMarkedErrors();
     };
 
+    AceLocationHandler.prototype.verifyExists = function (token) {
+      var self = this;
+
+      // the syntax worker is only defined when syntax check is on
+      // TODO: Only do this when browser caching is turned on
+      if (self.aceSqlSyntaxWorker && token.parseLocation && token.parseLocation.identifierChain) {
+        // We want to check the parent to see if it contains the entry for performance, as opposed to checking
+        // each entry with the API.
+        ApiHelper.getInstance().fetchAutocomplete({
+          sourceType: self.snippet.type(),
+          identifierChain: token.parseLocation.identifierChain.slice(0, token.parseLocation.identifierChain.length - 1),
+          defaultDatabase: self.snippet.database(),
+          silenceErrors: true,
+          errorCallback: function (data) {
+            console.log('error');
+            console.log(data);
+          },
+          successCallback: function (data) {
+            if (token.parseLocation.type === 'table' && data.tables_meta) {
+              var tableLowerCase = token.value.toLowerCase();
+              for (var i = 0; i < data.tables_meta.length; i++) {
+                if (data.tables_meta[i].name.toLowerCase() === tableLowerCase) {
+                  break;
+                }
+                if (i + 1 === data.tables_meta.length) {
+                  token.notFound = true;
+                  ApiHelper.getInstance().identifierChainToPath({
+                    identifierChain: token.parseLocation.identifierChain,
+                    sourceType: self.snippet.type(),
+                    defaultDatabase: self.snippet.database()
+                  }, function (path) {
+                    token.notFound = true;
+                    token.qualifiedIdentifier = path.join('.');
+                    var AceRange = ace.require('ace/range').Range;
+                    var range = new AceRange(token.parseLocation.location.first_line - 1, token.parseLocation.location.first_column - 1, token.parseLocation.location.last_line - 1, token.parseLocation.location.last_column - 1);
+                    var markerId = self.editor.session.addMarker(range, 'hue-ace-syntax-warning');
+                    self.editor.session.$backMarkers[markerId].token = token;
+                  })
+                }
+              }
+            }
+          }
+        });
+      }
+    };
+
     AceLocationHandler.prototype.attachSqlWorker = function () {
       var self = this;
 
@@ -3703,6 +3749,7 @@
                           delete location.tables;
                           token.parseLocation = location;
                           activeTokens.push(token);
+                          self.verifyExists(token);
                         } else if (tablesToGo.length > 0) {
                           findIdentifierChainInTable(tablesToGo);
                         }
@@ -3724,6 +3771,7 @@
             } else {
               token.parseLocation = location;
               activeTokens.push(token);
+              self.verifyExists(token);
             }
           }
         });
@@ -4142,7 +4190,7 @@
             var endTestPosition = editor.renderer.screenToTextCoordinates(e.clientX + 15, e.clientY);
             if (endTestPosition.column !== pointerPosition.column) {
               var token = editor.session.getTokenAt(pointerPosition.row, pointerPosition.column);
-              if (token !== null && token.parseLocation && !disableTooltip) {
+              if (token !== null && !token.notFound && token.parseLocation && !disableTooltip) {
                 tooltipTimeout = window.setTimeout(function () {
                   var endCoordinates = editor.renderer.textToScreenCoordinates(pointerPosition.row, token.start);
 
@@ -4156,8 +4204,16 @@
                   }
                   contextTooltip.show(tooltipText, endCoordinates.pageX, endCoordinates.pageY + editor.renderer.lineHeight + 3);
                 }, 500);
+              } else if (token !== null && token.notFound) {
+                tooltipTimeout = window.setTimeout(function () {
+                  // TODO: i18n
+                  var tooltipText = 'Could not find ' + (token.qualifiedIdentifier || token.value) + '';
+                  var endCoordinates = editor.renderer.textToScreenCoordinates(pointerPosition.row, token.start);
+                  contextTooltip.show(tooltipText, endCoordinates.pageX, endCoordinates.pageY + editor.renderer.lineHeight + 3);
+                }, 500);
               } else if (token !== null && token.syntaxError) {
                 tooltipTimeout = window.setTimeout(function () {
+                  // TODO: i18n
                   var tooltipText = 'Did you mean "' + token.syntaxError.expected[0].text + '"?';
                   var endCoordinates = editor.renderer.textToScreenCoordinates(pointerPosition.row, token.start);
                   contextTooltip.show(tooltipText, endCoordinates.pageX, endCoordinates.pageY + editor.renderer.lineHeight + 3);
@@ -4167,7 +4223,7 @@
               }
               if (lastHoveredToken !== token) {
                 clearActiveMarkers();
-                if (token !== null && token.parseLocation) {
+                if (token !== null && !token.notFound && token.parseLocation) {
                   markLocation(token.parseLocation);
                 }
                 lastHoveredToken = token;
@@ -4224,7 +4280,7 @@
                 bottom: endCoordinates.pageY + editor.renderer.lineHeight
               };
 
-              if (token.parseLocation) {
+              if (token.parseLocation && !token.notFound) {
                 huePubSub.publish('sql.context.popover.show', {
                   data: token.parseLocation,
                   sourceType: snippet.type(),

+ 7 - 1
desktop/core/src/desktop/static/desktop/less/hue-cross-version.less

@@ -182,7 +182,13 @@ input[type='password']::-ms-reveal {
 
 .hue-ace-syntax-error {
   position: absolute;
-  border-bottom: 1px dotted #FF0000;
+  border-bottom: 1px dotted @hue-error-color;
+  border-radius: 0 !important;
+}
+
+.hue-ace-syntax-warning {
+  position: absolute;
+  border-bottom: 1px dotted @hue-warning-color;
   border-radius: 0 !important;
 }
 

+ 1 - 0
desktop/core/src/desktop/static/desktop/less/hue-mixins.less

@@ -31,6 +31,7 @@
 
 @hue-disabled-color: @cui-gray-100;
 @hue-error-color: @cui-red-400;
+@hue-warning-color: @cui-orange-400;
 
 @hue-panel-border-radius: 2px;
 

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików