diff --git a/metadata_service/api/user.py b/metadata_service/api/user.py index 37f704c1..a2b255db 100644 --- a/metadata_service/api/user.py +++ b/metadata_service/api/user.py @@ -3,7 +3,7 @@ from flask_restful import Resource, fields, marshal -from metadata_service.api.table import table_detail_fields +from metadata_service.api.popular_tables import popular_table_fields from metadata_service.exception import NotFoundException from metadata_service.proxy import get_proxy_client from metadata_service.util import UserResourceRel @@ -23,7 +23,7 @@ } table_list_fields = { - 'table': fields.List(fields.Nested(table_detail_fields)) + 'table': fields.List(fields.Nested(popular_table_fields)) } diff --git a/metadata_service/proxy/neo4j_proxy.py b/metadata_service/proxy/neo4j_proxy.py index 44ce9d0c..d282c60f 100644 --- a/metadata_service/proxy/neo4j_proxy.py +++ b/metadata_service/proxy/neo4j_proxy.py @@ -771,8 +771,13 @@ def get_table_by_user_relation(self, *, user_email: str, relation_type: UserReso table_records = record.single().get('table_records', []) for record in table_records: - # todo: decide whether we want to return a list of table entities or just table_uri - results.append(self.get_table(table_uri=record['key'])) + _, last_neo4j_record = self._exec_col_query(record['key']) + results.append(PopularTable( + database=last_neo4j_record['db']['name'], + cluster=last_neo4j_record['clstr']['name'], + schema=last_neo4j_record['schema']['name'], + name=last_neo4j_record['tbl']['name'], + description=self._safe_get(last_neo4j_record, 'tbl_dscrpt', 'description'))) return {'table': results} @timer_with_counter diff --git a/setup.py b/setup.py index 240d142b..2e994baa 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -__version__ = '1.0.6' +__version__ = '1.0.7' setup( diff --git a/tests/unit/proxy/test_neo4j_proxy.py b/tests/unit/proxy/test_neo4j_proxy.py index bd9f50cb..c241b7b8 100644 --- a/tests/unit/proxy/test_neo4j_proxy.py +++ b/tests/unit/proxy/test_neo4j_proxy.py @@ -505,7 +505,7 @@ def test_get_users(self) -> None: def test_get_resources_by_user_relation(self) -> None: with patch.object(GraphDatabase, 'driver'), \ patch.object(Neo4jProxy, '_execute_cypher_query') as mock_execute, \ - patch.object(Neo4jProxy, 'get_table') as mock_get_table: + patch.object(Neo4jProxy, '_exec_col_query') as mock_col_query: mock_execute.return_value.single.return_value = { 'table_records': [ @@ -515,49 +515,30 @@ def test_get_resources_by_user_relation(self) -> None: } ] } - mock_get_table.return_value = Table(database='hive', - cluster='gold', - schema='foo_schema', - name='foo_table', - tags=[Tag(tag_name='test', tag_type='default')], - table_readers=[], description='foo description', - watermarks=[Watermark(watermark_type='high_watermark', - partition_key='ds', - partition_value='fake_value', - create_time='fake_time'), - Watermark(watermark_type='low_watermark', - partition_key='ds', - partition_value='fake_value', - create_time='fake_time')], - columns=[Column(name='bar_id_1', - description='bar col description', - col_type='varchar', - sort_order=0, stats=[Statistics(start_epoch=1, - end_epoch=1, - stat_type='avg', - stat_val='1')]), - Column(name='bar_id_2', - description='bar col2 description', - col_type='bigint', - sort_order=1, stats=[Statistics(start_epoch=2, - end_epoch=2, - stat_type='avg', - stat_val='2')])], - owners=[User(email='tester@lyft.com')], - table_writer=Application( - application_url=self.table_writer['application_url'], - description=self.table_writer['description'], - name=self.table_writer['name'], - id=self.table_writer['id']), - last_updated_timestamp=1, - source=Source(source='/source_file_loc', - source_type='github')) + + mock_col_query.return_value = 'not_related', { + 'db': { + 'name': 'db_name' + }, + 'clstr': { + 'name': 'cluster' + }, + 'schema': { + 'name': 'schema' + }, + 'tbl': { + 'name': 'table_name' + } + } neo4j_proxy = Neo4jProxy(host='DOES_NOT_MATTER', port=0000) result = neo4j_proxy.get_table_by_user_relation(user_email='test_user', relation_type=UserResourceRel.follow) self.assertEqual(len(result['table']), 1) - self.assertEqual(result['table'][0].name, 'foo_table') + self.assertEqual(result['table'][0].name, 'table_name') + self.assertEqual(result['table'][0].database, 'db_name') + self.assertEqual(result['table'][0].cluster, 'cluster') + self.assertEqual(result['table'][0].schema, 'schema') def test_add_resource_relation_by_user(self) -> None: with patch.object(GraphDatabase, 'driver') as mock_driver: