瀏覽代碼

HUE-7286 [editor] Show column type in the hover tooltip if the details of the column is cached

Johan Ahlen 8 年之前
父節點
當前提交
438d5be

+ 13 - 2
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -1448,6 +1448,7 @@ var ApiHelper = (function () {
    * @param {Function} [options.errorCallback]
    * @param {boolean} [options.silenceErrors]
    * @param {Number} [options.timeout]
+   * @param {boolean} [options.cachedOnly] - Default false
    * @param {Object} [options.editor] - Ace editor
    *
    * @param {string} options.databaseName
@@ -1469,7 +1470,7 @@ var ApiHelper = (function () {
     return typeof self.lastKnownDatabases[sourceType] !== 'undefined' && self.lastKnownDatabases[sourceType].indexOf(databaseName.toLowerCase()) > -1;
   };
 
-  ApiHelper.prototype.expandComplexIdentifierChain = function (sourceType, database, identifierChain, successCallback, errorCallback) {
+  ApiHelper.prototype.expandComplexIdentifierChain = function (sourceType, database, identifierChain, successCallback, errorCallback, cachedOnly) {
     var self = this;
 
     var fetchFieldsInternal =  function (table, database, identifierChain, callback, errorCallback, fetchedFields) {
@@ -1494,6 +1495,7 @@ var ApiHelper = (function () {
         tableName: table,
         fields: fetchedFields,
         timeout: self.timeout,
+        cachedOnly: cachedOnly,
         successCallback: function (data) {
           if (sourceType === 'hive'
               && typeof data.extended_columns !== 'undefined'
@@ -1536,6 +1538,7 @@ var ApiHelper = (function () {
    * @param {Object[]} options.identifierChain
    * @param {string} options.identifierChain.name
    * @param {string} options.defaultDatabase
+   * @param {boolean} [options.cachedOnly] - Default false
    *
    * @param {function} successCallback
    */
@@ -1552,7 +1555,7 @@ var ApiHelper = (function () {
     if (identifierChainClone.length > 1) {
       self.expandComplexIdentifierChain(options.sourceType, path[0], identifierChainClone, function (fetchedFields) {
         successCallback(path.concat(fetchedFields))
-      }, options.errorCallback);
+      }, options.errorCallback, options.cachedOnly);
     } else {
       successCallback(path.concat($.map(identifierChainClone, function (identifier) { return identifier.name })))
     }
@@ -1567,6 +1570,7 @@ var ApiHelper = (function () {
    * @param {boolean} [options.silenceErrors]
    * @param {Number} [options.timeout]
    * @param {Object} [options.editor] - Ace editor
+   * @param {boolean} [options.cachedOnly] - Default false
    *
    * @param {Object[]} options.identifierChain
    * @param {string} options.identifierChain.name
@@ -2081,6 +2085,7 @@ var ApiHelper = (function () {
    * @param {Function} options.errorCallback
    * @param {string} [options.cacheType] - Possible values 'default', 'optimizer'. Default value 'default'
    * @param {Number} [options.timeout]
+   * @param {boolean} [options.cachedOnly] - Default false
    * @param {Object} [options.editor] - Ace editor
    */
   var fetchAssistData = function (options) {
@@ -2098,6 +2103,12 @@ var ApiHelper = (function () {
         return;
       }
     }
+    if (options.cachedOnly) {
+      if (options.errorCallback) {
+        options.errorCallback(false);
+      }
+      return;
+    }
     if (typeof options.editor !== 'undefined' && options.editor !== null) {
       options.editor.showSpinner();
     }

+ 33 - 3
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -4401,12 +4401,42 @@
                     var endCoordinates = editor.renderer.textToScreenCoordinates(pointerPosition.row, token.start);
 
                     var tooltipText = token.parseLocation.type === 'asterisk' ? options.expandStar : options.contextTooltip;
+                    var colType;
+                    if (token.parseLocation.type === 'column') {
+                      var tableChain = token.parseLocation.identifierChain.concat();
+                      var lastIdentifier = tableChain.pop();
+                      if (tableChain.length > 0 && lastIdentifier && lastIdentifier.name) {
+                        var colName = lastIdentifier.name.toLowerCase();
+                        // Note, as cachedOnly is set to true it will call the successCallback right away (or not at all)
+                        ApiHelper.getInstance().fetchAutocomplete({
+                          sourceType: snippet.type(),
+                          defaultDatabase: snippet.database(),
+                          identifierChain: tableChain,
+                          cachedOnly: true,
+                          successCallback: function (details) {
+                            if (details && details.extended_columns) {
+                              details.extended_columns.every(function (col) {
+                                if (col.name.toLowerCase() === colName) {
+                                  colType = col.type;
+                                  return false;
+                                }
+                                return true;
+                              })
+                            }
+                          },
+                          silenceErrors: true
+                        })
+                      }
+                    }
                     if (token.parseLocation.identifierChain) {
-                      tooltipText += ' (' + $.map(token.parseLocation.identifierChain, function (identifier) {
+                      tooltipText += ' - ' + $.map(token.parseLocation.identifierChain, function (identifier) {
                           return identifier.name
-                        }).join('.') + ')';
+                        }).join('.');
+                      if (colType) {
+                        tooltipText += ' (' + colType + ')';
+                      }
                     } else if (token.parseLocation.function) {
-                      tooltipText += ' (' + token.parseLocation.function + ')';
+                      tooltipText += ' - ' + token.parseLocation.function;
                     }
                     contextTooltip.show(tooltipText, endCoordinates.pageX, endCoordinates.pageY + editor.renderer.lineHeight + 3);
                   }