Skip to content

Commit

Permalink
add is_view field to TableDetailAPI payload (#29)
Browse files Browse the repository at this point in the history
* add is_view to payload

* add test

* convert str(is_view) to boolean

* fix tests

* nit

* bump up amundsenmetadatalibrary version
  • Loading branch information
youngyjd authored and Hans Adriaans committed Jun 30, 2022
1 parent 8750451 commit 5c10d2f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
3 changes: 2 additions & 1 deletion metadata/metadata_service/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
'watermarks': fields.List(fields.Nested(watermark_fields)),
'table_writer': fields.Nested(table_writer_fields), # Optional
'last_updated_timestamp': fields.Integer, # Optional
'source': fields.Nested(source_fields) # Optional
'source': fields.Nested(source_fields), # Optional
'is_view': fields.Boolean # Optional
}


Expand Down
19 changes: 11 additions & 8 deletions metadata/metadata_service/entity/table_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,15 @@ def __init__(self, *,
schema: str,
name: str,
tags: Iterable[Tag] =(),
table_readers: Iterable[Reader] =(),
description: Optional[str] =None,
table_readers: Iterable[Reader] = (),
description: Optional[str] = None,
columns: Iterable[Column],
owners: Iterable[User] =(),
watermarks: Iterable[Watermark] =(),
table_writer: Optional[Application] =None,
owners: Iterable[User] = (),
watermarks: Iterable[Watermark] = (),
table_writer: Optional[Application] = None,
last_updated_timestamp: Optional[int],
source: Optional[Source] = None
source: Optional[Source] = None,
is_view: Optional[bool] = None,
) -> None:

self.database = database
Expand All @@ -160,13 +161,15 @@ def __init__(self, *,
self.table_writer = table_writer
self.last_updated_timestamp = last_updated_timestamp
self.source = source
self.is_view = is_view or False

def __repr__(self) -> str:
return """Table(database={!r}, cluster={!r}, schema={!r}, name={!r}, tags={!r}, table_readers={!r},
description={!r}, columns={!r}, owners={!r}, watermarks={!r}, table_writer={!r},
last_updated_timestamp={!r}, source={!r})"""\
last_updated_timestamp={!r}, source={!r}, is_view={!r})"""\
.format(self.database, self.cluster,
self.schema, self.name, self.tags,
self.table_readers, self.description,
self.columns, self.owners, self.watermarks,
self.table_writer, self.last_updated_timestamp, self.source)
self.table_writer, self.last_updated_timestamp,
self.source, self.is_view)
5 changes: 3 additions & 2 deletions metadata/metadata_service/proxy/neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def get_table(self, *, table_uri: str) -> Table:
watermarks=wmk_results,
table_writer=table_writer,
last_updated_timestamp=timestamp_value,
source=source)
source=source,
is_view=self._safe_get(last_neo4j_record, 'tbl', 'is_view'))

return table

Expand Down Expand Up @@ -233,7 +234,7 @@ def _safe_get(self, dct, *keys):
"""
for key in keys:
dct = dct.get(key)
if not dct:
if dct is None:
return None
return dct

Expand Down
2 changes: 1 addition & 1 deletion metadata/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.4'
__version__ = '1.0.5'


setup(
Expand Down
47 changes: 46 additions & 1 deletion metadata/tests/unit/proxy/test_neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,52 @@ def test_get_table(self) -> None:
id=self.table_writer['id']),
last_updated_timestamp=1,
source=Source(source='/source_file_loc',
source_type='github'))
source_type='github'),
is_view=False)

self.assertEqual(str(expected), str(table))

def test_get_table_view_only(self) -> None:
col_usage_return_value = copy.deepcopy(self.col_usage_return_value)
for col in col_usage_return_value:
col['tbl']['is_view'] = True

with patch.object(GraphDatabase, 'driver'), patch.object(Neo4jProxy, '_execute_cypher_query') as mock_execute:
mock_execute.side_effect = [col_usage_return_value, [], self.table_level_return_value]

neo4j_proxy = Neo4jProxy(host='DOES_NOT_MATTER', port=0000)
table = neo4j_proxy.get_table(table_uri='dummy_uri')

expected = 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'),
is_view=True)

self.assertEqual(str(expected), str(table))

Expand Down

0 comments on commit 5c10d2f

Please sign in to comment.