Skip to content

Commit

Permalink
atlas_lineage | 🎉 Initial commit.
Browse files Browse the repository at this point in the history
Signed-off-by: mgorsk1 <gorskimariusz13@gmail.com>
  • Loading branch information
mgorsk1 committed May 16, 2021
1 parent c441ed7 commit 4a30e61
Show file tree
Hide file tree
Showing 12 changed files with 724 additions and 171 deletions.
2 changes: 1 addition & 1 deletion common/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
format = pylint
exclude = .svc,CVS,.bzr,.hg,.git,__pycache__,venv
exclude = .svc,CVS,.bzr,.hg,.git,__pycache__,venv,.venv
max-complexity = 10
max-line-length = 120

Expand Down
1 change: 1 addition & 0 deletions databuilder/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exclude =
.git,
__pycache__,
venv,
.venv,
build,
databuilder/sql_parser/usage/presto/antlr_generated
max-complexity = 10
Expand Down
19 changes: 10 additions & 9 deletions frontend/amundsen_application/api/utils/metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0

import logging
import urllib.parse

from dataclasses import dataclass
from marshmallow import EXCLUDE
Expand All @@ -29,14 +28,16 @@ def __str__(self) -> str:

@classmethod
def from_uri(cls, uri: str) -> 'TableUri':
parsed = urllib.parse.urlparse(uri)
cluster, schema = parsed.netloc.rsplit('.', 1)
return TableUri(
database=parsed.scheme,
cluster=cluster,
schema=schema,
table=parsed.path.lstrip('/')
)
"""
TABLE_KEY_FORMAT = '{db}://{cluster}.{schema}/{tbl}'
"""
pattern = re.compile(r'^(?P<database>.*?)://(?P<cluster>.*)\.(?P<schema>.*?)/(?P<table>.*?)$', re.X)

groups = pattern.match(uri)

spec = groups.groupdict() if groups else {}

return TableUri(**spec)


def marshall_table_partial(table_dict: Dict) -> Dict:
Expand Down
2 changes: 1 addition & 1 deletion frontend/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
format = pylint
exclude = .svc,CVS,.bzr,.hg,.git,__pycache__,venv,venv3,node_modules
exclude = .svc,CVS,.bzr,.hg,.git,__pycache__,venv,venv3,.venv,node_modules
max-complexity = 10
max-line-length = 120
ignore = W503
Expand Down
26 changes: 18 additions & 8 deletions frontend/tests/unit/utils/test_metadata_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright Contributors to the Amundsen project.
# SPDX-License-Identifier: Apache-2.0

from typing import Dict
import unittest
from typing import Dict

from amundsen_application import create_app
from amundsen_application.api.utils.metadata_utils import _convert_prog_descriptions, _sort_prog_descriptions, \
_parse_editable_rule, is_table_editable, TableUri
from amundsen_application.config import MatchRuleObject
from amundsen_application import create_app

local_app = create_app('amundsen_application.config.TestConfig', 'tests/templates')

Expand Down Expand Up @@ -197,11 +197,21 @@ def test_schema_table_match_rule(self) -> None:
class TableUriObject(unittest.TestCase):
def test_simple_constructor(self) -> None:
uri = TableUri("db", "clstr", "schm", "tbl")
self.assertEqual(str(uri), 'db://clstr.schm/tbl')
self.assertEqual('db://clstr.schm/tbl', str(uri))

def test_from_uri_factory(self) -> None:
uri = TableUri.from_uri("db://clstr.with.dots.schm/tbl/with/slashes")
self.assertEqual(uri.database, 'db')
self.assertEqual(uri.cluster, 'clstr.with.dots')
self.assertEqual(uri.schema, 'schm')
self.assertEqual(uri.table, 'tbl/with/slashes')
params = [
('db', 'cluster', 'schema', 'table'),
('db_underscore', 'cluster.with.dots', 'schema', 'table/with/slashes'),
('db.dot', 'cluster.dot', 'schema', 'table.dot'),
('hive_table', 'demo', 'test_schema', 'test_table')
]

for db, cluster, schema, table in params:
with self.subTest():
_uri = f'{db}://{cluster}.{schema}/{table}'
uri = TableUri.from_uri(_uri)
self.assertEqual(db, uri.database)
self.assertEqual(cluster, uri.cluster)
self.assertEqual(schema, uri.schema)
self.assertEqual(table, uri.table)
Loading

0 comments on commit 4a30e61

Please sign in to comment.