Forráskód Böngészése

HUE-8758 [assist] Publish catalog entry with connector on assist selections

Johan Ahlen 5 éve
szülő
commit
318b59ce6d

+ 6 - 6
apps/beeswax/src/beeswax/static/beeswax/js/beeswax.vm.js

@@ -85,15 +85,15 @@ function BeeswaxViewModel(server, apiHelper) {
     }, 0);
   });
 
-  huePubSub.subscribe("assist.database.selected", function (database) {
-    if (database.sourceType === type && self.database() !== database.name) {
-      self.database(database.name);
+  huePubSub.subscribe("assist.database.selected", function (entry) {
+    if (entry.getConnector().type === type && self.database() !== entry.name) {
+      self.database(entry.name);
     }
   });
 
-  huePubSub.subscribe("assist.database.set", function (database) {
-    if (database.sourceType === type && self.database() !== database.name) {
-      self.database(database.name);
+  huePubSub.subscribe("assist.database.set", function (entry) {
+    if (entry.getConnector().type === type && self.database() !== entry.name) {
+      self.database(entry.name);
     }
   });
 

+ 4 - 4
apps/beeswax/src/beeswax/templates/create_database.mako

@@ -224,12 +224,12 @@ ${layout.metastore_menubar()}
       self.isLeftPanelVisible = ko.observable();
       self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
 
-      huePubSub.subscribe("assist.table.selected", function (tableDef) {
-        location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name + '?source=' + tableDef.sourceType + '&namespace=' + tableDef.namespace.id;
+      huePubSub.subscribe("assist.table.selected", function (entry) {
+        location.href = '/metastore/table/' + entry.path[0] + '/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
 
-      huePubSub.subscribe("assist.database.selected", function (databaseDef) {
-        location.href = '/metastore/tables/' + databaseDef.name + '?source=' + databaseDef.sourceType + '&namespace=' + databaseDef.namespace.id;
+      huePubSub.subscribe("assist.database.selected", function (entry) {
+        location.href = '/metastore/tables/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
     }
 

+ 4 - 4
apps/beeswax/src/beeswax/templates/create_table_manually.mako

@@ -544,12 +544,12 @@ ${ layout.metastore_menubar() }
       self.isLeftPanelVisible = ko.observable();
       self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
 
-      huePubSub.subscribe("assist.table.selected", function (tableDef) {
-        location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name  + '?source=' + tableDef.sourceType + '&namespace=' + tableDef.namespace.id;
+      huePubSub.subscribe("assist.table.selected", function (entry) {
+        location.href = '/metastore/table/' + entry.path[0] + '/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
 
-      huePubSub.subscribe("assist.database.selected", function (databaseDef) {
-        location.href = '/metastore/tables/' + databaseDef.name + '?source=' + databaseDef.sourceType + '&namespace=' + databaseDef.namespace.id;
+      huePubSub.subscribe("assist.database.selected", function (entry) {
+        location.href = '/metastore/tables/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
     }
 

+ 3 - 3
apps/beeswax/src/beeswax/templates/execute.mako

@@ -2804,9 +2804,9 @@ function setupCodeMirrorSubscription() {
 viewModel = new BeeswaxViewModel("${app_name}", apiHelper);
 ko.applyBindings(viewModel, $("#beeswax-execute")[0]);
 
-var handleAssistSelection = function (databaseDef) {
-  if (databaseDef.sourceType === snippetType && snippet.database() !== databaseDef.name) {
-    snippet.database(databaseDef.name);
+var handleAssistSelection = function (entry) {
+  if (entry.getConnector().type === snippetType && snippet.database() !== entry.name) {
+    snippet.database(entry.name);
   }
 };
 

+ 4 - 4
apps/beeswax/src/beeswax/templates/import_wizard_choose_delimiter.mako

@@ -185,12 +185,12 @@ ${ layout.metastore_menubar() }
       self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
 
 
-      huePubSub.subscribe("assist.table.selected", function (tableDef) {
-        location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name + '?source=' + tableDef.sourceType + '&namespace=' + tableDef.namespace.id;
+      huePubSub.subscribe("assist.table.selected", function (entry) {
+        location.href = '/metastore/table/' + entry.path[0] + '/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
 
-      huePubSub.subscribe("assist.database.selected", function (databaseDef) {
-        location.href = '/metastore/tables/' + databaseDef.name + '?source=' + databaseDef.sourceType + '&namespace=' + databaseDef.namespace.id;
+      huePubSub.subscribe("assist.database.selected", function (entry) {
+        location.href = '/metastore/tables/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
     }
 

+ 4 - 4
apps/beeswax/src/beeswax/templates/import_wizard_choose_file.mako

@@ -192,12 +192,12 @@ ${ layout.metastore_menubar() }
       self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
 
 
-      huePubSub.subscribe("assist.table.selected", function (tableDef) {
-        location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name  + '?source=' + tableDef.sourceType + '&namespace=' + tableDef.namespace.id;
+      huePubSub.subscribe("assist.table.selected", function (entry) {
+        location.href = '/metastore/table/' + entry.path[0] + '/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
 
-      huePubSub.subscribe("assist.database.selected", function (databaseDef) {
-        location.href = '/metastore/tables/' + databaseDef.name + '?source=' + databaseDef.sourceType + '&namespace=' + databaseDef.namespace.id;
+      huePubSub.subscribe("assist.database.selected", function (entry) {
+        location.href = '/metastore/tables/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
     }
 

+ 4 - 4
apps/beeswax/src/beeswax/templates/import_wizard_define_columns.mako

@@ -220,12 +220,12 @@ ${ layout.metastore_menubar() }
       self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
 
 
-      huePubSub.subscribe("assist.table.selected", function (tableDef) {
-        location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name + '?source=' + tableDef.sourceType + '&namespace=' + tableDef.namespace.id;
+      huePubSub.subscribe("assist.table.selected", function (entry) {
+        location.href = '/metastore/table/' + entry.path[0] + '/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
 
-      huePubSub.subscribe("assist.database.selected", function (databaseDef) {
-        location.href = '/metastore/tables/' + databaseDef.name + '?source=' + databaseDef.sourceType + '&namespace=' + databaseDef.namespace.id;
+      huePubSub.subscribe("assist.database.selected", function (entry) {
+        location.href = '/metastore/tables/' + entry.name + '?source=' + entry.getConnector().type + '&namespace=' + entry.namespace.id;
       });
     }
 

+ 4 - 4
desktop/core/src/desktop/js/apps/notebook/editorViewModel.js

@@ -365,9 +365,9 @@ class EditorViewModel {
 
     huePubSub.subscribe(
       'assist.database.set',
-      databaseDef => {
+      entry => {
         withActiveSnippet(activeSnippet => {
-          activeSnippet.handleAssistSelection(databaseDef);
+          activeSnippet.handleAssistSelection(entry);
         });
       },
       self.huePubSubId
@@ -375,9 +375,9 @@ class EditorViewModel {
 
     huePubSub.subscribe(
       'assist.database.selected',
-      databaseDef => {
+      entry => {
         withActiveSnippet(activeSnippet => {
-          activeSnippet.handleAssistSelection(databaseDef);
+          activeSnippet.handleAssistSelection(entry);
         });
       },
       self.huePubSubId

+ 6 - 6
desktop/core/src/desktop/js/apps/notebook/snippet.js

@@ -457,15 +457,15 @@ class Snippet {
     });
 
     let ignoreNextAssistDatabaseUpdate = false;
-    self.handleAssistSelection = function(databaseDef) {
+    self.handleAssistSelection = function(entry) {
       if (ignoreNextAssistDatabaseUpdate) {
         ignoreNextAssistDatabaseUpdate = false;
-      } else if (databaseDef.sourceType === self.type()) {
-        if (self.namespace() !== databaseDef.namespace) {
-          self.namespace(databaseDef.namespace);
+      } else if (entry.getConnector().type === self.connector().type) {
+        if (self.namespace() !== entry.namespace) {
+          self.namespace(entry.namespace);
         }
-        if (self.database() !== databaseDef.name) {
-          self.database(databaseDef.name);
+        if (self.database() !== entry.name) {
+          self.database(entry.name);
         }
       }
     };

+ 4 - 4
desktop/core/src/desktop/js/apps/notebook2/editorViewModel.js

@@ -209,9 +209,9 @@ class EditorViewModel {
 
     huePubSub.subscribe(
       'assist.database.set',
-      databaseDef => {
+      entry => {
         this.withActiveSnippet(activeSnippet => {
-          activeSnippet.handleAssistSelection(databaseDef);
+          activeSnippet.handleAssistSelection(entry);
         });
       },
       this.huePubSubId
@@ -219,9 +219,9 @@ class EditorViewModel {
 
     huePubSub.subscribe(
       'assist.database.selected',
-      databaseDef => {
+      entry => {
         this.withActiveSnippet(activeSnippet => {
-          activeSnippet.handleAssistSelection(databaseDef);
+          activeSnippet.handleAssistSelection(entry);
         });
       },
       this.huePubSubId

+ 6 - 6
desktop/core/src/desktop/js/apps/notebook2/snippet.js

@@ -1288,15 +1288,15 @@ export default class Snippet {
     }
   }
 
-  handleAssistSelection(databaseDef) {
+  handleAssistSelection(entry) {
     if (this.ignoreNextAssistDatabaseUpdate) {
       this.ignoreNextAssistDatabaseUpdate = false;
-    } else if (databaseDef.sourceType === this.dialect()) {
-      if (this.namespace() !== databaseDef.namespace) {
-        this.namespace(databaseDef.namespace);
+    } else if (entry.getConnector().type === this.connector().type) {
+      if (this.namespace() !== entry.namespace) {
+        this.namespace(entry.namespace);
       }
-      if (this.database() !== databaseDef.name) {
-        this.database(databaseDef.name);
+      if (this.database() !== entry.name) {
+        this.database(entry.name);
       }
     }
   }

+ 41 - 38
desktop/core/src/desktop/js/apps/table_browser/metastoreViewModel.js

@@ -21,7 +21,8 @@ import apiHelper from 'api/apiHelper';
 import huePubSub from 'utils/huePubSub';
 import hueUtils from 'utils/hueUtils';
 import MetastoreSource from 'apps/table_browser/metastoreSource';
-import { GET_KNOWN_CONFIG_EVENT } from 'utils/hueConfig';
+import dataCatalog from 'catalog/dataCatalog';
+import { findEditorConnector, GET_KNOWN_CONFIG_EVENT } from 'utils/hueConfig';
 
 class MetastoreViewModel {
   /**
@@ -115,10 +116,10 @@ class MetastoreViewModel {
 
     this.currentTab = ko.observable('');
 
-    huePubSub.subscribe('assist.database.selected', databaseDef => {
-      if (this.source().type !== databaseDef.sourceType) {
+    huePubSub.subscribe('assist.database.selected', entry => {
+      if (this.source().type !== entry.getConnector().type) {
         const found = this.sources().some(source => {
-          if (source.type === databaseDef.sourceType) {
+          if (source.type === entry.getConnector().type) {
             this.source(source);
             return true;
           }
@@ -128,11 +129,11 @@ class MetastoreViewModel {
         }
       }
 
-      if (this.source().namespace().id !== databaseDef.namespace.id) {
+      if (this.source().namespace().id !== entry.namespace.id) {
         const found = this.source()
           .namespaces()
           .some(namespace => {
-            if (namespace.id === databaseDef.namespace.id) {
+            if (namespace.id === entry.namespace.id) {
               this.source().namespace(namespace);
               return true;
             }
@@ -153,13 +154,13 @@ class MetastoreViewModel {
       }
       this.source()
         .namespace()
-        .setDatabaseByName(databaseDef.name, () => {
+        .setDatabaseByName(entry.name, () => {
           huePubSub.publish('metastore.url.change');
         });
     });
 
-    huePubSub.subscribe('assist.table.selected', tableDef => {
-      this.loadTableDef(tableDef, () => {
+    huePubSub.subscribe('assist.table.selected', entry => {
+      this.loadTableDef(entry, () => {
         huePubSub.publish('metastore.url.change');
       });
     });
@@ -271,10 +272,10 @@ class MetastoreViewModel {
     };
   }
 
-  loadTableDef(tableDef, callback) {
-    if (this.source().type !== tableDef.sourceType) {
+  loadTableDef(entry, callback) {
+    if (this.source().type !== entry.getConnector().type) {
       const found = this.sources().some(source => {
-        if (source.type === tableDef.sourceType) {
+        if (source.type === entry.getConnector().type) {
           this.source(source);
           return true;
         }
@@ -283,11 +284,11 @@ class MetastoreViewModel {
         return;
       }
     }
-    if (this.source().namespace().id !== tableDef.namespace.id) {
+    if (this.source().namespace().id !== entry.namespace.id) {
       const found = this.source()
         .namespaces()
         .some(namespace => {
-          if (namespace.id === tableDef.namespace.id) {
+          if (namespace.id === entry.namespace.id) {
             this.source().namespace(namespace);
             return true;
           }
@@ -299,7 +300,7 @@ class MetastoreViewModel {
 
     this.source()
       .namespace()
-      .setDatabaseByName(tableDef.database, () => {
+      .setDatabaseByName(entry.path[0], () => {
         if (
           this.source()
             .namespace()
@@ -313,7 +314,7 @@ class MetastoreViewModel {
             this.source()
               .namespace()
               .database()
-              .table().catalogEntry.name === tableDef.name
+              .table().catalogEntry.name === entry.name
           ) {
             if (callback) {
               callback();
@@ -326,7 +327,7 @@ class MetastoreViewModel {
               .namespace()
               .database()
               .tables()
-              .filter(table => table.catalogEntry.name === tableDef.name);
+              .filter(table => table.catalogEntry.name === entry.name);
             if (foundTables.length === 1) {
               this.source()
                 .namespace()
@@ -339,7 +340,7 @@ class MetastoreViewModel {
               dbEntry
                 .getChildren({ refreshCache: true, silenceErrors: true })
                 .then(childEntries => {
-                  if (childEntries.some(childEntry => childEntry.name === tableDef.name)) {
+                  if (childEntries.some(childEntry => childEntry.name === entry.name)) {
                     this.source()
                       .namespace()
                       .database()
@@ -351,7 +352,7 @@ class MetastoreViewModel {
                       .clearCache({
                         invalidate: 'invalidate',
                         silenceErrors: true,
-                        targetChild: tableDef.name
+                        targetChild: entry.name
                       })
                       .then(() => {
                         this.source()
@@ -489,25 +490,27 @@ class MetastoreViewModel {
             },
             'metastore'
           );
-          this.loadTableDef(
-            {
-              name: pathParts[2],
-              database: pathParts[1],
-              sourceType: this.source().type,
-              namespace: namespace
-            },
-            () => {
-              if (pathParts.length > 3 && pathParts[3] === 'partitions') {
-                huePubSub.subscribe(
-                  'metastore.loaded.partitions',
-                  () => {
-                    this.currentTab('partitions');
-                  },
-                  'metastore'
-                );
-              }
-            }
-          );
+
+          dataCatalog
+            .getEntry({
+              connector: findEditorConnector(connector => connector.type === this.source().type),
+              namespace: namespace.namespace,
+              compute: namespace.compute,
+              path: [pathParts[1], pathParts[2]]
+            })
+            .then(entry => {
+              this.loadTableDef(entry, () => {
+                if (pathParts.length > 3 && pathParts[3] === 'partitions') {
+                  huePubSub.subscribe(
+                    'metastore.loaded.partitions',
+                    () => {
+                      this.currentTab('partitions');
+                    },
+                    'metastore'
+                  );
+                }
+              });
+            });
       }
     });
   }

+ 2 - 11
desktop/core/src/desktop/js/ko/components/assist/assistDbEntry.js

@@ -531,18 +531,9 @@ class AssistDbEntry {
   openItem() {
     const self = this;
     if (self.catalogEntry.isTableOrView()) {
-      huePubSub.publish('assist.table.selected', {
-        sourceType: self.assistDbNamespace.sourceType,
-        namespace: self.assistDbNamespace.namespace,
-        database: self.databaseName,
-        name: self.catalogEntry.name
-      });
+      huePubSub.publish('assist.table.selected', self.catalogEntry);
     } else if (self.catalogEntry.isDatabase()) {
-      huePubSub.publish('assist.database.selected', {
-        sourceType: self.assistDbNamespace.sourceType,
-        namespace: self.assistDbNamespace.namespace,
-        name: self.catalogEntry.name
-      });
+      huePubSub.publish('assist.database.selected', self.catalogEntry);
     }
   }
 }

+ 2 - 5
desktop/core/src/desktop/js/ko/components/assist/assistDbNamespace.js

@@ -146,16 +146,13 @@ class AssistDbNamespace {
           self.selectedDatabase().loadEntries();
         }
         if (!self.navigationSettings.rightAssist) {
+          const entry = self.selectedDatabase().catalogEntry;
           apiHelper.setInTotalStorage(
             'assist_' + self.sourceType + '_' + self.namespace.id,
             'lastSelectedDb',
             self.selectedDatabase().catalogEntry.name
           );
-          huePubSub.publish('assist.database.set', {
-            sourceType: self.sourceType,
-            namespace: self.namespace,
-            name: self.selectedDatabase().catalogEntry.name
-          });
+          huePubSub.publish('assist.database.set', entry);
         }
       } else {
         apiHelper.setInTotalStorage(