Эх сурвалжийг харах

HUE-7948 [assist] Check the database metadata before loading tables in the right assistant

Johan Ahlen 7 жил өмнө
parent
commit
872253b95d

+ 36 - 23
desktop/core/src/desktop/static/desktop/js/assist/assistDbEntry.js

@@ -306,34 +306,47 @@ var AssistDbEntry = (function () {
 
     var successCallback = function(sourceMeta) {
       self.entries([]);
-      self.catalogEntry.getChildren().done(function (catalogEntries) {
-        self.hasErrors(false);
-        self.loading(false);
-        self.loaded = true;
-        if (catalogEntries.length === 0) {
-          self.entries([]);
-          return;
-        }
-        var newEntries = [];
-        catalogEntries.forEach(function (catalogEntry) {
-          newEntries.push(self.createEntry(catalogEntry));
+      if (!sourceMeta.notFound) {
+        self.catalogEntry.getChildren().done(function (catalogEntries) {
+          self.hasErrors(false);
+          self.loading(false);
+          self.loaded = true;
+          if (catalogEntries.length === 0) {
+            self.entries([]);
+            return;
+          }
+          var newEntries = [];
+          catalogEntries.forEach(function (catalogEntry) {
+            newEntries.push(self.createEntry(catalogEntry));
+          });
+          if (sourceMeta.type === 'array' || sourceMeta.type === 'map') {
+            self.entries(newEntries);
+            self.entries()[0].open(true);
+          } else {
+            newEntries.sort(self.sortFunctions[self.assistDbSource.activeSort()]);
+            self.entries(newEntries);
+          }
+
+          loadEntriesDeferred.resolve(newEntries);
+          if (typeof callback === 'function') {
+            callback();
+          }
+        }).fail(function () {
+          self.loading(false);
+          self.loaded = true;
+          self.hasErrors(true);
         });
-        if (sourceMeta.type === 'array' || sourceMeta.type === 'map') {
-          self.entries(newEntries);
-          self.entries()[0].open(true);
-        } else {
-          newEntries.sort(self.sortFunctions[self.assistDbSource.activeSort()]);
-          self.entries(newEntries);
-        }
 
-        loadEntriesDeferred.resolve(newEntries);
+        if (self.assistDbSource.sourceType !== 'solr') {
+          self.catalogEntry.loadNavigatorMetaForChildren({ silenceErrors: self.navigationSettings.rightAssist });
+        }
+      } else {
+        self.hasErrors(true);
+        self.loading(false);
+        self.loaded = true;
         if (typeof callback === 'function') {
           callback();
         }
-      });
-
-      if (self.assistDbSource.sourceType !== 'solr') {
-        self.catalogEntry.loadNavigatorMetaForChildren({ silenceErrors: self.navigationSettings.rightAssist });
       }
     };
 

+ 4 - 0
desktop/core/src/desktop/static/desktop/js/dataCatalog.js

@@ -478,6 +478,10 @@ var DataCatalog = (function () {
     var deferred = $.Deferred();
     self.childrenPromise = deferred.promise();
     self.getSourceMeta(apiOptions).done(function (sourceMeta) {
+      if (sourceMeta.notFound) {
+        deferred.reject();
+        return;
+      }
       var promises = [];
       var index = 0;
       var partitionKeys = {};

+ 43 - 18
desktop/core/src/desktop/templates/assist.mako

@@ -2621,24 +2621,49 @@ from desktop.views import _ko
                   }
 
                   dbDeferred.done(function (dbEntry) {
-                    var tableName = location.identifierChain[location.identifierChain.length - 1].name;
-                    DataCatalog.getEntry({
-                      sourceType: activeLocations.type,
-                      path: [database, tableName],
-                      definition: { type: 'table' }
-                    }).done(function (catalogEntry) {
-                      var tableEntry = new AssistDbEntry(
-                              catalogEntry,
-                              dbEntry,
-                              assistDbSource,
-                              self.filter,
-                              i18n,
-                              navigationSettings
-                      );
-                      activeTableIndex[createQualifiedIdentifier(location.identifierChain, activeLocations.defaultDatabase)] = tableEntry;
-                      tableQidIndex[qid] = true;
-                      updateTables = true;
-                      tableDeferred.resolve(tableEntry)
+                    dbEntry.catalogEntry.getChildren().done(function (tableEntries) {
+                      var tableName = location.identifierChain[location.identifierChain.length - 1].name;
+                      var found = tableEntries.some(function (tableEntry) {
+                        if (tableEntry.name === tableName) {
+                          var assistTableEntry = new AssistDbEntry(
+                            tableEntry,
+                            dbEntry,
+                            assistDbSource,
+                            self.filter,
+                            i18n,
+                            navigationSettings
+                          );
+                          activeTableIndex[createQualifiedIdentifier(location.identifierChain, activeLocations.defaultDatabase)] = assistTableEntry;
+                          tableQidIndex[qid] = true;
+                          updateTables = true;
+                          tableDeferred.resolve(assistTableEntry);
+                          return true;
+                        }
+                      });
+
+                      if (!found) {
+                        var missingEntry = new AssistDbEntry(
+                          {
+                            path: [dbEntry.catalogEntry.name, tableName],
+                            name: tableName,
+                            isTableOrView: function () { return true; },
+                            getType: function () { return 'table' },
+                            hasPossibleChildren: function () { return true; },
+                            getSourceMeta: function () { return $.Deferred().resolve({ notFound: true }).promise() },
+                            getDisplayName: function () { return dbEntry.catalogEntry.name + '.' + tableName }
+                          },
+                          dbEntry,
+                          assistDbSource,
+                          self.filter,
+                          i18n,
+                          navigationSettings
+                        );
+                        activeTableIndex[createQualifiedIdentifier(location.identifierChain, activeLocations.defaultDatabase)] = missingEntry;
+                        tableQidIndex[qid] = true;
+                        updateTables = true;
+                        missingEntry.hasErrors(true);
+                        tableDeferred.resolve(missingEntry);
+                      }
                     }).fail(tableDeferred.reject);
                   }).fail(tableDeferred.reject);
                 }