Skip to content

Commit e271808

Browse files
authored
Merge pull request #64 from ikanashov/MG-3809
MG-3809 harmonize with new version of DD-API and DD-UI
2 parents 41cfc9c + bc8e836 commit e271808

File tree

89 files changed

+8356
-1668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+8356
-1668
lines changed

data-detective-etl/common/builders/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from common.builders.table_info_builder import (
2-
TableInfoDescriptionType,
3-
TableInfoBuilder
4-
)
1+
from common.builders.table_info_builder import TableInfoDescriptionType, TableInfoBuilder
52
from common.builders.html_info_builder import HtmlInfoBuilder
63
from common.builders.code_builder import CodeBuilder
74
from common.builders.json_system_builder import JsonSystemBuilder

data-detective-etl/common/builders/code_builder.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55

66
class CodeBuilder:
77

8-
__slots__ = ('_header', '_language', '_key', '_data', '_opened',)
8+
__slots__ = (
9+
'_header',
10+
'_language',
11+
'_key',
12+
'_data',
13+
'_opened',
14+
)
915

1016
def __init__(
11-
self,
12-
header: str = None,
13-
language: str = None,
14-
key: List[str] = None,
15-
data: str = None,
16-
opened: bool = True,
17+
self,
18+
header: str = None,
19+
language: str = None,
20+
key: List[str] = None,
21+
data: str = None,
22+
opened: bool = True,
1723
):
1824
self._header = header
1925
self._language = language
@@ -22,13 +28,13 @@ def __init__(
2228
self._opened = opened
2329

2430
def __call__(
25-
self,
26-
header: str = None,
27-
language: str = None,
28-
key: List[str] = None,
29-
data: str = None,
30-
opened: bool = None,
31-
**kwargs
31+
self,
32+
header: str = None,
33+
language: str = None,
34+
key: List[str] = None,
35+
data: str = None,
36+
opened: bool = None,
37+
**kwargs,
3238
) -> _CodeInfoResultType:
3339
if opened is None:
3440
opened = self._opened

data-detective-etl/common/builders/html_info_builder.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ class HtmlInfoBuilder:
99
"""Build html_info by source data
1010
build block with data field and container contents
1111
"""
12+
1213
__slots__ = ('_header_mapping', '_type', '_opened')
1314

14-
def __init__(self, header_mapping: Mapping[Text, Text],
15-
opened: bool = None):
15+
def __init__(self, header_mapping: Mapping[Text, Text], opened: bool = None):
1616
self._header_mapping = header_mapping
1717
self._opened = opened
1818

1919
def __call__(self, row_data) -> _HtmlInfoResultType:
20-
return [{'data': row_data[k], 'header': v, 'opened': str(int(self._opened))} if isinstance(self._opened, bool)
21-
else {'data': row_data[k], 'header': v} for k, v in self._header_mapping.items()
22-
if isnotempty(row_data.get(k))]
20+
return [
21+
{'data': row_data[k], 'header': v, 'opened': str(int(self._opened))}
22+
if isinstance(self._opened, bool)
23+
else {'data': row_data[k], 'header': v}
24+
for k, v in self._header_mapping.items()
25+
if isnotempty(row_data.get(k))
26+
]

data-detective-etl/common/builders/json_system_builder.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ class JsonSystemBuilder:
88
__slots__ = ('_system_for_search', '_type_for_search', '_card_type', '_business_type')
99

1010
def __init__(
11-
self,
12-
system_for_search: str = None,
13-
type_for_search: str = None,
14-
card_type: str = None,
15-
business_type: str = None,
11+
self,
12+
system_for_search: str = None,
13+
type_for_search: str = None,
14+
card_type: str = None,
15+
business_type: str = None,
1616
):
1717
self._system_for_search = system_for_search
1818
self._type_for_search = type_for_search
1919
self._card_type = card_type
2020
self._business_type = business_type
2121

2222
def __call__(
23-
self,
24-
system_for_search: str = None,
25-
type_for_search: str = None,
26-
card_type: str = None,
27-
business_type: str = None,
28-
**kwargs
23+
self,
24+
system_for_search: str = None,
25+
type_for_search: str = None,
26+
card_type: str = None,
27+
business_type: str = None,
28+
**kwargs,
2929
) -> _JsonSystemResultType:
3030
result = dict(
3131
system_for_search=system_for_search or self._system_for_search,

data-detective-etl/common/builders/link_builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self, link_types: Mapping[Text, Text] = None):
1313
self._link_types = link_types or self._map
1414

1515
def __call__(self, row_data) -> _LinkResultType:
16-
result = [{'link': row_data.pop(k), 'type': v}
17-
for k, v in self._link_types.items() if isnotempty(row_data.get(k))]
16+
result = [
17+
{'link': row_data.pop(k), 'type': v} for k, v in self._link_types.items() if isnotempty(row_data.get(k))
18+
]
1819
return result or None

data-detective-etl/common/builders/table_info_builder.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
from common.utils import isnotempty
66

77

8-
_TableInfoResultType = Dict[str, Union[
9-
Optional[str],
10-
List[str],
11-
List[Optional[str]],
12-
List[Dict[str, str]],
13-
List[Dict[str, Optional[str]]]
14-
]]
8+
_TableInfoResultType = Dict[
9+
str, Union[Optional[str], List[str], List[Optional[str]], List[Dict[str, str]], List[Dict[str, Optional[str]]]]
10+
]
1511

1612

1713
class TableInfoDescriptionType(BaseModel):
@@ -31,22 +27,27 @@ def __init__(self, table: TableInfoDescriptionType):
3127

3228
def _apply_serializers(self, row_data: Dict) -> Dict:
3329
serializers = self._table.serializers or dict()
34-
return {value: serializers.get(key, str)(row_data[key])
35-
for key, value in self._table.keys.items() if isnotempty(row_data.get(key))}
30+
return {
31+
value: serializers.get(key, str)(row_data[key])
32+
for key, value in self._table.keys.items()
33+
if isnotempty(row_data.get(key))
34+
}
3635

3736
@staticmethod
3837
def _get_all_keys(row_data):
39-
return {k for row in row_data for k in row.keys()} \
40-
if isinstance(row_data, (list, tuple)) else row_data.keys()
38+
return {k for row in row_data for k in row.keys()} if isinstance(row_data, (list, tuple)) else row_data.keys()
4139

4240
def _get_kv_table(self, row_data) -> _TableInfoResultType:
4341
serializers: Dict[Text, Callable[..., Text]] = self._table.serializers or dict()
4442
return dict(
4543
columns=['Key', 'Value'],
46-
data=[{'Key': value, 'Value': serializers.get(key, str)(row_data[key])}
47-
for key, value in self._table.keys.items() if isnotempty(row_data.get(key))],
44+
data=[
45+
{'Key': value, 'Value': serializers.get(key, str)(row_data[key])}
46+
for key, value in self._table.keys.items()
47+
if isnotempty(row_data.get(key))
48+
],
4849
header=self._table.header,
49-
display_headers=self._table.display_headers
50+
display_headers=self._table.display_headers,
5051
)
5152

5253
def _get_table(self, row_data) -> _TableInfoResultType:
@@ -55,10 +56,11 @@ def _get_table(self, row_data) -> _TableInfoResultType:
5556
columns.sort()
5657
return dict(
5758
columns=columns,
58-
data=[self._apply_serializers(row) for row in row_data] if isinstance(row_data, list)
59+
data=[self._apply_serializers(row) for row in row_data]
60+
if isinstance(row_data, list)
5961
else [self._apply_serializers(row_data)],
6062
header=self._table.header,
61-
display_headers=self._table.display_headers
63+
display_headers=self._table.display_headers,
6264
)
6365

6466
def get_table(self, row_data) -> _TableInfoResultType:

data-detective-etl/common/root_tree_generator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ def print_table(table):
3636
print('```')
3737
bfs(graph_yaml, 'root', root_table=root)
3838
print('```')
39-
print('''
39+
print(
40+
'''
4041
Description of hierarchy of root entities:
4142
4243
| Name | Path to entity | Entity type | Info |
43-
| --- | --- | --- | --- |''')
44+
| --- | --- | --- | --- |'''
45+
)
4446
print_table(root)

data-detective-etl/common/utilities/entity_enums.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
from collections import namedtuple
2+
from enum import Enum
13
from typing import FrozenSet
24

35

4-
class EntityTypes:
5-
TREE_NODE = 'TREE_NODE'
6-
SCHEMA = 'SCHEMA'
7-
TABLE = 'TABLE'
8-
COLUMN = 'COLUMN'
9-
JOB = 'JOB'
10-
LOGICAL_SCHEMA = 'LOGICAL_SCHEMA'
11-
LOGICAL_TABLE = 'LOGICAL_TABLE'
12-
LOGICAL_COLUMN = 'LOGICAL_COLUMN'
13-
LOGICAL_REPORT = 'LOGICAL_REPORT'
6+
class EntityTypes(namedtuple('EntityType', 'key message_code'), Enum):
7+
TREE_NODE = 'TREE_NODE', 'data.entity.entity-type.tree-node'
8+
SCHEMA = 'SCHEMA', 'data.entity.entity-type.schema'
9+
TABLE = 'TABLE', 'data.entity.entity-type.table'
10+
COLUMN = 'COLUMN', 'data.entity.entity-type.column'
11+
JOB = 'JOB', 'data.entity.entity-type.job'
12+
LOGICAL_SCHEMA = 'LOGICAL_SCHEMA', 'data.entity.entity-type.logical-schema'
13+
LOGICAL_TABLE = 'LOGICAL_TABLE', 'data.entity.entity-type.logical-table'
14+
LOGICAL_COLUMN = 'LOGICAL_COLUMN', 'data.entity.entity-type.logical-column'
15+
LOGICAL_REPORT = 'LOGICAL_REPORT', 'data.entity.entity-type.logical-report'
1416

1517

1618
class EntityFields:
@@ -45,8 +47,16 @@ class RelationFields:
4547
ATTRIBUTE = 'attribute'
4648

4749

48-
ENTITY_CORE_FIELDS: FrozenSet[str] = frozenset({EntityFields.URN, EntityFields.ENTITY_TYPE,
49-
EntityFields.ENTITY_NAME, EntityFields.ENTITY_NAME_SHORT,
50-
EntityFields.JSON_DATA, EntityFields.SEARCH_DATA})
51-
RELATION_CORE_FIELDS: FrozenSet[str] = frozenset({RelationFields.SOURCE, RelationFields.DESTINATION,
52-
RelationFields.TYPE, RelationFields.ATTRIBUTE})
50+
ENTITY_CORE_FIELDS: FrozenSet[str] = frozenset(
51+
{
52+
EntityFields.URN,
53+
EntityFields.ENTITY_TYPE,
54+
EntityFields.ENTITY_NAME,
55+
EntityFields.ENTITY_NAME_SHORT,
56+
EntityFields.JSON_DATA,
57+
EntityFields.SEARCH_DATA,
58+
}
59+
)
60+
RELATION_CORE_FIELDS: FrozenSet[str] = frozenset(
61+
{RelationFields.SOURCE, RelationFields.DESTINATION, RelationFields.TYPE, RelationFields.ATTRIBUTE}
62+
)
Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,51 @@
11
from collections import namedtuple
22
from enum import Enum
3+
from typing import Union
34

45
SYSTEM_FOR_SEARCH = 'system_for_search'
56
TYPE_FOR_SEARCH = 'type_for_search'
67

78

89
# https://stackoverflow.com/a/62601113/4545870
9-
class SystemForSearch(namedtuple('SearchSystem', 'name description'), Enum):
10-
ORACLE = 'Oracle', 'Oracle databases from replication'
11-
POSTGRES = 'Postgres', 'Postgres databases from replication'
12-
LOGICAL_MODEL = 'Logical Model', 'Logical Model DWH'
13-
DATA_DETECTIVE = 'Data Detective', 'Data Catalog for entities of any type'
10+
class SystemForSearch(namedtuple('SearchSystem', 'name title_code info_code'), Enum):
11+
ORACLE = 'Oracle', 'data.search.filters.system.oracle.title', 'data.search.filters.system.oracle.info'
12+
POSTGRES = 'Postgres', 'data.search.filters.system.postgres.title', 'data.search.filters.system.postgres.info'
13+
LOGICAL_MODEL = (
14+
'Logical_Model',
15+
'data.search.filters.system.logical-model.title',
16+
'data.search.filters.system.logical-model.info',
17+
)
18+
DATA_DETECTIVE = (
19+
'Data Detective',
20+
'data.search.filters.system.data-detective.title',
21+
'data.search.filters.system.data-detective.info',
22+
)
1423

1524
def __str__(self) -> str:
1625
return self.name
1726

1827

19-
class TypeForSearch(namedtuple('SearchType', 'name description'), Enum):
20-
COLUMN = 'Column', 'Physical column of physical table'
21-
TABLE = 'Table', 'Physical table or view in database'
22-
SCHEMA = 'Schema', 'Physical schema in database'
23-
DATABASE = 'Database', 'Database from DBMS'
24-
JOB = 'Job', 'ETL job, pipeline, DAG or workflow'
25-
LOGICAL_SCHEMA = 'Logical Schema', 'Logical schema in model'
26-
LOGICAL_TABLE = 'Logical Table', 'Logical table in model'
27-
LOGICAL_COLUMN = 'Logical Column', 'Column in logical table'
28+
class TypeForSearch(namedtuple('SearchType', 'name title_code info_code'), Enum):
29+
COLUMN = 'Column', 'data.search.filters.type.column.title', 'data.search.filters.type.column.info'
30+
TABLE = 'Table', 'data.search.filters.type.table.title', 'data.search.filters.type.table.info'
31+
SCHEMA = 'Schema', 'data.search.filters.type.schema.title', 'data.search.filters.type.schema.info'
32+
DATABASE = 'Database', 'data.search.filters.type.database.title', 'data.search.filters.type.database.info'
33+
JOB = 'Job', 'data.search.filters.type.job.title', 'data.search.filters.type.job.info'
34+
LOGICAL_SCHEMA = (
35+
'Logical Schema',
36+
'data.search.filters.type.logical-schema.title',
37+
'data.search.filters.type.logical-schema.info',
38+
)
39+
LOGICAL_TABLE = (
40+
'Logical Table',
41+
'data.search.filters.type.logical-table.title',
42+
'data.search.filters.type.logical-table.info',
43+
)
44+
LOGICAL_COLUMN = (
45+
'Logical Column',
46+
'data.search.filters.type.logical-column.title',
47+
'data.search.filters.type.logical-column.info',
48+
)
2849

2950
def __str__(self) -> str:
3051
return self.name
@@ -38,3 +59,39 @@ class CardType(namedtuple('CardType', 'name description'), Enum):
3859

3960
def __str__(self) -> str:
4061
return self.name
62+
63+
64+
system_for_search_x_type_for_search: list[dict[str, Union[str, list[str]]]] = [
65+
{
66+
"system_name": SystemForSearch.ORACLE.name,
67+
"type_name": [
68+
TypeForSearch.COLUMN.name,
69+
TypeForSearch.TABLE.name,
70+
TypeForSearch.SCHEMA.name,
71+
TypeForSearch.DATABASE.name,
72+
],
73+
},
74+
{
75+
"system_name": SystemForSearch.POSTGRES.name,
76+
"type_name": [
77+
TypeForSearch.COLUMN.name,
78+
TypeForSearch.TABLE.name,
79+
TypeForSearch.SCHEMA.name,
80+
TypeForSearch.DATABASE.name,
81+
],
82+
},
83+
{
84+
"system_name": SystemForSearch.LOGICAL_MODEL.name,
85+
"type_name": [
86+
TypeForSearch.LOGICAL_COLUMN.name,
87+
TypeForSearch.LOGICAL_TABLE.name,
88+
TypeForSearch.LOGICAL_SCHEMA.name,
89+
],
90+
},
91+
{
92+
"system_name": SystemForSearch.DATA_DETECTIVE.name,
93+
"type_name": [
94+
TypeForSearch.JOB.name,
95+
],
96+
},
97+
]

0 commit comments

Comments
 (0)