瀏覽代碼

HUE-7951 [editor] Properly handle complex fields in the assist and autocomplete suggestions

Johan Ahlen 7 年之前
父節點
當前提交
2d27ab2173

+ 4 - 4
desktop/core/src/desktop/static/desktop/js/assist/assistDbEntry.js

@@ -202,14 +202,14 @@ var AssistDbEntry = (function () {
       type = 'collection';
     } else if (self.catalogEntry.isColumn()) {
       type = 'column';
-    } else if (self.catalogEntry.isComplex()) {
-      type = 'complex';
+    } else if (self.catalogEntry.isDatabase()) {
+      type = 'database';
     } else if (self.catalogEntry.isTable()) {
       type = 'table';
     } else if (self.catalogEntry.isView()) {
       type = 'view';
     } else {
-      type = 'database';
+      type = 'complex';
     }
 
     self.statsVisible(true);
@@ -319,7 +319,7 @@ var AssistDbEntry = (function () {
           catalogEntries.forEach(function (catalogEntry) {
             newEntries.push(self.createEntry(catalogEntry));
           });
-          if (sourceMeta.type === 'array' || sourceMeta.type === 'map') {
+          if (sourceMeta.type === 'array') {
             self.entries(newEntries);
             self.entries()[0].open(true);
           } else {

+ 14 - 12
desktop/core/src/desktop/static/desktop/js/dataCatalog.js

@@ -487,21 +487,21 @@ var DataCatalog = (function () {
   };
 
   /**
-   * @param {Object} [apiOptions]
-   * @param {boolean} [apiOptions.silenceErrors]
-   * @param {boolean} [apiOptions.cachedOnly]
-   * @param {boolean} [apiOptions.refreshCache]
+   * @param {Object} [options]
+   * @param {boolean} [options.silenceErrors]
+   * @param {boolean} [options.cachedOnly]
+   * @param {boolean} [options.refreshCache]
    *
    * @return {Promise}
    */
-  DataCatalogEntry.prototype.getChildren = function (apiOptions) {
+  DataCatalogEntry.prototype.getChildren = function (options) {
     var self = this;
-    if (self.childrenPromise && (!apiOptions || !apiOptions.refreshCache)) {
+    if (self.childrenPromise && (!options || !options.refreshCache)) {
       return self.childrenPromise;
     }
     var deferred = $.Deferred();
     self.childrenPromise = deferred.promise();
-    self.getSourceMeta(apiOptions).done(function (sourceMeta) {
+    self.getSourceMeta(options).done(function (sourceMeta) {
       if (sourceMeta.notFound) {
         deferred.reject();
         return;
@@ -516,12 +516,14 @@ var DataCatalog = (function () {
       }
 
       var entities = sourceMeta.databases
-        || sourceMeta.tables_meta || sourceMeta.extended_columns || sourceMeta.fields || sourceMeta.columns
-        || (sourceMeta.value && sourceMeta.value.fields) || (sourceMeta.item && sourceMeta.item.fields);
+        || sourceMeta.tables_meta || sourceMeta.extended_columns || sourceMeta.fields || sourceMeta.columns;
+
       if (entities) {
         entities.forEach(function (entity) {
-          if (!sourceMeta.databases || ((entity || entity.name) !== '_impala_builtins')) {
-            promises.push(self.dataCatalog.getEntry({path: self.path.concat(entity.name || entity)}).done(function (catalogEntry) {
+          if (!sourceMeta.databases || ((entity.name || entity) !== '_impala_builtins')) {
+            promises.push(self.dataCatalog.getEntry({
+              path: self.path.concat(entity.name || entity)
+            }).done(function (catalogEntry) {
               if (!catalogEntry.definition || typeof catalogEntry.definition.index === 'undefined') {
                 var definition = typeof entity === 'object' ? entity : {};
                 if (typeof entity !== 'object') {
@@ -544,7 +546,7 @@ var DataCatalog = (function () {
           }
         });
       }
-      if (self.getSourceType() === 'impala' && self.isComplex()) {
+      if ((self.getSourceType() === 'impala' || self.getSourceType() === 'hive') && self.isComplex()) {
         (sourceMeta.type === 'map' ? ['key', 'value'] : ['item']).forEach(function (path) {
           if (sourceMeta[path]) {
             promises.push(self.dataCatalog.getEntry({ path: self.path.concat(path) }).done(function (catalogEntry) {

+ 35 - 11
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter3.js

@@ -740,22 +740,46 @@ var AutocompleteResults = (function () {
                 if (self.snippet.type() === 'hive' && (childEntry.isArray() || childEntry.isMap())) {
                   name += '[]';
                 }
-                if (SqlFunctions.matchesType(self.snippet.type(), types, [childEntry.getType().toUpperCase()])
-                    || SqlFunctions.matchesType(self.snippet.type(), [childEntry.getType().toUpperCase()], types)
-                    || childEntry.getType === 'column'
-                    || childEntry.isComplex()) {
+                  if (SqlFunctions.matchesType(self.snippet.type(), types, [childEntry.getType().toUpperCase()])
+                      || SqlFunctions.matchesType(self.snippet.type(), [childEntry.getType().toUpperCase()], types)
+                      || childEntry.getType === 'column'
+                      || childEntry.isComplex()) {
+                    columnSuggestions.push({
+                      value: name,
+                      meta: childEntry.getType(),
+                      table: table,
+                      category: CATEGORIES.COLUMN,
+                      popular: ko.observable(false),
+                      weightAdjust: types[0].toUpperCase() !== 'T' && types.some(function (type) { return hueUtils.equalIgnoreCase(type, childEntry.getType()) }) ? 1 : 0,
+                      hasCatalogEntry: true,
+                      details: childEntry
+                    });
+                  }
+              });
+              if (self.snippet.type() === 'hive' && (dataCatalogEntry.isArray() || dataCatalogEntry.isMap()) ) {
+                // Remove 'item' or 'value' and 'key' for Hive
+                columnSuggestions.pop();
+                if (dataCatalogEntry.isMap()) {
+                  columnSuggestions.pop();
+                }
+              }
+
+              var complexExtras = sourceMeta.value && sourceMeta.value.fields || sourceMeta.item && sourceMeta.item.fields;
+              if ((self.snippet.type() === 'impala' || self.snippet.type() === 'hive') && complexExtras) {
+                complexExtras.forEach(function (field) {
+                  var fieldType = field.type.indexOf('<') !== -1 ? field.type.substring(0, field.type.indexOf('<')) : field.type;
                   columnSuggestions.push({
-                    value: name,
-                    meta: childEntry.getType(),
+                    value: field.name,
+                    meta: fieldType,
                     table: table,
                     category: CATEGORIES.COLUMN,
                     popular: ko.observable(false),
-                    weightAdjust: types[0].toUpperCase() !== 'T' && types.some(function (type) { return hueUtils.equalIgnoreCase(type, childEntry.getType()) }) ? 1 : 0,
-                    hasCatalogEntry: true,
-                    details: childEntry
+                    weightAdjust: types[0].toUpperCase() !== 'T' && types.some(function (type) { return hueUtils.equalIgnoreCase(type, fieldType) }) ? 1 : 0,
+                    hasCatalogEntry: false,
+                    details: field
                   });
-                }
-              });
+                });
+              }
               addColumnsDeferred.resolve();
             }).fail(addColumnsDeferred.reject));
         }).fail(addColumnsDeferred.reject));