瀏覽代碼

HUE-4480 [meta] Filter SQL objects in the backend

Romain Rigaux 9 年之前
父節點
當前提交
cc311ca663

+ 36 - 34
desktop/core/src/desktop/templates/assist.mako

@@ -1203,40 +1203,6 @@ from metadata.conf import has_navigator
           }
         });
 
-        self.performSearch = function () {
-          if (self.searchInput() === lastQuery) {
-            return;
-          }
-          if (self.searching()) {
-            window.setTimeout(function() {
-              self.performSearch();
-            }, 100);
-          }
-          lastQuery = self.searchInput();
-          self.searching(true);
-          $.post('/metadata/api/navigator/search_entities?query_s=' + self.searchInput() )
-              .done(function (data) {
-                console.log(data);
-                data.entities.forEach(function (entity) {
-                  if (entity.type === 'DATABASE') {
-                    entity.link = '/metastore/tables/' + entity.originalName;
-                  } else if (entity.type === 'TABLE') {
-                    entity.link = '/metastore/table' + entity.parentPath + '/' + entity.originalName;
-                  } else if (entity.type === 'SOURCE') {
-                    entity.link = entity.sourceUrl;
-                  } else if (entity.type === 'OPERATION_EXECUTION') {
-                    entity.link = '/jobbrowser/jobs/' + entity.jobID;
-                  } else if (entity.type === 'DIRECTORY' || entity.type === 'FILE') {
-                    entity.link = '/filebrowser/#' + entity.fileSystemPath;
-                  } else {
-                    entity.link = '#';
-                  }
-                });
-                self.searchResult(data.entities);
-                self.searching(false);
-              })
-        };
-
         self.onlySql = true; // params.onlySql; - Only show SQL until Hue 4
         self.loading = ko.observable(false);
 
@@ -1291,6 +1257,42 @@ from metadata.conf import has_navigator
           self.availablePanels[0].visible(true);
         }
 
+        self.performSearch = function () {
+          if (self.searchInput() === lastQuery) {
+            return;
+          }
+          if (self.searching()) {
+            window.setTimeout(function() {
+              self.performSearch();
+            }, 100);
+          }
+          lastQuery = self.searchInput();
+          self.searching(true);
+          $.post('/metadata/api/navigator/search_entities', {
+              query_s: self.searchInput(),
+              sources: ko.mapping.toJSON($.map(self.availablePanels[0].panelData.sources(), function(source) { return source.sourceType; })) // type empty for some reason, using name
+          })
+          .done(function (data) {
+            data.entities.forEach(function (entity) {
+              if (entity.type === 'DATABASE') {
+                entity.link = '/metastore/tables/' + entity.originalName;
+              } else if (entity.type === 'TABLE') {
+                entity.link = '/metastore/table' + entity.parentPath + '/' + entity.originalName;
+              } else if (entity.type === 'SOURCE') {
+                entity.link = entity.sourceUrl;
+              } else if (entity.type === 'OPERATION_EXECUTION') {
+                entity.link = '/jobbrowser/jobs/' + entity.jobID;
+              } else if (entity.type === 'DIRECTORY' || entity.type === 'FILE') {
+                entity.link = '/filebrowser/#' + entity.fileSystemPath;
+              } else {
+                entity.link = '#';
+              }
+            });
+            self.searchResult(data.entities);
+            self.searching(false);
+          })
+        };
+
         self.visiblePanels = ko.pureComputed(function () {
           var result = $.grep(self.availablePanels, function (panel) {
             return panel.visible();

+ 6 - 6
desktop/libs/metadata/src/metadata/navigator_api.py

@@ -62,16 +62,16 @@ def error_handler(view_fn):
 
 @error_handler
 def search_entities(request):
-  response = {'status': -1}
-
   api = NavigatorApi()
-  query_s = request.GET.get('query_s')
-  offset = request.GET.get('offset', 0)
-  limit = request.GET.get('limit', 100)
+
+  query_s = request.POST.get('query_s')
+  offset = request.POST.get('offset', 0)
+  limit = request.POST.get('limit', 100)
+  sources = json.loads(request.POST.get('sources'), [])
 
   query_s = query_s.strip()
 
-  entities = api.search_entities(query_s)
+  entities = api.search_entities(query_s, sources=sources)
 
   response = {
     'entities': entities,

+ 5 - 0
desktop/libs/metadata/src/metadata/navigator_client.py

@@ -76,6 +76,11 @@ class NavigatorApi(object):
     search_fields = ('originalName', 'originalDescription', 'name', 'description', 'tags')
     entity_types = ('DATABASE', 'TABLE', 'PARTITION', 'FIELD', 'FILE', 'OPERATION')
 
+    sources = filters.get('sources', [])
+
+    if 'hive' in sources or 'impala' in sources:
+      entity_types = ('DATABASE', 'TABLE', 'PARTITION', 'FIELD')
+
     try:
       params = self.__params