Skip to content

Commit a54d7db

Browse files
Standardize FIELD_TYPES variable, whitespace cleanup (#13)
Always check the same offset in nested FIELD_TYPES check, fix linter errors on whitespace.
1 parent f4e6e56 commit a54d7db

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

bulk_insert.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ def pack_props(self, line):
160160
props = []
161161
for num, field in enumerate(line[self.prop_offset:]):
162162
field_type_idx = self.prop_offset+num
163-
try :
164-
FIELD_TYPES[self.entity_str][num]
165-
except :
163+
try:
164+
FIELD_TYPES[self.entity_str][field_type_idx]
165+
except:
166166
props.append(prop_to_binary(field, None))
167-
else :
167+
else:
168168
props.append(prop_to_binary(field, FIELD_TYPES[self.entity_str][field_type_idx]))
169169
return b''.join(p for p in props)
170170

@@ -204,7 +204,7 @@ def process_entities(self, expected_col_count):
204204
if NODE_DICT is not None:
205205
if row[0] in NODE_DICT:
206206
sys.stderr.write("Node identifier '%s' was used multiple times - second occurrence at %s:%d\n"
207-
% (row[0], self.infile.name, self.reader.line_num))
207+
% (row[0], self.infile.name, self.reader.line_num))
208208
if CONFIGS.skip_invalid_nodes is False:
209209
exit(1)
210210
NODE_DICT[row[0]] = TOP_NODE_ID
@@ -295,7 +295,6 @@ def prop_to_binary(prop_str, type):
295295
return struct.pack(format_str, Type.NULL)
296296

297297
# If field can be cast to a float, allow it
298-
299298
if type == None or type == Type.NUMERIC:
300299
try:
301300
numeric_prop = float(prop_str)
@@ -316,7 +315,7 @@ def prop_to_binary(prop_str, type):
316315
# Encoding len+1 adds a null terminator to the string
317316
format_str += "%ds" % (len(encoded_str) + 1)
318317
return struct.pack(format_str, Type.STRING, encoded_str)
319-
318+
320319
## if it hasn't returned by this point, it is trying to set it to a type that it can't adopt
321320
raise Exception("unable to parse [" + prop_str + "] with type ["+repr(type)+"]")
322321

@@ -372,7 +371,7 @@ def bulk_insert(graph, host, port, password, nodes, relations, separator, max_to
372371
if field_types != None:
373372
try :
374373
FIELD_TYPES = json.loads(field_types)
375-
except:
374+
except:
376375
raise Exception("Problem parsing field-types. Use the format {<label>:[<col1 type>, <col2 type> ...]} where type can be 0(null),1(bool),2(numeric),3(string) ")
377376

378377
QUOTING=int(quote)

0 commit comments

Comments
 (0)