Przeglądaj źródła

HUE-4942 [metadata] Support custom end user filters

Starting a test suite
Romain Rigaux 9 lat temu
rodzic
commit
c94f1448b1

+ 7 - 7
desktop/libs/metadata/src/metadata/navigator_client.py

@@ -95,18 +95,18 @@ class NavigatorApi(object):
           query_clauses.append('OR'.join(['(%s:*%s*)' % (field, term) for field in search_fields]))
         else:
           name, val = term.split(':')
-          if val:
+          if val and (name != 'type' or val in entity_types): # Manual filter allowed
             user_filters.append(term) # e.g. type:VIEW ca
-      if user_filters and not query_clauses:
-        query_clauses.append('*') # e.g. type:VIEW
 
-      filter_query = '(originalName:*.*)'
-      if search_terms:
+      filter_query = '*'
+
+      if query_clauses:
         filter_query = 'OR'.join(['(%s)' % clause for clause in query_clauses])
 
-      type_filter_clause = 'OR'.join(['(%s:%s)' % ('type', entity_type) for entity_type in entity_types])
       if user_filters:
-        type_filter_clause = '(%s) AND (%s)' % ('OR'.join(user_filters), type_filter_clause)
+        type_filter_clause = 'OR '.join(['(%s)' % f for f in user_filters])
+      else:
+        type_filter_clause = 'OR'.join(['(%s:%s)' % ('type', entity_type) for entity_type in default_entity_types])
       filter_query = '%s AND (%s)' % (filter_query, type_filter_clause)
 
       params += (

+ 66 - 0
desktop/libs/metadata/src/metadata/navigator_client_tests.py

@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+
+from nose.plugins.skip import SkipTest
+from nose.tools import assert_equal
+
+from hadoop.pseudo_hdfs4 import is_live_cluster
+
+from metadata.conf import has_navigator
+from metadata.navigator_client import NavigatorApi
+
+
+LOG = logging.getLogger(__name__)
+
+
+class MockedRoot():
+  def get(self, relpath=None, params=None, headers=None, clear_cookies=False):
+    return params
+
+
+class TestNavigatorclient:
+
+  @classmethod
+  def setup_class(cls):
+    if not is_live_cluster() or not has_navigator(): # Until v1
+      raise SkipTest
+
+  def test_search_entities(self):
+    api = NavigatorApi()
+    api._root = MockedRoot()
+
+    assert_equal(
+        '((originalName:*cases*)OR(originalDescription:*cases*)OR(name:*cases*)OR(description:*cases*)OR(tags:*cases*)) AND ((type:TABLE)OR(type:VIEW))',
+        api.search_entities(query_s='cases', sources=['hive'])[0][1]
+    )
+
+    assert_equal(
+        '* AND ((type:FIELD))',
+        api.search_entities(query_s='type:FIELD', sources=['hive'])[0][1]
+    )
+
+    # type:
+    # type:VIEW
+    # type:VIEW ca
+    # type:VIEW ca owner:hue
+    # type:(VIEW OR TABLE)
+    # type:(VIEW OR TABLE) ca
+    # ca es
+    # "ca es"
+    # ca OR es