-
Notifications
You must be signed in to change notification settings - Fork 0
/
atlas_lookups.py
121 lines (91 loc) · 2.36 KB
/
atlas_lookups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""Load atlas lookups to solr search."""
import os
from functools import partial
from types import SimpleNamespace
from typing import Dict
from dotenv import load_dotenv
load_dotenv()
SOLRLOOKUPURL = os.environ.get(
"SOLRLOOKUPURL", "https://solr.example.com/solr/atlas_lookups"
)
from functions import clean_doc, connect, rows, solr_load_batch
def build_doc(lookup: SimpleNamespace) -> Dict:
"""Build lookup doc."""
doc = {
"id": lookup.id,
"atlas_id": lookup.atlas_id,
"item_type": lookup.item_type,
"item_name": lookup.item_name,
}
return clean_doc(doc)
cnxn, cursor = connect()
cursor.execute(
"""
select
concat('financial_impact_', cast(id as nvarchar)) as id,
'financial_impact' as item_type,
Name as 'item_name',
id as 'atlas_id'
from app.FinancialImpact
union all
select
concat('fragility_', cast(id as nvarchar)) as id,
'fragility' as item_type,
name as 'item_name',
id as 'atlas_id'
from app.Fragility
union all
select
concat('fragility_tag_', cast(id as nvarchar)) as id,
'fragility_tag' as item_type,
name as 'item_name',
id as 'atlas_id'
from app.FragilityTag
union all
select
concat('maintenance_log_status_', cast(id as nvarchar)) as id,
'maintenance_log_status' as item_type,
name as 'item_name',
id as 'atlas_id'
from app.MaintenanceLogStatus
union all
select
concat('maintenance_schedule_', cast(id as nvarchar)) as id,
'maintenance_schedule' as item_type,
name as 'item_name',
id as 'atlas_id'
from app.MaintenanceSchedule
union all
select
concat('organizational_value_', cast(id as nvarchar)) as id,
'organizational_value' as item_type,
name as 'item_name',
id as 'atlas_id'
from app.OrganizationalValue
union all
select
concat('run_frequency_', cast(id as nvarchar)) as id,
'run_frequency' as item_type,
name as 'item_name',
id as 'atlas_id'
from app.EstimatedRunFrequency
union all
select
concat('strategic_importance_', cast(id as nvarchar)) as id,
'strategic_importance' as item_type,
Name as 'item_name',
id as 'atlas_id'
from app.StrategicImportance
union all
select
concat('user_roles_', cast(UserRolesId as nvarchar)) as id,
'user_roles' as item_type,
Name as 'item_name',
UserRolesId as 'atlas_id'
from app.UserRoles
"""
)
columns = [column[0] for column in cursor.description]
batch_loader = partial(solr_load_batch, build_doc, SOLRLOOKUPURL)
list(map(batch_loader, rows(cursor, columns)))
cnxn.close()