Pārlūkot izejas kodu

HUE-6230 [metadata] Send unique tables to navopt

Johan Ahlen 8 gadi atpakaļ
vecāks
revīzija
f850097

+ 8 - 3
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -1500,7 +1500,8 @@ var ApiHelper = (function () {
 
   ApiHelper.prototype.createNavOptDbTablesJson = function (options) {
     var self = this;
-    var dbTables = [];
+    var tables = [];
+    var tableIndex = {};
     options.tables.forEach(function (table) {
       var clonedIdentifierChain = table.identifierChain.concat();
 
@@ -1512,9 +1513,13 @@ var ApiHelper = (function () {
       } else {
         databasePrefix = '';
       }
-      dbTables.push(databasePrefix  + $.map(clonedIdentifierChain, function (identifier) { return identifier.name }).join('.'));
+      var identifier = databasePrefix  + $.map(clonedIdentifierChain, function (identifier) { return identifier.name }).join('.');
+      if (!tableIndex[databasePrefix  + $.map(clonedIdentifierChain, function (identifier) { return identifier.name }).join('.')]) {
+        tables.push(identifier);
+        tableIndex[identifier] = true;
+      }
     });
-    return ko.mapping.toJSON(dbTables);
+    return ko.mapping.toJSON(tables);
   };
 
   /**

+ 23 - 0
desktop/core/src/desktop/static/desktop/spec/apiHelperSpec.js

@@ -130,6 +130,29 @@
           });
 
           expect(result).toEqual('["default.a_table_from_default","other_db.a_table_from_other_db"]');
+        });
+
+        it('should remove duplicates', function () {
+          spyOn(subject, 'containsDatabase').and.callFake(function () {
+            return true;
+          });
+
+          var result = subject.createNavOptDbTablesJson({
+            defaultDatabase: 'default',
+            sourceType: 'hive',
+            tables: [
+              { identifierChain: [{ name: 'someTable' }] },
+              { identifierChain: [{ name: 'someDb' }, { name: 'someTable' }] },
+              { identifierChain: [{ name: 'default' }, { name: 'someTable' }] },
+              { identifierChain: [{ name: 'someDb' }, { name: 'otherTable' }] },
+              { identifierChain: [{ name: 'someDb' }, { name: 'someTable' }] },
+              { identifierChain: [{ name: 'someTable' }] },
+              { identifierChain: [{ name: 'someDb' }, { name: 'otherTable' }] },
+              { identifierChain: [{ name: 'someDb' }, { name: 'otherTable' }] }
+            ]
+          });
+
+          expect(result).toEqual('["default.someTable","someDb.someTable","someDb.otherTable"]');
         })
       });
     })