Skip to content

Commit

Permalink
feat: Add query text and query URL into Dashboard detail API (#140)
Browse files Browse the repository at this point in the history
* Dashboard query text and URL

* Update

* Update

* Flake8

* Update
  • Loading branch information
jinhyukchang authored Jun 3, 2020
1 parent f51001f commit 850827a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
21 changes: 19 additions & 2 deletions metadata_service/api/swagger_doc/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,19 @@ components:
type: string
query_names:
type: array
description: 'Chart names associated with the Dashboard'
description: '[DEPRECATED] Chart names associated with the Dashboard'
items:
type: string
frequent_users:
type: array
description: 'List of queries used by this Dashboard'
items:
$ref: '#/components/schemas/UserDetailFields'
tables:
type: array
description: 'Tables that is used in Dashboard'
items:
$ref: '#/components/schemas/PopularTables'
$ref: '#/components/schemas/DashboardQuery'
tags:
type: array
description: 'Tags tagged on Dashboard'
Expand Down Expand Up @@ -347,6 +352,18 @@ components:
last_successful_run_timestamp:
type: int
description: 'Dashboard last run timestamp in epoch'
DashboardQuery:
type: object
properties:
query_name:
type: string
description: 'Name of the query'
query_url:
type: string
description: 'URL of the query'
query_text:
type: string
description: 'Query statement text'
ErrorResponse:
type: object
properties:
Expand Down
8 changes: 5 additions & 3 deletions metadata_service/entity/dashboard_detail.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import List
from typing import Optional

import attr
from amundsen_common.models.popular_table import PopularTable
from amundsen_common.models.table import Tag
from amundsen_common.models.user import User
from marshmallow_annotations.ext.attrs import AttrsSchema

from amundsen_common.models.table import Tag
from typing import Optional
from metadata_service.entity.dashboard_query import DashboardQuery


@attr.s(auto_attribs=True, kw_only=True)
Expand All @@ -27,7 +28,8 @@ class DashboardDetail:
owners: List[User] = attr.ib(factory=list)
frequent_users: List[User] = attr.ib(factory=list)
chart_names: List[str] = attr.ib(factory=list)
query_names: List[str] = attr.ib(factory=list)
query_names: List[str] = attr.ib(factory=list) # DEPRECATED
queries: List[DashboardQuery] = attr.ib(factory=list)
tables: List[PopularTable] = attr.ib(factory=list)
tags: List[Tag] = attr.ib(factory=list)
badges: List[Tag] = attr.ib(factory=list)
Expand Down
17 changes: 17 additions & 0 deletions metadata_service/entity/dashboard_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Optional

import attr
from marshmallow_annotations.ext.attrs import AttrsSchema


@attr.s(auto_attribs=True, kw_only=True)
class DashboardQuery:
name: Optional[str] = attr.ib(default=None)
url: Optional[str] = attr.ib(default=None)
query_text: Optional[str] = attr.ib(default=None)


class DashboardQuerySchema(AttrsSchema):
class Meta:
target = DashboardQuery
register_as_scheme = True
7 changes: 6 additions & 1 deletion metadata_service/proxy/neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from neo4j.v1 import BoltStatementResult, Driver, GraphDatabase # noqa: F401

from metadata_service.entity.dashboard_detail import DashboardDetail as DashboardDetailEntity
from metadata_service.entity.dashboard_query import DashboardQuery as DashboardQueryEntity
from metadata_service.entity.description import Description
from metadata_service.entity.resource_type import ResourceType
from metadata_service.entity.tag_detail import TagDetail
Expand Down Expand Up @@ -1086,7 +1087,7 @@ def get_dashboard(self,
sum(read.read_count) as recent_view_count
OPTIONAL MATCH (d)-[:HAS_QUERY]->(query:Query)
WITH c, dg, d, description, last_exec, last_success_exec, t, owners, tags,
recent_view_count, collect(query) as queries
recent_view_count, collect({name: query.name, url: query.url, query_text: query.query_text}) as queries
OPTIONAL MATCH (d)-[:HAS_QUERY]->(query:Query)-[:HAS_CHART]->(chart:Chart)
WITH c, dg, d, description, last_exec, last_success_exec, t, owners, tags,
recent_view_count, queries, collect(chart) as charts
Expand Down Expand Up @@ -1127,7 +1128,10 @@ def get_dashboard(self,
owners = [self._build_user_from_record(record=owner) for owner in record['owners']]
tags = [Tag(tag_type=tag['tag_type'], tag_name=tag['key']) for tag in record['tags']]
chart_names = [chart['name'] for chart in record['charts'] if 'name' in chart and chart['name']]
# TODO Deprecate query_names in favor of queries after several releases from v2.5.0
query_names = [query['name'] for query in record['queries'] if 'name' in query and query['name']]
queries = [DashboardQueryEntity(**query) for query in record['queries']
if query.get('name') or query.get('url') or query.get('text')]
tables = [PopularTable(**table) for table in record['tables'] if 'name' in table and table['name']]

return DashboardDetailEntity(uri=record['uri'],
Expand All @@ -1149,6 +1153,7 @@ def get_dashboard(self,
recent_view_count=record['recent_view_count'],
chart_names=chart_names,
query_names=query_names,
queries=queries,
tables=tables
)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

__version__ = '2.5.0'
__version__ = '2.5.1'


requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/proxy/test_neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from metadata_service import create_app
from metadata_service.entity.dashboard_detail import DashboardDetail
from metadata_service.entity.dashboard_query import DashboardQuery
from metadata_service.entity.resource_type import ResourceType
from metadata_service.entity.tag_detail import TagDetail
from metadata_service.exception import NotFoundException
Expand Down Expand Up @@ -732,7 +733,8 @@ def test_get_dashboard(self) -> None:
}
],
'charts': [{'name': 'chart1'}, {'name': 'chart2'}],
'queries': [{'name': 'query1'}, {'name': 'query2'}],
'queries': [{'name': 'query1'}, {'name': 'query2', 'url': 'http://foo.bar/query',
'query_text': 'SELECT * FROM foo.bar'}],
'tables': [
{
'database': 'db1',
Expand Down Expand Up @@ -795,6 +797,9 @@ def test_get_dashboard(self) -> None:
employee_type='teamMember', manager_fullname='')],
frequent_users=[], chart_names=['chart1', 'chart2'],
query_names=['query1', 'query2'],
queries=[DashboardQuery(name='query1'),
DashboardQuery(name='query2', url='http://foo.bar/query',
query_text='SELECT * FROM foo.bar')],
tables=[
PopularTable(database='db1',
name='table1',
Expand Down

0 comments on commit 850827a

Please sign in to comment.