Revision 2030
Added by Aaron Marcuse-Kubitza over 12 years ago
map | ||
---|---|---|
183 | 183 |
in_is_xml = in_is_xpaths and not in_is_db |
184 | 184 |
out_is_xml_ref[0] = out_is_xpaths and not out_is_db |
185 | 185 |
|
186 |
# Prevent collisions if multiple inputs mapping to same output |
|
187 |
outputs_idxs = dict() |
|
188 |
for i, mapping in enumerate(mappings): |
|
189 |
in_, out = mapping |
|
190 |
default = util.NamedTuple(count=1, first=i) |
|
191 |
idxs = outputs_idxs.setdefault(out, default) |
|
192 |
if idxs is not default: # key existed, so there was a collision |
|
193 |
if idxs.count == 1: # first key does not yet have /_alt/# |
|
194 |
mappings[idxs.first][1] += '/_alt/0' |
|
195 |
mappings[i][1] += '/_alt/'+str(idxs.count) |
|
196 |
idxs.count += 1 |
|
197 |
|
|
198 | 186 |
def process_rows(process_row, rows, rows_start=0): |
199 | 187 |
'''Processes input rows |
200 | 188 |
@param process_row(in_row, i) |
... | ... | |
219 | 207 |
'''Maps input rows |
220 | 208 |
@param get_value(in_, row):str |
221 | 209 |
''' |
210 |
# Prevent collisions if multiple inputs mapping to same output |
|
211 |
outputs_idxs = dict() |
|
212 |
for i, mapping in enumerate(mappings): |
|
213 |
in_, out = mapping |
|
214 |
default = util.NamedTuple(count=1, first=i) |
|
215 |
idxs = outputs_idxs.setdefault(out, default) |
|
216 |
if idxs is not default: # key existed, so there was a collision |
|
217 |
if idxs.count == 1: # first key does not yet have /_alt/# |
|
218 |
mappings[idxs.first][1] += '/_alt/0' |
|
219 |
mappings[i][1] += '/_alt/'+str(idxs.count) |
|
220 |
idxs.count += 1 |
|
221 |
|
|
222 | 222 |
id_node = None |
223 | 223 |
if out_is_db: |
224 | 224 |
for i, mapping in enumerate(mappings): |
Also available in: Unified diff
bin/map: Moved collision-prevention code to map_rows() so it would only run if there were mappings, and so that it would run after any mappings preprocessing by map_table() that creates more collisions