python-eigen-ingenuity 0.4.36b2__py3-none-any.whl → 0.4.37__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- eigeningenuity/auth.py +1 -1
- modelbuilder/src/assetmodelbuilder.py +2 -2
- modelbuilder/src/configmanager.py +10 -6
- modelbuilder/src/csvcontentsmanager.py +4 -8
- modelbuilder/src/processors/nodefileprocessor.py +8 -11
- modelbuilder/src/processors/propertymanager.py +31 -0
- modelbuilder/src/processors/relationshipfileprocessor.py +12 -14
- {python_eigen_ingenuity-0.4.36b2.dist-info → python_eigen_ingenuity-0.4.37.dist-info}/METADATA +1 -1
- {python_eigen_ingenuity-0.4.36b2.dist-info → python_eigen_ingenuity-0.4.37.dist-info}/RECORD +12 -13
- modelbuilder/src/fileprocessors.py +0 -691
- {python_eigen_ingenuity-0.4.36b2.dist-info → python_eigen_ingenuity-0.4.37.dist-info}/WHEEL +0 -0
- {python_eigen_ingenuity-0.4.36b2.dist-info → python_eigen_ingenuity-0.4.37.dist-info}/entry_points.txt +0 -0
- {python_eigen_ingenuity-0.4.36b2.dist-info → python_eigen_ingenuity-0.4.37.dist-info}/top_level.txt +0 -0
eigeningenuity/auth.py
CHANGED
|
@@ -82,7 +82,7 @@ def _authenticate_azure_user(baseurl):
|
|
|
82
82
|
|
|
83
83
|
if not result:
|
|
84
84
|
# So no suitable token exists in cache. Let's get a new one from Azure AD.
|
|
85
|
-
settings.
|
|
85
|
+
settings.clear_auth_token_cache()
|
|
86
86
|
result = app.acquire_token_interactive(scope,auth_uri_callback=_backup_auth_azure_user)
|
|
87
87
|
|
|
88
88
|
if "access_token" in result:
|
|
@@ -63,7 +63,7 @@ def _convert_sys_argv_(func):
|
|
|
63
63
|
@_convert_sys_argv_
|
|
64
64
|
def build(path:str='.', config:str='config.ini', file:str='', query:list=[], preprocess:list=[], postprocess:list=[], delete_all:list=[], separator:str=';',
|
|
65
65
|
start_from:int=1, end_at:int=1, no_versions:bool=False, no_system_properties:bool=False, ignore_nodes:bool=False, skip_duplicates:bool=False,
|
|
66
|
-
no_duplicates:bool=False, allow_blanks:
|
|
66
|
+
no_duplicates:bool=False, allow_blanks:list=[], batch:int=0, auth:bool=False, order:str='qnrc', primary_property:str='', required_labels:list=[],
|
|
67
67
|
required_properties:list=[], database:str='0', verify:bool=False, summarise:bool=False, show_queries:bool=False, show_returns:bool=False,
|
|
68
68
|
write_queries:str='', write_returns:str='', display_rate='auto', create_node_csv_file:bool=False, node_labels:list=[], node_properties:list=[],
|
|
69
69
|
csv_file_suffix:str='', create_relationship_csv_file:bool=False, csv_to_labels:list=[], csv_to_properties:str=''):
|
|
@@ -88,7 +88,7 @@ def build(path:str='.', config:str='config.ini', file:str='', query:list=[], pre
|
|
|
88
88
|
no_system_properties: Suppress creation of system properties on nodes and relationships. Implies -nov
|
|
89
89
|
ignore_nodes: Treat node columns in relationship files as relationship properties
|
|
90
90
|
skip_duplicates: Don't create a version node if there are no changes. Same as -nod
|
|
91
|
-
allow_blanks:
|
|
91
|
+
allow_blanks: List of properties to create even if blank
|
|
92
92
|
batch: Number of queries to batch together when processing a node .csv file, significantly improves performance
|
|
93
93
|
auth: Enable Azure Authentication
|
|
94
94
|
order: Order in which to process the input files. Default is qnrc
|
|
@@ -25,8 +25,8 @@ class ConfigManager:
|
|
|
25
25
|
parser.add_argument('-f', '--file', nargs='+', default='', help='List of input files (space separated, quoted with " where necessary)')
|
|
26
26
|
parser.add_argument('-q', '--query', nargs='+', default='', help='List of queries to run (space separated, quoted with " where necessary)')
|
|
27
27
|
parser.add_argument('-pre', '--preprocess', nargs='+', default='', help='Command(s) to execute before processing input files')
|
|
28
|
-
parser.add_argument('-post', '--postprocess', nargs='+', default='',
|
|
29
|
-
parser.add_argument('-da', '--deleteall', nargs='*', default='',help='Lists of labels to identify nodes to delete before processing any files')
|
|
28
|
+
parser.add_argument('-post', '--postprocess', nargs='+', default='', help='Command(s) to execute after processing input files')
|
|
29
|
+
parser.add_argument('-da', '--deleteall', nargs='*', default='', help='Lists of labels to identify nodes to delete before processing any files')
|
|
30
30
|
|
|
31
31
|
# This next set change the behaviour of the processing away from the default
|
|
32
32
|
parser.add_argument('-s', '--separator', default=';', help="The separator used in the csv files. Default is a semi-colon ';'")
|
|
@@ -38,7 +38,7 @@ class ConfigManager:
|
|
|
38
38
|
parser.add_argument('-in', '--ignorenodes', action='store_true', help='Treat node columns in relationship files as relationship properties')
|
|
39
39
|
parser.add_argument('-sd', '--skipduplicates', action='store_true', help='Don\'t create a version node if there are no changes. Same as -nod')
|
|
40
40
|
parser.add_argument('-nod', '--noduplicates', action='store_true', help='Don\'t create a version node if there are no changes. Same as -sd')
|
|
41
|
-
parser.add_argument('-ab', '--allowblanks',
|
|
41
|
+
parser.add_argument('-ab', '--allowblanks', nargs='*', default='', help='Update a node_key even if it is blank')
|
|
42
42
|
parser.add_argument('-b', '--batch', default=0, type=int, help='Number of queries to batch together when processing a node .csv file')
|
|
43
43
|
parser.add_argument('-a', '--auth', action='store_true', help='Enable Azure Authentication')
|
|
44
44
|
default_order = 'qnrc'
|
|
@@ -90,7 +90,11 @@ class ConfigManager:
|
|
|
90
90
|
self.stop_on_failure = args.stoponfailure
|
|
91
91
|
self.ignore_nodes = args.ignorenodes
|
|
92
92
|
self.no_duplicates = args.skipduplicates or args.noduplicates
|
|
93
|
-
|
|
93
|
+
blank_properties_list = args.allowblanks
|
|
94
|
+
if blank_properties_list != '':
|
|
95
|
+
self.blank_properties_list = pm.validate_property_keys(blank_properties_list)
|
|
96
|
+
else:
|
|
97
|
+
self.blank_properties_list = ''
|
|
94
98
|
self.batch_rate = args.batch
|
|
95
99
|
self.auth = args.auth
|
|
96
100
|
|
|
@@ -345,8 +349,8 @@ class ConfigManager:
|
|
|
345
349
|
def get_ignore_nodes(self):
|
|
346
350
|
return self.ignore_nodes
|
|
347
351
|
|
|
348
|
-
def
|
|
349
|
-
return self.
|
|
352
|
+
def get_blank_property_list(self):
|
|
353
|
+
return self.blank_properties_list
|
|
350
354
|
|
|
351
355
|
def get_batch_rate(self):
|
|
352
356
|
return self.batch_rate
|
|
@@ -34,14 +34,10 @@ class CSVContentsManager:
|
|
|
34
34
|
else:
|
|
35
35
|
format = ':' + part
|
|
36
36
|
|
|
37
|
-
print(f'H: {header} -> ({key}, {format}, {type})')
|
|
38
|
-
|
|
39
37
|
return key, format, type
|
|
40
38
|
|
|
41
|
-
print(f'HM: {header_mappings}')
|
|
42
39
|
for header in file_headers:
|
|
43
40
|
|
|
44
|
-
print(f'H: {header}')
|
|
45
41
|
this_key, this_format, this_type = split_header(header)
|
|
46
42
|
unmapped_keys += [this_key]
|
|
47
43
|
|
|
@@ -126,14 +122,14 @@ class CSVContentsManager:
|
|
|
126
122
|
properties_list = [{self.mapped_keys[column]+self.formats[column]:this_row[column]} for column in column_numbers if len(this_row[column])]
|
|
127
123
|
return properties_list
|
|
128
124
|
|
|
129
|
-
def get_property_values_dict(self, row_number, column_numbers,
|
|
125
|
+
def get_property_values_dict(self, row_number, column_numbers, allow_blank_property_list, default_key='', prefix=''):
|
|
130
126
|
this_row = self.data_list[row_number]
|
|
131
127
|
split_values = [this_row[column].split('::') for column in column_numbers]
|
|
132
|
-
this_list = {prefix + (self.mapped_keys[column] or default_key) + self.formats[column]: this_row[column] if len(split_values[count]) == 1 else {prefix + split_values[count][0] + self.formats[column]: split_values[count][1]} for count, column in enumerate(column_numbers) if this_row[column] or
|
|
128
|
+
this_list = {prefix + (self.mapped_keys[column] or default_key) + self.formats[column]: this_row[column] if len(split_values[count]) == 1 else {prefix + split_values[count][0] + self.formats[column]: split_values[count][1]} for count, column in enumerate(column_numbers) if this_row[column] or self.mapped_keys[column] in allow_blank_property_list or allow_blank_property_list == []}
|
|
133
129
|
return this_list
|
|
134
130
|
|
|
135
|
-
def get_property_values_list(self, row_number, column_numbers,
|
|
131
|
+
def get_property_values_list(self, row_number, column_numbers, default_key='', override_key=''):
|
|
136
132
|
this_row = self.data_list[row_number]
|
|
137
133
|
split_values = [this_row[column].split('::') for column in column_numbers]
|
|
138
|
-
this_list = [{(override_key or self.mapped_keys[column] or default_key) + self.formats[column]: this_row[column]} if len(split_values[count]) == 1 else {split_values[count][0] + self.formats[column]: split_values[count][1]} for count, column in enumerate(column_numbers) if this_row[column]
|
|
134
|
+
this_list = [{(override_key or self.mapped_keys[column] or default_key) + self.formats[column]: this_row[column]} if len(split_values[count]) == 1 else {split_values[count][0] + self.formats[column]: split_values[count][1]} for count, column in enumerate(column_numbers) if this_row[column]]
|
|
139
135
|
return this_list
|
|
@@ -5,6 +5,7 @@ import assetmodelutilities as amu
|
|
|
5
5
|
from queries.query import Neo4jQuery
|
|
6
6
|
import uuid
|
|
7
7
|
import processors.labelmanager as lm
|
|
8
|
+
import processors.propertymanager as pm
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
class NodeFileProcessor:
|
|
@@ -29,7 +30,7 @@ class NodeFileProcessor:
|
|
|
29
30
|
self.validate_only = config.in_validation_mode()
|
|
30
31
|
self.summarise = config.in_summary_mode()
|
|
31
32
|
|
|
32
|
-
self.
|
|
33
|
+
self.blank_property_list = config.get_blank_property_list()
|
|
33
34
|
self.batch_rate = config.get_batch_rate()
|
|
34
35
|
self.start_from = config.get_start_from()
|
|
35
36
|
self.last_row = config.get_end_at()
|
|
@@ -66,9 +67,8 @@ class NodeFileProcessor:
|
|
|
66
67
|
while this_row < last_row:
|
|
67
68
|
validated_csv_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, label_columns))
|
|
68
69
|
merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, validated_csv_labels)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
properties = {**self.required_properties, **properties}
|
|
70
|
+
row_properties = self.contents.get_property_values_dict(this_row, property_columns, self.blank_property_list)
|
|
71
|
+
properties = pm.combine_properties(self.required_properties, row_properties)
|
|
72
72
|
# Remove any properties we don't want
|
|
73
73
|
for property in self.unrequired_properties:
|
|
74
74
|
try:
|
|
@@ -81,7 +81,7 @@ class NodeFileProcessor:
|
|
|
81
81
|
else:
|
|
82
82
|
properties[property_ref_dot + k] = properties.pop(k)
|
|
83
83
|
|
|
84
|
-
for primary_property in self.contents.get_property_values_list(this_row, node_columns,
|
|
84
|
+
for primary_property in self.contents.get_property_values_list(this_row, node_columns, self.primary_property):
|
|
85
85
|
time_now = amu.get_formatted_time_now()
|
|
86
86
|
|
|
87
87
|
# Build a simple MERGE query using queries
|
|
@@ -157,13 +157,10 @@ class NodeFileProcessor:
|
|
|
157
157
|
while this_row < last_row:
|
|
158
158
|
validated_csv_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, label_columns))
|
|
159
159
|
merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, validated_csv_labels)
|
|
160
|
-
row_properties = self.contents.get_property_values_dict(this_row, property_columns,
|
|
160
|
+
row_properties = self.contents.get_property_values_dict(this_row, property_columns, self.blank_property_list)
|
|
161
161
|
|
|
162
|
-
for primary_property in self.contents.get_property_values_list(this_row, node_columns,
|
|
163
|
-
|
|
164
|
-
properties = {**self.required_properties, **row_properties}
|
|
165
|
-
else:
|
|
166
|
-
properties = row_properties.copy()
|
|
162
|
+
for primary_property in self.contents.get_property_values_list(this_row, node_columns, self.primary_property):
|
|
163
|
+
properties = pm.combine_properties(self.required_properties, row_properties)
|
|
167
164
|
# Remove any properties we don't want
|
|
168
165
|
for property in self.unrequired_properties:
|
|
169
166
|
try:
|
|
@@ -44,6 +44,14 @@ def validate_properties(properties):
|
|
|
44
44
|
else:
|
|
45
45
|
return properties
|
|
46
46
|
|
|
47
|
+
|
|
48
|
+
def validate_property_keys(key_list):
|
|
49
|
+
validated = []
|
|
50
|
+
for key in key_list:
|
|
51
|
+
validated += [*validate_properties(i.split(':')[0] for i in key.split(','))]
|
|
52
|
+
return validated
|
|
53
|
+
|
|
54
|
+
|
|
47
55
|
def sort_properties(properties):
|
|
48
56
|
validated = {}
|
|
49
57
|
unwanted = []
|
|
@@ -85,3 +93,26 @@ def combine_required_properties(config_properties, override_properties):
|
|
|
85
93
|
unwanted_properties = [i for i in unwanted_override_properties] + [i for i in unwanted_config_properties if i not in valid_override_properties.keys() and i not in retain_override_properties]
|
|
86
94
|
|
|
87
95
|
return required_properties, unwanted_properties
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def split_node_key(node):
|
|
99
|
+
split_node = node.split(':')
|
|
100
|
+
if len(split_node) == 1:
|
|
101
|
+
name = node
|
|
102
|
+
type = ''
|
|
103
|
+
else:
|
|
104
|
+
name = split_node[0]
|
|
105
|
+
type = ':' + split_node[1]
|
|
106
|
+
return name, type
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def combine_properties(default_properties, actual_properties):
|
|
110
|
+
combined_properties = default_properties.copy()
|
|
111
|
+
for property, value in actual_properties.items():
|
|
112
|
+
if value != '' or property not in default_properties.keys():
|
|
113
|
+
# Either value has been specified in csv
|
|
114
|
+
# or value is blank (can only happen if --allowblanks used) and the property is NOT in the config list
|
|
115
|
+
# (if it is in the list, we use that rather than overriding config value with blank)
|
|
116
|
+
combined_properties[property] = value
|
|
117
|
+
|
|
118
|
+
return combined_properties
|
|
@@ -5,6 +5,7 @@ import assetmodelutilities as amu
|
|
|
5
5
|
from queries.query import Neo4jQuery
|
|
6
6
|
import processors.labelmanager as lm
|
|
7
7
|
import processors.relationshipmanager as rm
|
|
8
|
+
import processors.propertymanager as pm
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
class RelationshipFileProcessor:
|
|
@@ -29,7 +30,7 @@ class RelationshipFileProcessor:
|
|
|
29
30
|
self.validate_only = config.in_validation_mode()
|
|
30
31
|
self.summarise = config.in_summary_mode()
|
|
31
32
|
|
|
32
|
-
self.
|
|
33
|
+
self.blank_property_list = config.get_blank_property_list()
|
|
33
34
|
self.batch_rate = config.get_batch_rate()
|
|
34
35
|
self.start_from = config.get_start_from()
|
|
35
36
|
self.last_row = config.get_end_at()
|
|
@@ -75,17 +76,15 @@ class RelationshipFileProcessor:
|
|
|
75
76
|
|
|
76
77
|
relationships = rm.validate_relationships(self.contents.get_column_values_list(this_row, relation_columns))
|
|
77
78
|
|
|
78
|
-
properties = self.contents.get_property_values_dict(this_row, property_columns, self.
|
|
79
|
+
properties = self.contents.get_property_values_dict(this_row, property_columns, self.blank_property_list, prefix=relation_ref_dot)
|
|
79
80
|
# If there are multiple From or To nodes, create a relationship query for each combination
|
|
80
|
-
for from_node in self.contents.get_property_values_list(this_row, from_columns,
|
|
81
|
+
for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.primary_property):
|
|
81
82
|
validated_csv_from_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, from_label_columns))
|
|
82
83
|
from_labels = lm.sort_relationship_labels(self.required_labels, validated_csv_from_labels)
|
|
83
|
-
for to_node in self.contents.get_property_values_list(this_row, to_columns,
|
|
84
|
+
for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.primary_property):
|
|
84
85
|
validated_csv_to_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, to_label_columns))
|
|
85
86
|
to_labels = lm.sort_relationship_labels(self.required_labels, validated_csv_to_labels)
|
|
86
87
|
|
|
87
|
-
# We need to create sets of updates that have the same label combinations, and relationship
|
|
88
|
-
|
|
89
88
|
# Build a MERGE query for the relationship(s)
|
|
90
89
|
for relationship in relationships:
|
|
91
90
|
for relation in relationship.split(':'):
|
|
@@ -164,12 +163,12 @@ class RelationshipFileProcessor:
|
|
|
164
163
|
last_row = self.get_last_row(num_data_rows)
|
|
165
164
|
while this_row < last_row:
|
|
166
165
|
relationships = rm.validate_relationships(self.contents.get_column_values_list(this_row, relation_columns))
|
|
167
|
-
properties = self.contents.get_property_values_dict(this_row, property_columns, self.
|
|
166
|
+
properties = self.contents.get_property_values_dict(this_row, property_columns, self.blank_property_list)
|
|
168
167
|
# If there are multiple From or To nodes, create a relationship query for each combination
|
|
169
|
-
for from_node in self.contents.get_property_values_list(this_row, from_columns,
|
|
168
|
+
for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.primary_property):
|
|
170
169
|
validated_csv_from_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, from_label_columns))
|
|
171
170
|
from_labels = lm.sort_relationship_labels(self.required_labels, validated_csv_from_labels)
|
|
172
|
-
for to_node in self.contents.get_property_values_list(this_row, to_columns,
|
|
171
|
+
for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.primary_property):
|
|
173
172
|
validated_csv_to_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, to_label_columns))
|
|
174
173
|
to_labels = lm.sort_relationship_labels(self.required_labels, validated_csv_to_labels)
|
|
175
174
|
|
|
@@ -204,8 +203,8 @@ class RelationshipFileProcessor:
|
|
|
204
203
|
from_labels = batch_keys[from_to_labels][0]
|
|
205
204
|
to_labels = batch_keys[from_to_labels][1]
|
|
206
205
|
relationship = batch_keys[from_to_labels][2]
|
|
207
|
-
from_key = batch_keys[from_to_labels][3]
|
|
208
|
-
to_key = batch_keys[from_to_labels][4]
|
|
206
|
+
from_key, from_type = pm.split_node_key(batch_keys[from_to_labels][3])
|
|
207
|
+
to_key, to_type = pm.split_node_key(batch_keys[from_to_labels][4])
|
|
209
208
|
|
|
210
209
|
batch_num = 1
|
|
211
210
|
while batch_num <= num_batches:
|
|
@@ -221,8 +220,8 @@ class RelationshipFileProcessor:
|
|
|
221
220
|
# Combine all the update data...
|
|
222
221
|
update = updates[(batch_num - 1) * self.batch_rate + this_size]
|
|
223
222
|
update_properties = update[2] or {} # In case update_properties[2] is {}
|
|
224
|
-
update_properties[from_ref] = update[0]
|
|
225
|
-
update_properties[to_ref] = update[1]
|
|
223
|
+
update_properties[from_ref + from_type] = update[0]
|
|
224
|
+
update_properties[to_ref + to_type] = update[1]
|
|
226
225
|
if self.add_system_properties:
|
|
227
226
|
update_properties[self.update_time_property] = update[3]
|
|
228
227
|
payload.append(update_properties)
|
|
@@ -232,7 +231,6 @@ class RelationshipFileProcessor:
|
|
|
232
231
|
formatted_payload = []
|
|
233
232
|
for a_payload in payload:
|
|
234
233
|
formatted_payload.append(Properties(a_payload).format())
|
|
235
|
-
|
|
236
234
|
# Build a MERGE query using queries
|
|
237
235
|
from_keys = " {" + from_key + ":" + payload_ref_dot + from_ref + "}"
|
|
238
236
|
to_keys = " {" + to_key + ":" + payload_ref_dot + to_ref + "}"
|
{python_eigen_ingenuity-0.4.36b2.dist-info → python_eigen_ingenuity-0.4.37.dist-info}/RECORD
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
eigeningenuity/__init__.py,sha256=wiP9sP_ibX_oufhkGLXiTLze3fF17CUIHVo1hymdO2U,1500
|
|
2
2
|
eigeningenuity/assetmodel.py,sha256=gpimrnPOhrUCRPmi223eeZ9d5jlYP5JkMQQNJElZuX4,16785
|
|
3
|
-
eigeningenuity/auth.py,sha256=
|
|
3
|
+
eigeningenuity/auth.py,sha256=SPD5HXycsG5SBb2yf1pR5vee6gwG_UkWLkzmP02sWlY,6565
|
|
4
4
|
eigeningenuity/elastic.py,sha256=WG4nlsJXNs_-m76jtj46UfgvLgWLvn6d6QW2dk7LBI4,6648
|
|
5
5
|
eigeningenuity/events.py,sha256=wUc1TkT7047gduNuNfzkSO5tK13ErJdeI2K5cPXhNCY,3336
|
|
6
6
|
eigeningenuity/historian.py,sha256=YGAwaSMSdDAB_czQUCE0POxzYkU5ywsIrhl_abGl7rk,36341
|
|
@@ -12,15 +12,14 @@ eigeningenuity/util.py,sha256=P-WvDaIkb7OpEADQYCQJWY92wQimMu9u_GHpDZDyC-g,14872
|
|
|
12
12
|
eigeningenuity/core/__init__.py,sha256=u3wAldyaivF-E2HzMftBNFPWUGNf0ZxGmdMUY6Em6nA,8439
|
|
13
13
|
modelbuilder/__init__.py,sha256=HSsHItu5BbGQiHYTG00QPMNDbC3RkRUaaN50YpksIUA,171
|
|
14
14
|
modelbuilder/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
modelbuilder/src/assetmodelbuilder.py,sha256=
|
|
15
|
+
modelbuilder/src/assetmodelbuilder.py,sha256=On0ndiJQQQ52vv-mo8pO2nsG5yMAk933kuBf4S8WQYg,8080
|
|
16
16
|
modelbuilder/src/assetmodelcsvwriter.py,sha256=GKNi_fw7AlY-UG2XhwFIS34Ff3XiVRss-o5MUzyJSV0,1071
|
|
17
17
|
modelbuilder/src/assetmodelutilities.py,sha256=KwyP8-2EfpRHKmGasPJLV74EGYBjSHgxHBAy8xuvh6k,1743
|
|
18
|
-
modelbuilder/src/configmanager.py,sha256=
|
|
19
|
-
modelbuilder/src/csvcontentsmanager.py,sha256=
|
|
18
|
+
modelbuilder/src/configmanager.py,sha256=o_kDcup2DwCupOMlovcs_QqXt4PzH50QVamDrsWH5Dw,23158
|
|
19
|
+
modelbuilder/src/csvcontentsmanager.py,sha256=c311x0K5rPzDXGDAH7jlE2Ml3oks8-1-iFbdl0a8TuA,6400
|
|
20
20
|
modelbuilder/src/csvwriter.py,sha256=m2XVbyZq3Gq2bb36HqvOFuTuet1fi1nRPURL6yEtfjI,14051
|
|
21
21
|
modelbuilder/src/fileanalyser.py,sha256=LUWrqogjBXsXHV-maoEOmu6FKuu7JmvNZJZMlFhbKQA,3627
|
|
22
22
|
modelbuilder/src/filemanager.py,sha256=h8BHOEWA94jvDw8WCiGbXwhRDm2FvycJgoTyO1gTi88,18834
|
|
23
|
-
modelbuilder/src/fileprocessors.py,sha256=-ZoaqsnlOA4Rh_unF3L-TE6RqCgYHheGd_FQRSa-DRc,35692
|
|
24
23
|
modelbuilder/src/messages.py,sha256=6JnW-ke6nHGUA4hTEBvo_kVlNJTXoV4LWw8mNwMpBCQ,1325
|
|
25
24
|
modelbuilder/src/versionmanager.py,sha256=WKrxY8JkSIquHxivS5eyN5W0izJ5LWLmxSvd9wg_5Is,18289
|
|
26
25
|
modelbuilder/src/connectors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -31,16 +30,16 @@ modelbuilder/src/connectors/httpsconnector.py,sha256=06TrQSEa5bmqXjPPAqz1hXrOEOw
|
|
|
31
30
|
modelbuilder/src/processors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
31
|
modelbuilder/src/processors/cypherfileprocessor.py,sha256=Y77GddRVhQKNhs6V4jfqwE2LhZvINZ1NX0a_lRadlds,2868
|
|
33
32
|
modelbuilder/src/processors/labelmanager.py,sha256=03fD-JXjdeEyHXUeihst5rVWgmd-3-Y8fSMM42OfsT8,6237
|
|
34
|
-
modelbuilder/src/processors/nodefileprocessor.py,sha256=
|
|
35
|
-
modelbuilder/src/processors/propertymanager.py,sha256=
|
|
36
|
-
modelbuilder/src/processors/relationshipfileprocessor.py,sha256=
|
|
33
|
+
modelbuilder/src/processors/nodefileprocessor.py,sha256=c1RYBxUdKZIC-lMPI0o-qp06n0VLPeyyvr7KsXXiJXQ,12667
|
|
34
|
+
modelbuilder/src/processors/propertymanager.py,sha256=nYdjTNKecKcaLLthMJcWhUajapqTMPNxP6e6PrZniL0,4797
|
|
35
|
+
modelbuilder/src/processors/relationshipfileprocessor.py,sha256=cq-oDBWVx_m-5zoVd35uNvbhqax4F5fAS7yUfsFitRU,14943
|
|
37
36
|
modelbuilder/src/processors/relationshipmanager.py,sha256=lDtE_5AdKzL3boq7VD8Gmpai8Uscq79vRxkzYQL8A9A,1105
|
|
38
37
|
modelbuilder/src/queries/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
39
38
|
modelbuilder/src/queries/cypherbuilder.py,sha256=XHChyxnTyJegfVhN949UU0T3t3Lf1CKgN0yCN8Cx8cM,10384
|
|
40
39
|
modelbuilder/src/queries/query.py,sha256=gN69uwsf-0F6_dGx9cxLGuM17960_FV58pyimJ9usxY,2472
|
|
41
40
|
modelbuilder/src/queries/typedefs.py,sha256=8uAnLfE_EyAfrdMZuotfu_YHqORXhWfgPG3Yltvyr5A,6129
|
|
42
|
-
python_eigen_ingenuity-0.4.
|
|
43
|
-
python_eigen_ingenuity-0.4.
|
|
44
|
-
python_eigen_ingenuity-0.4.
|
|
45
|
-
python_eigen_ingenuity-0.4.
|
|
46
|
-
python_eigen_ingenuity-0.4.
|
|
41
|
+
python_eigen_ingenuity-0.4.37.dist-info/METADATA,sha256=g-wAAYVfpqtp1AfDI9FghMhNivZAa0Gg_CG27v_mRao,32119
|
|
42
|
+
python_eigen_ingenuity-0.4.37.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
43
|
+
python_eigen_ingenuity-0.4.37.dist-info/entry_points.txt,sha256=G3LjFQX5xKaN4mqtqCL8uaC-gRbP5T5x9r0gBTJTXXA,70
|
|
44
|
+
python_eigen_ingenuity-0.4.37.dist-info/top_level.txt,sha256=lFiZ43CY_1bmdtRidIXbA6rrY2d92Rs-9tH8pcgI-XU,28
|
|
45
|
+
python_eigen_ingenuity-0.4.37.dist-info/RECORD,,
|
|
@@ -1,691 +0,0 @@
|
|
|
1
|
-
import csv
|
|
2
|
-
|
|
3
|
-
import messages
|
|
4
|
-
from queries.cypherbuilder import QueryBuilder
|
|
5
|
-
from queries.typedefs import Properties
|
|
6
|
-
from csvcontentsmanager import csvContentsManager
|
|
7
|
-
# from dfcontentsmanager import dfContentsManager
|
|
8
|
-
import assetmodelutilities as amu
|
|
9
|
-
from queries.query import Neo4jQuery
|
|
10
|
-
import uuid
|
|
11
|
-
##json import pandas as pdf
|
|
12
|
-
|
|
13
|
-
#max_payload_size = 9500000
|
|
14
|
-
|
|
15
|
-
class FileProcessor():
|
|
16
|
-
|
|
17
|
-
def __init__(self, filename, config, inline_query=False):
|
|
18
|
-
self.filename = filename
|
|
19
|
-
self.inline_query = inline_query
|
|
20
|
-
|
|
21
|
-
self.primary_property = config.get_primary_property()
|
|
22
|
-
self.add_system_properties = not config.get_no_system_properties()
|
|
23
|
-
|
|
24
|
-
self.required_labels = config.get_required_labels()
|
|
25
|
-
self.required_properties = config.get_required_properties_dict()
|
|
26
|
-
self.unrequired_properties = config.get_unrequired_properties_list()
|
|
27
|
-
self.unique_id_property = config.get_unique_id_property()
|
|
28
|
-
self.creation_time_property = config.get_creation_time_property()
|
|
29
|
-
self.update_time_property = config.get_update_time_property()
|
|
30
|
-
self.header_mappings = config.get_header_mappings()
|
|
31
|
-
self.default_data_type = config.get_default_data_type()
|
|
32
|
-
|
|
33
|
-
self.label_alias = config.get_label_alias()
|
|
34
|
-
self.node_alias = config.get_node_alias()
|
|
35
|
-
self.from_node_alias = config.get_from_alias()
|
|
36
|
-
self.from_label_alias = config.get_from_label_alias()
|
|
37
|
-
self.to_node_alias = config.get_to_alias()
|
|
38
|
-
self.to_label_alias = config.get_to_label_alias()
|
|
39
|
-
self.relationship_alias = config.get_relationship_alias()
|
|
40
|
-
self.ignore_nodes = config.get_ignore_nodes()
|
|
41
|
-
|
|
42
|
-
self.separator = config.get_separator()
|
|
43
|
-
self.def_path = config.get_default_path()
|
|
44
|
-
self.validate_only = config.in_validation_mode()
|
|
45
|
-
self.summarise = config.in_summary_mode()
|
|
46
|
-
self.show_query = config.get_show_query()
|
|
47
|
-
|
|
48
|
-
self.output_file = config.get_query_output()
|
|
49
|
-
self.results_file = config.get_results_output()
|
|
50
|
-
|
|
51
|
-
self.allow_blanks = config.get_allow_blanks()
|
|
52
|
-
self.batch_rate = config.get_batch_rate()
|
|
53
|
-
self.last_row = config.get_end_at()
|
|
54
|
-
|
|
55
|
-
# Define special types that are used by the Neo4j importer
|
|
56
|
-
# They are also used in Java asset model builder
|
|
57
|
-
# Could add these to the config file at some point, but they are unlikely to change
|
|
58
|
-
self.node_types = ['ID']
|
|
59
|
-
self.from_types = ['START_ID']
|
|
60
|
-
self.to_types = ['END_ID']
|
|
61
|
-
self.relation_types = ['TYPE']
|
|
62
|
-
self.label_types = ['LABEL', 'ALABEL']
|
|
63
|
-
self.all_types = self.node_types + self.from_types + self.to_types + self.relation_types + self.label_types
|
|
64
|
-
|
|
65
|
-
def get_label_lists(self, labels):
|
|
66
|
-
unique_labels = []
|
|
67
|
-
for label in list(set(labels)):
|
|
68
|
-
for split_label in label.replace(',', ':').split(':'):
|
|
69
|
-
unique_labels.append(split_label)
|
|
70
|
-
label_list = []
|
|
71
|
-
unwanted_label_list = []
|
|
72
|
-
remove_label_list = []
|
|
73
|
-
for label in unique_labels:
|
|
74
|
-
if label:
|
|
75
|
-
if not ('!'+label in self.required_labels or label.startswith('!') or label == '') or (label.startswith('!!')):
|
|
76
|
-
label_list.append(amu.remove_leading_chars(label, '!'))
|
|
77
|
-
elif label.startswith('!'):
|
|
78
|
-
remove_label_list.append(amu.remove_leading_chars(label, '!'))
|
|
79
|
-
else:
|
|
80
|
-
unwanted_label_list.append('!'+amu.remove_leading_chars(label, '!'))
|
|
81
|
-
|
|
82
|
-
return list(set(label_list)), list(set(unwanted_label_list)), list(set(remove_label_list))
|
|
83
|
-
|
|
84
|
-
def merge_labels(self, required_labels, unrequired_labels, remove_labels):
|
|
85
|
-
merged_labels = [i for i in self.required_labels + required_labels if (not ('!' + i in unrequired_labels) and not (i in remove_labels) and not (i.startswith('!')))]
|
|
86
|
-
return merged_labels
|
|
87
|
-
|
|
88
|
-
def get_last_row(self, num_rows):
|
|
89
|
-
if self.last_row < 0:
|
|
90
|
-
last_row = num_rows
|
|
91
|
-
else:
|
|
92
|
-
last_row = min(num_rows, self.last_row)
|
|
93
|
-
return last_row
|
|
94
|
-
|
|
95
|
-
def split_node(self, value, property):
|
|
96
|
-
split_node = value.split('::')
|
|
97
|
-
if len(split_node) == 1:
|
|
98
|
-
if property == '':
|
|
99
|
-
key = self.primary_property
|
|
100
|
-
else:
|
|
101
|
-
key = property
|
|
102
|
-
name = split_node[0]
|
|
103
|
-
else:
|
|
104
|
-
key = split_node[0]
|
|
105
|
-
name = split_node[1]
|
|
106
|
-
return key, name
|
|
107
|
-
|
|
108
|
-
def determine_file_type(self, file_type):
|
|
109
|
-
|
|
110
|
-
file_name = amu.find_file(self.def_path, self.filename)
|
|
111
|
-
if file_name is None:
|
|
112
|
-
return 'fnf', []
|
|
113
|
-
|
|
114
|
-
match file_type:
|
|
115
|
-
case 'csv':
|
|
116
|
-
try:
|
|
117
|
-
with open(file_name, encoding='utf8') as csv_file:
|
|
118
|
-
csv_data = csv.reader(csv_file, delimiter=self.separator)
|
|
119
|
-
self.contents = csvContentsManager(csv_data, self.header_mappings, self.default_data_type)
|
|
120
|
-
except:
|
|
121
|
-
try:
|
|
122
|
-
with open(file_name) as csv_file:
|
|
123
|
-
csv_data = csv.reader(csv_file, delimiter=self.separator)
|
|
124
|
-
self.contents = csvContentsManager(csv_data, self.header_mappings, self.default_data_type)
|
|
125
|
-
except:
|
|
126
|
-
return 'incorrect file format', []
|
|
127
|
-
|
|
128
|
-
## json case 'json':
|
|
129
|
-
## json with open(file_name, encoding='utf8') as json_file:
|
|
130
|
-
## json json_data = pdf.read_json(json_file)
|
|
131
|
-
## json self.contents = dfContentsManager(json_data.fillna('').convert_dtypes(), self.header_mappings, self.default_data_type)
|
|
132
|
-
case _:
|
|
133
|
-
pass
|
|
134
|
-
|
|
135
|
-
# print(self.node_alias, self.node_types)
|
|
136
|
-
num_node_columns = self.contents.get_column_count(self.node_alias, self.node_types)
|
|
137
|
-
# print(self.from_node_alias, self.from_types)
|
|
138
|
-
num_from_columns = self.contents.get_column_count(self.from_node_alias, self.from_types)
|
|
139
|
-
# print(self.to_node_alias, self.to_types)
|
|
140
|
-
num_to_columns = self.contents.get_column_count(self.to_node_alias, self.to_types)
|
|
141
|
-
# print(self.relationship_alias, self.relation_types)
|
|
142
|
-
num_relation_columns = self.contents.get_column_count(self.relationship_alias, self.relation_types)
|
|
143
|
-
# print(num_node_columns, num_from_columns, num_to_columns, num_relation_columns)
|
|
144
|
-
|
|
145
|
-
incomplete_rows = self.contents.get_incomplete_rows()
|
|
146
|
-
if len(incomplete_rows) > 0:
|
|
147
|
-
return 'incomplete row(s)', incomplete_rows
|
|
148
|
-
|
|
149
|
-
# If there is a least one Node (including aliases) column, this could be a Node file
|
|
150
|
-
if num_node_columns > 0:
|
|
151
|
-
could_be_node = True
|
|
152
|
-
if num_node_columns > 1:
|
|
153
|
-
messages.warning_message(f'Multiple node columns found in ', f'{self.filename}')
|
|
154
|
-
else:
|
|
155
|
-
could_be_node = False
|
|
156
|
-
|
|
157
|
-
# Check if there are at least one each of From, To and Relationship (including aliases) columns
|
|
158
|
-
# If so, this could be a Relationship file
|
|
159
|
-
if num_from_columns > 0 and num_to_columns > 0 and num_relation_columns > 0:
|
|
160
|
-
could_be_relations = True
|
|
161
|
-
else:
|
|
162
|
-
could_be_relations = False
|
|
163
|
-
|
|
164
|
-
if could_be_node:
|
|
165
|
-
if could_be_relations:
|
|
166
|
-
if self.ignore_nodes:
|
|
167
|
-
file_type = 'relationships'
|
|
168
|
-
else:
|
|
169
|
-
file_type = 'both'
|
|
170
|
-
else:
|
|
171
|
-
file_type = 'nodes'
|
|
172
|
-
else:
|
|
173
|
-
if could_be_relations:
|
|
174
|
-
file_type = 'relationships'
|
|
175
|
-
else:
|
|
176
|
-
file_type = 'neither'
|
|
177
|
-
|
|
178
|
-
return file_type, []
|
|
179
|
-
|
|
180
|
-
def process_node_file(self, start_from):
|
|
181
|
-
|
|
182
|
-
# For each line in the file, build a cypher query to MERGE a node
|
|
183
|
-
# Each query is added to a list of queries, which are returned to the caller. They are NOT actioned here
|
|
184
|
-
|
|
185
|
-
num_data_rows = self.contents.get_row_count()
|
|
186
|
-
node_columns = self.contents.get_column_numbers_list(self.node_alias, self.node_types)
|
|
187
|
-
label_columns = self.contents.get_column_numbers_list(self.label_alias, self.label_types)
|
|
188
|
-
property_columns = self.contents.get_other_column_numbers_list(self.node_alias + self.label_alias, self.all_types)
|
|
189
|
-
|
|
190
|
-
queries = []
|
|
191
|
-
|
|
192
|
-
num_rows = num_data_rows - start_from + 1
|
|
193
|
-
this_row = start_from-1
|
|
194
|
-
last_row = self.get_last_row(num_data_rows)
|
|
195
|
-
property_ref = 'n'
|
|
196
|
-
property_ref_dot = property_ref + '.'
|
|
197
|
-
|
|
198
|
-
while this_row < last_row:
|
|
199
|
-
wanted_labels, unwanted_labels, remove_labels = self.get_label_lists(self.contents.get_column_values_list(this_row, label_columns))
|
|
200
|
-
labels = [i for i in self.required_labels if (not('!'+i in unwanted_labels) and not(i.startswith('!')))]
|
|
201
|
-
new_labels = [i for i in wanted_labels if i not in labels]
|
|
202
|
-
properties = self.contents.get_property_values_dict(this_row, property_columns, allow_blanks=self.allow_blanks)
|
|
203
|
-
if len(self.required_properties) > 0:
|
|
204
|
-
properties = {**self.required_properties, **properties}
|
|
205
|
-
# Remove any properties we don't want
|
|
206
|
-
for property in self.unrequired_properties:
|
|
207
|
-
try:
|
|
208
|
-
properties.pop(property)
|
|
209
|
-
except:
|
|
210
|
-
pass
|
|
211
|
-
for k in list(properties):
|
|
212
|
-
properties[property_ref_dot + k] = properties.pop(k)
|
|
213
|
-
|
|
214
|
-
for node_name in self.contents.get_column_values_list_with_properties(this_row, node_columns, self.node_types):
|
|
215
|
-
time_now = amu.get_formatted_time_now()
|
|
216
|
-
node_value, node_property = list(node_name.items())[0]
|
|
217
|
-
key, name = self.split_node(node_value, node_property)
|
|
218
|
-
primary_property = {key: name}
|
|
219
|
-
|
|
220
|
-
# Build a simple MERGE query using queries
|
|
221
|
-
query_text = (QueryBuilder()
|
|
222
|
-
.merge()
|
|
223
|
-
.node(labels=labels, ref_name=property_ref, properties=Properties(primary_property))
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
# Add in System properties if required
|
|
227
|
-
if self.add_system_properties:
|
|
228
|
-
new_uuid = str(uuid.uuid4())
|
|
229
|
-
create_time = property_ref_dot + self.creation_time_property + '=datetime("' + time_now + '")'
|
|
230
|
-
id_property = property_ref_dot + self.unique_id_property
|
|
231
|
-
update_id = id_property + '= CASE WHEN ' + id_property + ' IS null THEN "' + new_uuid + '" ELSE ' + id_property + ' END,' +\
|
|
232
|
-
property_ref_dot + self.update_time_property + '=datetime("' + time_now + '")'
|
|
233
|
-
query_text = query_text.on_create().set_literal(create_time).set_literal(update_id)
|
|
234
|
-
|
|
235
|
-
if len(new_labels) > 0:
|
|
236
|
-
query_text = query_text.set_labels(ref_name=property_ref, labels=new_labels)
|
|
237
|
-
if len(remove_labels) > 0:
|
|
238
|
-
query_text = query_text.remove_literal(f'{property_ref}:{":".join(remove_labels)}')
|
|
239
|
-
if len(properties) > 0:
|
|
240
|
-
query_text = query_text.set(properties=properties)
|
|
241
|
-
|
|
242
|
-
query_text = query_text.toStr()
|
|
243
|
-
|
|
244
|
-
query = Neo4jQuery('node', query_text, time_now, labels, new_labels, primary_property, properties)
|
|
245
|
-
|
|
246
|
-
if self.validate_only and not self.summarise:
|
|
247
|
-
print(query.text)
|
|
248
|
-
|
|
249
|
-
queries.append(query)
|
|
250
|
-
|
|
251
|
-
this_row += 1
|
|
252
|
-
messages.message_no_cr(f'Generating queries... {100 * (this_row - start_from + 1) / num_rows:.0f}%{chr(13)}')
|
|
253
|
-
|
|
254
|
-
messages.message('', False)
|
|
255
|
-
return queries
|
|
256
|
-
|
|
257
|
-
def process_node_file_batch(self, start_from):
|
|
258
|
-
|
|
259
|
-
# For each line in the file, build a cypher query to MERGE a node
|
|
260
|
-
# Each query is added to a list of queries, which are returned to the caller. They are NOT actioned here
|
|
261
|
-
|
|
262
|
-
num_data_rows = self.contents.get_row_count()
|
|
263
|
-
node_columns = self.contents.get_column_numbers_list(self.node_alias, self.node_types)
|
|
264
|
-
label_columns = self.contents.get_column_numbers_list(self.label_alias, self.label_types)
|
|
265
|
-
property_columns = self.contents.get_other_column_numbers_list(self.node_alias + self.label_alias, self.all_types)
|
|
266
|
-
|
|
267
|
-
queries = []
|
|
268
|
-
|
|
269
|
-
num_rows = num_data_rows - start_from + 1
|
|
270
|
-
this_row = start_from-1
|
|
271
|
-
last_row = self.get_last_row(num_data_rows)
|
|
272
|
-
dict_size = 0
|
|
273
|
-
property_ref = 'n'
|
|
274
|
-
property_ref_dot = property_ref + '.'
|
|
275
|
-
payload_ref = 'payload'
|
|
276
|
-
payload_ref_dot = payload_ref + '.'
|
|
277
|
-
|
|
278
|
-
time_now = amu.get_formatted_time_now()
|
|
279
|
-
|
|
280
|
-
# For best optimisation, we need to create a batch query for all the update with the same labels
|
|
281
|
-
# So we will create a dictionary of queries based on the labels for each query
|
|
282
|
-
# Since the dictionary key can't be a list, we will create a list (of lists) and use the index in that list as the key
|
|
283
|
-
# When we have worked through all the input and grouped the queries by label combination, we will create the queries
|
|
284
|
-
|
|
285
|
-
list_of_label_combinations = []
|
|
286
|
-
query_dictionary = {}
|
|
287
|
-
labels = [i for i in self.required_labels if (not (i.startswith('!')))]
|
|
288
|
-
id_property = property_ref_dot + self.unique_id_property
|
|
289
|
-
creation_property = property_ref_dot + self.creation_time_property
|
|
290
|
-
|
|
291
|
-
while this_row < last_row:
|
|
292
|
-
wanted_labels, unwanted_labels, remove_labels = self.get_label_lists(self.contents.get_column_values_list(this_row, label_columns))
|
|
293
|
-
label_list = [i for i in labels if (not('!'+i in unwanted_labels))]
|
|
294
|
-
new_labels = [i for i in wanted_labels if i not in label_list]
|
|
295
|
-
|
|
296
|
-
# # Remove any unwanted labels (marked with '!' in the settings file)
|
|
297
|
-
properties = self.contents.get_property_values_dict(this_row, property_columns, allow_blanks=self.allow_blanks)
|
|
298
|
-
|
|
299
|
-
for node_name in self.contents.get_column_values_list_with_properties(this_row, node_columns, self.node_types):
|
|
300
|
-
node_value, node_property = list(node_name.items())[0]
|
|
301
|
-
key, name = self.split_node(node_value, node_property)
|
|
302
|
-
# primary_property = {key: name}
|
|
303
|
-
if len(self.required_properties) > 0:
|
|
304
|
-
properties = {**self.required_properties, **properties}
|
|
305
|
-
# Remove any properties we don't want
|
|
306
|
-
for property in self.unrequired_properties:
|
|
307
|
-
try:
|
|
308
|
-
properties.pop(property)
|
|
309
|
-
except:
|
|
310
|
-
pass
|
|
311
|
-
properties[key] = name
|
|
312
|
-
|
|
313
|
-
query_data = [properties, time_now]
|
|
314
|
-
|
|
315
|
-
# So now we know all about this particular update. Let's put it in the query dictionary
|
|
316
|
-
# We'll group these by unique combinations of labels and primary key type
|
|
317
|
-
dictionary_key = [new_labels, key, label_list, remove_labels]
|
|
318
|
-
try:
|
|
319
|
-
dictionary_index = list_of_label_combinations.index(dictionary_key)
|
|
320
|
-
query_dictionary[dictionary_index].append(query_data)
|
|
321
|
-
except:
|
|
322
|
-
dictionary_index = len(list_of_label_combinations)
|
|
323
|
-
query_dictionary[dictionary_index] = [query_data]
|
|
324
|
-
list_of_label_combinations.append(dictionary_key)
|
|
325
|
-
dict_size += 1
|
|
326
|
-
|
|
327
|
-
this_row += 1
|
|
328
|
-
messages.message_no_cr(f'Analysing file... {100 * (this_row - start_from + 1) / num_rows:.0f}%{chr(13)}')
|
|
329
|
-
|
|
330
|
-
messages.message('', False)
|
|
331
|
-
|
|
332
|
-
# Right, so now we have a dictionary of updates grouped by labels. Let's create the queries
|
|
333
|
-
query_count = 0
|
|
334
|
-
for new_labels, updates in query_dictionary.items():
|
|
335
|
-
num_updates_for_this_label = len(updates)
|
|
336
|
-
num_batches = int((num_updates_for_this_label-1)/self.batch_rate) + 1
|
|
337
|
-
|
|
338
|
-
batch_num = 1
|
|
339
|
-
while batch_num <= num_batches:
|
|
340
|
-
if batch_num == num_batches:
|
|
341
|
-
# Last batch, so
|
|
342
|
-
batch_size = 1 + (num_updates_for_this_label-1) % self.batch_rate
|
|
343
|
-
else:
|
|
344
|
-
batch_size = self.batch_rate
|
|
345
|
-
|
|
346
|
-
this_size = 0
|
|
347
|
-
payload = []
|
|
348
|
-
# payload_len = 0
|
|
349
|
-
# while this_size < batch_size and payload_len < max_payload_size:
|
|
350
|
-
while this_size < batch_size:
|
|
351
|
-
# Combine all the update data...
|
|
352
|
-
update = updates[(batch_num-1)*self.batch_rate + this_size]
|
|
353
|
-
update_properties = update[0] or {}
|
|
354
|
-
if self.add_system_properties:
|
|
355
|
-
update_properties[self.update_time_property] = update[1]
|
|
356
|
-
payload.append(update_properties)
|
|
357
|
-
# payload_len += len(Properties(update_properties).format())
|
|
358
|
-
this_size += 1
|
|
359
|
-
query_count += 1
|
|
360
|
-
|
|
361
|
-
formatted_payload = []
|
|
362
|
-
property_count = 0
|
|
363
|
-
for a_payload in payload:
|
|
364
|
-
formatted_payload.append(Properties(a_payload).format())
|
|
365
|
-
property_count += len(a_payload)
|
|
366
|
-
|
|
367
|
-
# Build a MERGE query using queries
|
|
368
|
-
node_labels = list_of_label_combinations[new_labels][2]
|
|
369
|
-
remove_labels = list_of_label_combinations[new_labels][3]
|
|
370
|
-
if list_of_label_combinations[new_labels][0]:
|
|
371
|
-
node_labels += list_of_label_combinations[new_labels][0]
|
|
372
|
-
query_text = (QueryBuilder()
|
|
373
|
-
.unwind_list_as(formatted_payload, payload_ref)
|
|
374
|
-
.merge()
|
|
375
|
-
.node_batch(labels=list(set(node_labels)), ref_name=property_ref, properties=list_of_label_combinations[new_labels][1]+':'+payload_ref_dot+list_of_label_combinations[new_labels][1])
|
|
376
|
-
.set_literal(property_ref + ' += ' + payload_ref)
|
|
377
|
-
)
|
|
378
|
-
if len(remove_labels) > 0:
|
|
379
|
-
query_text = query_text.remove_literal(f'{property_ref}:{":".join(remove_labels)}')
|
|
380
|
-
if self.add_system_properties:
|
|
381
|
-
query_text = query_text.set_literal(id_property + '= CASE WHEN ' + id_property + ' IS null THEN randomUUID() ELSE ' + id_property + ' END')
|
|
382
|
-
query_text = query_text.set_literal(creation_property + '= CASE WHEN ' + creation_property + ' IS null THEN ' + property_ref_dot + self.update_time_property + ' ELSE ' + creation_property + ' END')
|
|
383
|
-
|
|
384
|
-
query_text = query_text.toStr()
|
|
385
|
-
query = Neo4jQuery('batch node', query_text, time_now, batch_size=this_size, property_count=property_count)
|
|
386
|
-
queries.append(query)
|
|
387
|
-
messages.message_no_cr(f'Generating queries... {100 * query_count / dict_size:.0f}%{chr(13)}')
|
|
388
|
-
|
|
389
|
-
if self.validate_only and not self.summarise:
|
|
390
|
-
print(query.text)
|
|
391
|
-
|
|
392
|
-
batch_num += 1
|
|
393
|
-
|
|
394
|
-
messages.message('', False)
|
|
395
|
-
return queries
|
|
396
|
-
|
|
397
|
-
def process_relationship_file(self, start_from):
|
|
398
|
-
|
|
399
|
-
# For each line in the file, build a cypher query to MERGE a relationship
|
|
400
|
-
# Each query is added to a list of queries, which are returned to the caller. They are NOT actioned here
|
|
401
|
-
|
|
402
|
-
num_data_rows = self.contents.get_row_count()
|
|
403
|
-
from_columns = self.contents.get_column_numbers_list(self.from_node_alias, self.from_types)
|
|
404
|
-
from_label_columns = self.contents.get_column_numbers_list(self.from_label_alias)
|
|
405
|
-
to_columns = self.contents.get_column_numbers_list(self.to_node_alias, self.to_types)
|
|
406
|
-
to_label_columns = self.contents.get_column_numbers_list(self.to_label_alias)
|
|
407
|
-
relation_columns = self.contents.get_column_numbers_list(self.relationship_alias, self.relation_types)
|
|
408
|
-
other_columns = self.from_node_alias + self.from_label_alias + self.to_node_alias + self.to_label_alias + self.relationship_alias
|
|
409
|
-
property_columns = self.contents.get_other_column_numbers_list(other_columns, self.all_types)
|
|
410
|
-
|
|
411
|
-
queries = []
|
|
412
|
-
from_ref = 'from'
|
|
413
|
-
relation_ref = 'rel'
|
|
414
|
-
to_ref = 'to'
|
|
415
|
-
relation_ref_dot = relation_ref + '.'
|
|
416
|
-
|
|
417
|
-
num_rows = num_data_rows - start_from + 1
|
|
418
|
-
this_row = start_from-1
|
|
419
|
-
last_row = self.get_last_row(num_data_rows)
|
|
420
|
-
while this_row < last_row:
|
|
421
|
-
|
|
422
|
-
relationships = self.contents.get_column_values_list(this_row, relation_columns)
|
|
423
|
-
properties = self.contents.get_property_values_dict(this_row, property_columns, relation_ref_dot, self.allow_blanks)
|
|
424
|
-
# If there are multiple From or To nodes, create a relationship query for each combination
|
|
425
|
-
for from_properties in self.contents.get_column_values_list_with_properties(this_row, from_columns, self.from_types):
|
|
426
|
-
from_value, from_property = list(from_properties.items())[0]
|
|
427
|
-
key, name = self.split_node(from_value, from_property)
|
|
428
|
-
from_node = {key: name}
|
|
429
|
-
required_from_labels, unrequired_from_labels, remove_from_labels = self.get_label_lists(self.contents.get_column_values_list(this_row, from_label_columns))
|
|
430
|
-
from_labels = self.merge_labels(required_from_labels, unrequired_from_labels, remove_from_labels)
|
|
431
|
-
for to_properties in self.contents.get_column_values_list_with_properties(this_row, to_columns, self.to_types):
|
|
432
|
-
to_value, to_property = list(to_properties.items())[0]
|
|
433
|
-
key, name = self.split_node(to_value, to_property)
|
|
434
|
-
to_node = {key: name}
|
|
435
|
-
required_to_labels, unrequired_to_labels, remove_to_labels = self.get_label_lists(self.contents.get_column_values_list(this_row, to_label_columns))
|
|
436
|
-
to_labels = self.merge_labels(required_to_labels, unrequired_to_labels, remove_to_labels)
|
|
437
|
-
|
|
438
|
-
# We need to create sets of updates that have the same label combinations, and relationship
|
|
439
|
-
|
|
440
|
-
# Build a MERGE query for the relationship(s)
|
|
441
|
-
for relationship in relationships:
|
|
442
|
-
for relation in relationship.split(':'):
|
|
443
|
-
if relation:
|
|
444
|
-
|
|
445
|
-
time_now = amu.get_formatted_time_now()
|
|
446
|
-
query_text = (QueryBuilder()
|
|
447
|
-
.match()
|
|
448
|
-
.node(labels=from_labels, ref_name=from_ref, properties=Properties(from_node))
|
|
449
|
-
.match()
|
|
450
|
-
.node(labels=to_labels, ref_name=to_ref, properties=Properties(to_node))
|
|
451
|
-
.merge()
|
|
452
|
-
.node(ref_name=from_ref)
|
|
453
|
-
.related_to(label=relation, ref_name=relation_ref)
|
|
454
|
-
.node(ref_name=to_ref)
|
|
455
|
-
)
|
|
456
|
-
|
|
457
|
-
# Add in System properties
|
|
458
|
-
if self.add_system_properties:
|
|
459
|
-
create_time = relation_ref_dot + self.creation_time_property + '=datetime("' + time_now + '")'
|
|
460
|
-
update_time = relation_ref_dot + self.update_time_property + '=datetime("' + time_now + '")'
|
|
461
|
-
query_text = query_text.on_create().set_literal(create_time).set_literal(update_time)
|
|
462
|
-
|
|
463
|
-
if len(properties) > 0:
|
|
464
|
-
query_text = query_text.set(properties=properties)
|
|
465
|
-
query_text = query_text.toStr()
|
|
466
|
-
query = Neo4jQuery('relationship', query_text, time_now)
|
|
467
|
-
|
|
468
|
-
if self.validate_only and not self.summarise:
|
|
469
|
-
print(query.text)
|
|
470
|
-
|
|
471
|
-
queries.append(query)
|
|
472
|
-
|
|
473
|
-
this_row += 1
|
|
474
|
-
messages.message_no_cr(f'Generating queries... {100 * (this_row - start_from + 1) / num_rows:.0f}%{chr(13)}')
|
|
475
|
-
|
|
476
|
-
messages.message('', False)
|
|
477
|
-
return queries
|
|
478
|
-
|
|
479
|
-
def process_relationship_file_batch(self, start_from):
|
|
480
|
-
|
|
481
|
-
# For each line in the file, build a cypher query to MERGE a relationship
|
|
482
|
-
# Each query is added to a list of queries, which are returned to the caller. They are NOT actioned here
|
|
483
|
-
|
|
484
|
-
num_data_rows = self.contents.get_row_count()
|
|
485
|
-
from_columns = self.contents.get_column_numbers_list(self.from_node_alias, self.from_types)
|
|
486
|
-
from_label_columns = self.contents.get_column_numbers_list(self.from_label_alias)
|
|
487
|
-
to_columns = self.contents.get_column_numbers_list(self.to_node_alias, self.to_types)
|
|
488
|
-
to_label_columns = self.contents.get_column_numbers_list(self.to_label_alias)
|
|
489
|
-
relation_columns = self.contents.get_column_numbers_list(self.relationship_alias, self.relation_types)
|
|
490
|
-
other_columns = self.from_node_alias + self.from_label_alias + self.to_node_alias + self.to_label_alias + self.relationship_alias
|
|
491
|
-
property_columns = self.contents.get_other_column_numbers_list(other_columns, self.all_types)
|
|
492
|
-
|
|
493
|
-
queries = []
|
|
494
|
-
from_ref = 'from'
|
|
495
|
-
relation_ref = 'rel'
|
|
496
|
-
to_ref = 'to'
|
|
497
|
-
relation_ref_dot = relation_ref + '.'
|
|
498
|
-
payload_ref = 'payload'
|
|
499
|
-
payload_ref_dot = payload_ref + '.'
|
|
500
|
-
|
|
501
|
-
time_now = amu.get_formatted_time_now()
|
|
502
|
-
|
|
503
|
-
# For best optimisation, we need to create a batch query for all the update with the same labels
|
|
504
|
-
# So we will create a dictionary of queries based on the labels and relationships for each query
|
|
505
|
-
# Since the dictionary key can't be a list, we will create a list (of lists) and use the index in that list as the key
|
|
506
|
-
# When we have worked through all the input and grouped the queries by label and relationship combinations, we will create the queries
|
|
507
|
-
|
|
508
|
-
list_of_combinations = []
|
|
509
|
-
query_dictionary = {}
|
|
510
|
-
dict_size = 0
|
|
511
|
-
|
|
512
|
-
num_rows = num_data_rows - start_from + 1
|
|
513
|
-
this_row = start_from-1
|
|
514
|
-
last_row = self.get_last_row(num_data_rows)
|
|
515
|
-
while this_row < last_row:
|
|
516
|
-
relationships = self.contents.get_column_values_list(this_row, relation_columns)
|
|
517
|
-
properties = self.contents.get_property_values_dict(this_row, property_columns, '', self.allow_blanks)
|
|
518
|
-
# If there are multiple From or To nodes, create a relationship query for each combination
|
|
519
|
-
for from_properties in self.contents.get_column_values_list_with_properties(this_row, from_columns, self.from_types):
|
|
520
|
-
from_value, from_property = list(from_properties.items())[0]
|
|
521
|
-
key, name = self.split_node(from_value, from_property)
|
|
522
|
-
from_node = [key, name]
|
|
523
|
-
required_from_labels, unrequired_from_labels, remove_from_labels = self.get_label_lists(self.contents.get_column_values_list(this_row, from_label_columns))
|
|
524
|
-
from_labels = self.merge_labels(required_from_labels, unrequired_from_labels, remove_from_labels)
|
|
525
|
-
for to_properties in self.contents.get_column_values_list_with_properties(this_row, to_columns, self.to_types):
|
|
526
|
-
to_value, to_property = list(to_properties.items())[0]
|
|
527
|
-
key, name = self.split_node(to_value, to_property)
|
|
528
|
-
to_node = [key, name]
|
|
529
|
-
required_to_labels, unrequired_to_labels, remove_to_labels = self.get_label_lists(self.contents.get_column_values_list(this_row, to_label_columns))
|
|
530
|
-
to_labels = self.merge_labels(required_to_labels, unrequired_to_labels, remove_to_labels)
|
|
531
|
-
|
|
532
|
-
# Build a MERGE query for the relationship(s)
|
|
533
|
-
for relationship in relationships:
|
|
534
|
-
for relation in relationship.split(':'):
|
|
535
|
-
if relation:
|
|
536
|
-
|
|
537
|
-
new_labels = [from_labels, to_labels, relation, from_node[0], to_node[0]]
|
|
538
|
-
query_data = [from_node[1], to_node[1], properties, time_now]
|
|
539
|
-
|
|
540
|
-
# So now we know all about this particular update. Let's put it in the query dictionary
|
|
541
|
-
try:
|
|
542
|
-
dictionary_index = list_of_combinations.index(new_labels)
|
|
543
|
-
query_dictionary[dictionary_index].append(query_data)
|
|
544
|
-
except:
|
|
545
|
-
dictionary_index = len(list_of_combinations)
|
|
546
|
-
query_dictionary[dictionary_index] = [query_data]
|
|
547
|
-
list_of_combinations.append(new_labels)
|
|
548
|
-
dict_size += 1
|
|
549
|
-
|
|
550
|
-
this_row += 1
|
|
551
|
-
messages.message_no_cr(f'Analysing file... {100 * (this_row - start_from + 1) / num_rows:.0f}%{chr(13)}')
|
|
552
|
-
|
|
553
|
-
messages.message('', False)
|
|
554
|
-
|
|
555
|
-
# Right, so now we have a dictionary of updates grouped by labels. Let's create the queries
|
|
556
|
-
query_count = 0
|
|
557
|
-
for from_to_labels, updates in query_dictionary.items():
|
|
558
|
-
num_updates_for_this_label = len(updates)
|
|
559
|
-
num_batches = int((num_updates_for_this_label - 1) / self.batch_rate) + 1
|
|
560
|
-
from_labels = list_of_combinations[from_to_labels][0]
|
|
561
|
-
to_labels = list_of_combinations[from_to_labels][1]
|
|
562
|
-
relationship = list_of_combinations[from_to_labels][2]
|
|
563
|
-
from_key = list_of_combinations[from_to_labels][3]
|
|
564
|
-
to_key = list_of_combinations[from_to_labels][4]
|
|
565
|
-
|
|
566
|
-
batch_num = 1
|
|
567
|
-
while batch_num <= num_batches:
|
|
568
|
-
if batch_num == num_batches:
|
|
569
|
-
# Last batch, so
|
|
570
|
-
batch_size = 1 + (num_updates_for_this_label - 1) % self.batch_rate
|
|
571
|
-
else:
|
|
572
|
-
batch_size = self.batch_rate
|
|
573
|
-
|
|
574
|
-
this_size = 0
|
|
575
|
-
payload = []
|
|
576
|
-
while this_size < batch_size:
|
|
577
|
-
# Combine all the update data...
|
|
578
|
-
update = updates[(batch_num - 1) * self.batch_rate + this_size]
|
|
579
|
-
update_properties = update[2] or {} # In case update_properties[2] is {}
|
|
580
|
-
update_properties[from_ref] = update[0]
|
|
581
|
-
update_properties[to_ref] = update[1]
|
|
582
|
-
if self.add_system_properties:
|
|
583
|
-
update_properties[self.update_time_property] = update[3]
|
|
584
|
-
payload.append(update_properties)
|
|
585
|
-
this_size += 1
|
|
586
|
-
query_count += 1
|
|
587
|
-
|
|
588
|
-
formatted_payload = []
|
|
589
|
-
for a_payload in payload:
|
|
590
|
-
formatted_payload.append(Properties(a_payload).format())
|
|
591
|
-
|
|
592
|
-
# Build a MERGE query using queries
|
|
593
|
-
from_property = " {" + from_key + ":" + payload_ref_dot + from_ref + "}"
|
|
594
|
-
to_property = " {" + to_key + ":" + payload_ref_dot + to_ref + "}"
|
|
595
|
-
create_time = relation_ref_dot + self.creation_time_property + '=datetime("' + time_now + '")'
|
|
596
|
-
update_time = relation_ref_dot + self.update_time_property + '=datetime("' + time_now + '")'
|
|
597
|
-
|
|
598
|
-
query_text = (QueryBuilder()
|
|
599
|
-
.unwind_list_as(formatted_payload, payload_ref)
|
|
600
|
-
.match()
|
|
601
|
-
.node(labels=from_labels, ref_name=from_ref, properties_literal=from_property)
|
|
602
|
-
.match()
|
|
603
|
-
.node(labels=to_labels, ref_name=to_ref, properties_literal=to_property)
|
|
604
|
-
.merge()
|
|
605
|
-
.node(ref_name=from_ref)
|
|
606
|
-
.related_to(label=relationship, ref_name=relation_ref)
|
|
607
|
-
.node(ref_name=to_ref)
|
|
608
|
-
)
|
|
609
|
-
|
|
610
|
-
if self.add_system_properties:
|
|
611
|
-
query_text = query_text.on_create().set_literal(create_time)
|
|
612
|
-
|
|
613
|
-
query_text = query_text.set_literal(relation_ref + ' += ' + payload_ref)
|
|
614
|
-
|
|
615
|
-
if self.add_system_properties:
|
|
616
|
-
query_text = query_text.set_literal(update_time)
|
|
617
|
-
|
|
618
|
-
query_text = query_text.remove_literal(relation_ref_dot + from_ref + ', ' + relation_ref_dot + to_ref)
|
|
619
|
-
query_text = query_text.toStr()
|
|
620
|
-
|
|
621
|
-
query = Neo4jQuery('batch relationship', query_text, time_now, batch_size=this_size)
|
|
622
|
-
|
|
623
|
-
if self.validate_only and not self.summarise:
|
|
624
|
-
print(query.text)
|
|
625
|
-
|
|
626
|
-
queries.append(query)
|
|
627
|
-
messages.message_no_cr(f'Generating queries... {100 * query_count / dict_size:.0f}%{chr(13)}')
|
|
628
|
-
|
|
629
|
-
batch_num += 1
|
|
630
|
-
|
|
631
|
-
messages.message('', False)
|
|
632
|
-
return queries
|
|
633
|
-
|
|
634
|
-
def process_cypher_file(self, start_from):
|
|
635
|
-
|
|
636
|
-
queries = []
|
|
637
|
-
try:
|
|
638
|
-
cypher_file_name = amu.find_file(self.def_path, self.filename)
|
|
639
|
-
cypher_file = open(cypher_file_name, 'r', encoding='UTF8')
|
|
640
|
-
cypher_list = list(cypher_file)
|
|
641
|
-
file_queries = 0
|
|
642
|
-
next_query = ''
|
|
643
|
-
cypher_file_size = len(cypher_list)
|
|
644
|
-
entry_count = 0
|
|
645
|
-
while entry_count < cypher_file_size:
|
|
646
|
-
this_entry = cypher_list[entry_count].strip()
|
|
647
|
-
if not this_entry.startswith('#') and not this_entry == '\n':
|
|
648
|
-
next_query += this_entry + '\n'
|
|
649
|
-
if not this_entry.endswith(',') and not this_entry.endswith('\\'):
|
|
650
|
-
while next_query.endswith('\n'):
|
|
651
|
-
next_query = next_query[0:-1]
|
|
652
|
-
query = Neo4jQuery('cypher', next_query.replace('\\', '').strip())
|
|
653
|
-
next_query = ''
|
|
654
|
-
if self.validate_only and not self.summarise:
|
|
655
|
-
print(query.text)
|
|
656
|
-
queries.append(query)
|
|
657
|
-
file_queries += 1
|
|
658
|
-
entry_count += 1
|
|
659
|
-
|
|
660
|
-
# Process any leftover query at the end of the file
|
|
661
|
-
# This shouldn't normally happen, but will if the last entry ends with a comma or backslash
|
|
662
|
-
# Any trailing backslash is removed, so the query may be OK but will be missing any continuation clause(s)
|
|
663
|
-
# But a trailing comma will be left - result is a query that will generate an error if executed!
|
|
664
|
-
# This is done intentionally as the query in the input file is incomplete
|
|
665
|
-
if next_query != '':
|
|
666
|
-
query = Neo4jQuery('cypher', next_query[0:-1].replace('\\', '').strip())
|
|
667
|
-
if self.validate_only and not self.summarise:
|
|
668
|
-
print(query.text)
|
|
669
|
-
queries.append(query)
|
|
670
|
-
file_queries += 1
|
|
671
|
-
|
|
672
|
-
cypher_file.close()
|
|
673
|
-
except:
|
|
674
|
-
print(f'{self.filename} not found')
|
|
675
|
-
|
|
676
|
-
return queries
|
|
677
|
-
|
|
678
|
-
def process_query_list(self, start_from):
|
|
679
|
-
|
|
680
|
-
queries = []
|
|
681
|
-
query = Neo4jQuery('query', self.filename)
|
|
682
|
-
if self.validate_only and not self.summarise:
|
|
683
|
-
print(query.text)
|
|
684
|
-
queries.append(query)
|
|
685
|
-
return queries
|
|
686
|
-
|
|
687
|
-
def get_filename(self):
|
|
688
|
-
return self.filename
|
|
689
|
-
|
|
690
|
-
def is_inline_query(self):
|
|
691
|
-
return self.inline_query
|
|
File without changes
|
|
File without changes
|
{python_eigen_ingenuity-0.4.36b2.dist-info → python_eigen_ingenuity-0.4.37.dist-info}/top_level.txt
RENAMED
|
File without changes
|