Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. public static void insertEntitiesInGDM(Map<String, Map<String, Long>> frequencyOfTopFrequentItems,
  2.         String fileName, long rowsCount) {
  3.  
  4.     // NON FARE LA LISTA MA UNA MAPPA
  5.     //List<Tuple2<String, Document>> docList = new LinkedList<Tuple2<String, Document>>();
  6.     Map<String, List<Document>> docMap = new HashMap<>();
  7.  
  8.     for (Entry<String, Map<String, Long>> entry : frequencyOfTopFrequentItems.entrySet()) {
  9.         String columnName = entry.getKey();
  10.         String datasetColumnKey = fileName.replace(".",",") + "|%#-#%|" + columnName;
  11.         Map<String, Long> topFrequentMap = entry.getValue();
  12.        
  13.         // FALLA QUI
  14.         List<Document> docList = new LinkedList<>();
  15.  
  16.         for (Entry<String, Long> topFrequentEntry : topFrequentMap.entrySet()) {
  17.             Integer topFrequentCount = topFrequentMap.entrySet().size();
  18.             String entityName = topFrequentEntry.getKey();
  19.             Long entityOccurrencies = topFrequentEntry.getValue();
  20.             Document datasetAndColumnDocument = new Document("datasetAndColumn", datasetColumnKey);
  21.             Document details = new Document("occurrencies", entityOccurrencies)
  22.                                         .append("topFrequentCount", topFrequentCount);
  23.  
  24.             // Qui inizializzi la lista dentro la mappa
  25.             docMap.putIfAbsent(entityName, new LinkedList<>());
  26.  
  27.             // Qui ottiene la lista associata all'entityName e ci aggiungi il documento
  28.             docMap.get(entityName).add(details);
  29.  
  30.         }
  31.  
  32.  
  33.  
  34.     }
  35.  
  36.     /* ora ti giri tutta la mappa e per ogni chiave fai un insertMany */
  37.     for (Entry<String, List<Document> entry : map.entrySet()) {
  38.         String entityName = entry.getKey();
  39.         List<Document> listDocs = entry.getValue();
  40.         GDMENTITYDATABASE.getCollection(entityName).insertMany(listDocs);
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement