Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. Dict_Data   =   [{'id' : 'id_5637', 'feature1' : 1, 'feature2' : 2, 'feature3' : 3, 'feature4' : 4, 'feature5' : 5},
  2.                  {'id' : 'id_1246', 'feature1' : 3, 'feature2' : 4, 'feature3' : 5, 'feature4' : 6, 'feature5' : 7},
  3.                  {'id' : 'id_3357', 'feature1' : 1, 'feature2' : 4, 'feature3' : 6, 'feature4' : 2, 'feature5' : 4}]
  4.  
  5. map_Dict_Data = []
  6. for i in range(len(Dict_Data)):
  7.     map_Dict_Data.append(run_map(Dict_Data[i]))#считаем, что мап принимает на вход дикт,
  8.     #в котором ключи это имя признаков (названия колонок в таблице)
  9.     #возвращает такой же жикт
  10. key = 'id'
  11. run_sort(key, map_Dict_Data) # в сорт передаем имя колонки, по которой хотим посортировать
  12.  
  13. key_old = map_Dict_Data[0][key]
  14. reducer_Dict_Data = []
  15. Res_Dict_Data = []
  16.  
  17. for i in range(num_worker):
  18.     Dict_worker_data[i] = []
  19.  
  20. for i in range(len(map_Dict_Data)):
  21.     Dict_worker_data[partitioner(map_Dict_Data[i][key])].append(map_Dict_Data[i])
  22.  
  23. for j in range(num_worker):# идем по всем партициям
  24.     reducer_Data = []
  25.     for i in range(len(Dict_worker_data[j])):  # идем по всем данным, которые партишонер отнес к данной партиции
  26.         key_new = Dict_worker_data[j][i][key]
  27.         if key_new == key_old:
  28.             reducer_Dict_Data.appernd(Dict_worker_data[j][i])
  29.         else:
  30.             Res_Dict_Data.append(run_reducer(reducer_Dict_Data))
  31.             key_old = key_new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement