def test_search_normal(self) -> None: expected = SearchResult(total_results=2, results=[ Table(name=self.entity1_name, key=make_table_qualified_name( self.entity1_name, self.cluster, self.db), description=self.entity1_description, cluster=self.cluster, database=self.entity_type, schema=self.db, column_names=[], tags=[Tag(tag_name='PII_DATA')], badges=[Tag(tag_name='PII_DATA')], last_updated_timestamp=123) ]) entity1 = self.to_class(self.entity1) entity_collection = MagicMock() entity_collection.entities = [entity1] entity_collection._data = {'approximateCount': 1} result = MagicMock(return_value=entity_collection) with patch.object(self.proxy.atlas.search_basic, 'create', result): resp = self.proxy.fetch_table_search_results(query_term="Table") self.assertEquals(resp.total_results, 1) self.assertIsInstance( resp.results[0], Table, "Search result received is not of 'Table' type!") self.assertDictEqual( vars(resp.results[0]), vars(expected.results[0]), "Search Result doesn't match with expected result!")
def _prepare_tables(self, response: EntityCollection, enhance_metadata: bool = False) -> List[Table]: """ Based on an Atlas {response} with table entities, we render Table objects. :param response: Collection of Atlas Entities :param enhance_metadata: Should Atlas be queried to acquire complete entity definitions (search might not return all available attributes) :return: List of Table objects """ result = list() # if condition is satisfied then we query Atlas again to collect all available information regarding each table # along with relationship information. This is helpful when using Atlas DSL as returned entities contain minimal # amount of attributes. if enhance_metadata: ids = list() for hit in response: ids.append(hit.guid) entities = self._extract_entities(self.atlas.entity_bulk(guid=ids, ignoreRelationships=False)) else: entities = response for entity in entities: entity_attrs = entity.attributes qn = parse_table_qualified_name(qualified_name=entity_attrs.get(self.ATLAS_QN_ATTRIBUTE)) entity_name = qn.get('table_name') or entity_attrs.get('name') db_name = qn.get('db_name', '') db_cluster = qn.get('cluster_name', '') tags: List[Tag] = [] for classification in entity.classificationNames or list(): tags.append(Tag(tag_name=classification)) badges: List[Tag] = tags table = Table(name=entity_name, key=make_table_qualified_name(entity_name, db_cluster, db_name), description=entity_attrs.get('description'), cluster=db_cluster, database=entity.typeName, schema=db_name, tags=tags, badges=badges, column_names=[], last_updated_timestamp=entity_attrs.get('updateTime')) result.append(table) return result
def _get_table_entity(self, *, table_uri: str) -> EntityUniqueAttribute: """ Fetch information from table_uri and then find the appropriate entity The reason, we're not returning the entity_unique_attribute().entity directly is because the entity_unique_attribute() return entity Object that can be used for update purposes, while entity_unique_attribute().entity only returns the dictionary :param table_uri: :return: A tuple of Table entity and parsed information of table qualified name """ table_info = self._extract_info_from_uri(table_uri=table_uri) table_qn = make_table_qualified_name(table_info.get('name'), table_info.get('cluster'), table_info.get('db') ) try: return self._driver.entity_unique_attribute(table_info['entity'], qualifiedName=table_qn) except Exception as ex: LOGGER.exception(f'Table not found. {str(ex)}') raise NotFoundException('Table URI( {table_uri} ) does not exist' .format(table_uri=table_uri))
def test_make_table_qn_only_table(self): qn = make_table_qualified_name(TB) assert qn == '{}'.format(TB)
def test_make_table_qn_without_cluster(self): qn = make_table_qualified_name(TB, db=DB) assert qn == '{}.{}'.format(DB, TB)
def test_make_table_qn_without_database(self): qn = make_table_qualified_name(TB, CL) assert qn == '{}@{}'.format(TB, CL)
def test_make_table_qn_only_table_with_default_db_cluster(self): qn = make_table_qualified_name(TB, DEFAULT_DB_CLUSTER, DEFAULT_DB_CLUSTER) assert qn == '{}'.format(TB)
def test_make_table_qn_with_default_cluster(self): qn = make_table_qualified_name(TB, DEFAULT_DB_CLUSTER, DB) assert qn == '{}.{}'.format(DB, TB)
def test_make_table_qn_with_default_database(self): qn = make_table_qualified_name(TB, CL, DEFAULT_DB_CLUSTER) assert qn == '{}@{}'.format(TB, CL)
def test_make_table_qn(self): qn = make_table_qualified_name(TB, CL, DB) assert qn == '{}.{}@{}'.format(DB, TB, CL)