Skip to content

Commit

Permalink
Use PopularTable model when return user resource (#44)
Browse files Browse the repository at this point in the history
* Use PopularTable model when return user resource

* Update pypi version
  • Loading branch information
feng-tao authored May 20, 2019
1 parent 00b98d2 commit 7184471
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 44 deletions.
4 changes: 2 additions & 2 deletions metadata_service/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +23,7 @@
}

table_list_fields = {
'table': fields.List(fields.Nested(table_detail_fields))
'table': fields.List(fields.Nested(popular_table_fields))
}


Expand Down
9 changes: 7 additions & 2 deletions metadata_service/proxy/neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

__version__ = '1.0.6'
__version__ = '1.0.7'


setup(
Expand Down
59 changes: 20 additions & 39 deletions tests/unit/proxy/test_neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand All @@ -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='[email protected]')],
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:
Expand Down

0 comments on commit 7184471

Please sign in to comment.