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

HUE-8848 [catalog] Enable faceted classification search for Atlas

This adds 'tags:...', 'tag:...' and 'classification:...' from the top search and it shows the classifications in read-only mode in the table browser and context popover.
Johan Ahlen 6 жил өмнө
parent
commit
ae298ca240

+ 1 - 1
apps/metastore/src/metastore/templates/metastore.mako

@@ -449,7 +449,7 @@ ${ components.menubar(is_embeddable) }
 </script>
 
 <script type="text/html" id="metastore-nav-tags">
-  <!-- ko if: window.HAS_CATALOG_TAGS && $root.navigatorEnabled()  -->
+  <!-- ko if: $root.navigatorEnabled()  -->
   <div class="metastore-nav-tags" data-bind="component: { name: 'nav-tags', params: { catalogEntry: catalogEntry }}"></div>
   <!-- /ko -->
 </script>

+ 1 - 1
desktop/core/src/desktop/js/ko/components/contextPopover/ko.contextPopover.js

@@ -404,7 +404,7 @@ const SUPPORT_TEMPLATES = `
           <!-- /ko -->
 
           <!-- ko ifnot: $parent.commentExpanded -->
-              <!-- ko if: window.HAS_CATALOG && window.HAS_CATALOG_TAGS && !isTemporary && (getSourceType() === 'hive' || getSourceType() === 'impala') -->
+              <!-- ko if: window.HAS_CATALOG && !isTemporary && (getSourceType() === 'hive' || getSourceType() === 'impala') -->
               <div data-bind="component: { name: 'nav-tags', params: { catalogEntry: $data, overflowEllipsis: true } }"></div>
               <!-- /ko -->
 

+ 3 - 1
desktop/core/src/desktop/js/ko/components/ko.globalSearch.js

@@ -152,7 +152,7 @@ class GlobalSearch {
         placeHolder: I18n(window.HAS_CATALOG ? 'Search data and saved documents...' : 'Search saved documents...'),
         querySpec: self.querySpec,
         onClear: function () { self.selectedIndex(null); self.searchResultVisible(false); },
-        facets: window.HAS_CATALOG_TAGS ? ['type', 'tags', 'parentPath', 'originalName'] : ['type'],
+        facets: window.HAS_READ_ONLY_CATALOG ? ['type', 'tag', 'classification'] : ['type', 'tag', 'parentPath', 'originalName'],
         knownFacetValues: self.knownFacetValues,
         autocompleteFromEntries: self.autocompleteFromEntries,
         triggerObservable: self.searchResultCategories
@@ -339,7 +339,9 @@ class GlobalSearch {
     const self = this;
     dataCatalog.getAllNavigatorTags({ silenceErrors: true }).done(facets => {
       const facetValues = self.knownFacetValues();
+      facetValues['tag'] = facets;
       facetValues['tags'] = facets;
+      facetValues['classification'] = facets;
     });
   }
 

+ 1 - 2
desktop/core/src/desktop/templates/global_js_constants.mako

@@ -24,7 +24,7 @@
   from beeswax.conf import LIST_PARTITIONS_LIMIT
   from dashboard.conf import HAS_SQL_ENABLED
   from indexer.conf import ENABLE_NEW_INDEXER
-  from metadata.conf import has_catalog, has_catalog_tags, has_readonly_catalog, has_optimizer, has_workload_analytics, OPTIMIZER
+  from metadata.conf import has_catalog, has_readonly_catalog, has_optimizer, has_workload_analytics, OPTIMIZER
   from notebook.conf import ENABLE_NOTEBOOK_2, ENABLE_QUERY_ANALYSIS, ENABLE_QUERY_SCHEDULING
 
   from metastore.views import has_write_access
@@ -65,7 +65,6 @@
   window.ENABLE_SQL_SYNTAX_CHECK = '${ conf.ENABLE_SQL_SYNTAX_CHECK.get() }' === 'True';
 
   window.HAS_CATALOG = '${ has_catalog(request.user) }' === 'True';
-  window.HAS_CATALOG_TAGS = '${ has_catalog_tags(request.user) }' === 'True';
   window.HAS_READ_ONLY_CATALOG = '${ has_readonly_catalog(request.user) }' === 'True' || '${ has_write_access(request.user) }' === 'False';
 
   window.HAS_OPTIMIZER = '${ has_optimizer() }' === 'True';

+ 13 - 10
desktop/libs/metadata/src/metadata/catalog/atlas_client.py

@@ -220,13 +220,10 @@ class AtlasApi(Api):
       }
 
       # This takes care of the list_tags endpoint
-      if (not query_s and facetFields and 'tags' in facetFields):
-        # Classification names from Atlas can contain spaces which doesn't work with the top search at the moment
-        # so for now we return an empty list
-
-        # classification_response = self._root.get('/v2/types/typedefs?type=classification')
-        # for classification_def in classification_response['classificationDefs']:
-        #   response['facets']['tags'][classification_def['name']] = 0
+      if not query_s and facetFields and 'tags' in facetFields:
+        classification_response = self._root.get('/v2/types/typedefs?type=classification')
+        for classification_def in classification_response['classificationDefs']:
+          response['facets']['tags'][classification_def['name']] = -1
         return response
 
       query_s = (query_s.strip() if query_s else '') + '*'
@@ -234,7 +231,7 @@ class AtlasApi(Api):
       search_terms = [term for term in query_s.strip().split()] if query_s else []
       query = []
 
-      atlas_type = 'hive_table'
+      atlas_type = None
 
       for term in search_terms:
         if ':' not in term:
@@ -243,6 +240,11 @@ class AtlasApi(Api):
           name, val = term.rstrip('*').split(':')
           if val and name.lower() == 'type' and self.NAV_TO_ATLAS_TYPE.get(val.lower()):
             atlas_type = self.NAV_TO_ATLAS_TYPE.get(val.lower())
+          if val and name.lower() in ['tag', 'tags','classification']:
+            if not atlas_type:
+              atlas_type = 'Asset' # 'Asset' contains all types of entities so we need to filter below
+            # Atlas filters by classification name on default
+            query.append(val + '*')
 
       data = json.dumps({
         "attributes": None,
@@ -257,7 +259,7 @@ class AtlasApi(Api):
         "query": ' '.join(query),
         "tagFilters": None,
         "termName": None,
-        "typeName": atlas_type
+        "typeName": atlas_type or 'hive_table'
       })
 
       atlas_response = self._root.post('/v2/search/basic', data=data, contenttype=_JSON_CONTENT_TYPE)
@@ -265,7 +267,8 @@ class AtlasApi(Api):
       # Adapt Atlas entities to Navigator structure in the results
       if 'entities' in atlas_response:
         for atlas_entity in atlas_response['entities']:
-          response['results'].append(self.adapt_atlas_entity_to_navigator(atlas_entity))
+          if atlas_type != 'Asset' or atlas_entity['typeName'].lower() in ['hive_db', 'hive_table', 'hive_column']:
+            response['results'].append(self.adapt_atlas_entity_to_navigator(atlas_entity))
 
       return response
     except RestException as e:

+ 0 - 3
desktop/libs/metadata/src/metadata/conf.py

@@ -232,9 +232,6 @@ def has_catalog(user):
   return ((bool(get_catalog_url() and get_catalog_auth_password())) or has_navigator(user)) \
       and (is_admin(user) or user.has_hue_permission(action="access", app=DJANGO_APPS[0]))
 
-def has_catalog_tags(user):
-  return has_catalog(user) and has_navigator(user)
-
 def has_readonly_catalog(user):
   return has_catalog(user) and not has_navigator(user)