Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void insertEntitiesInGDM(Map<String, Map<String, Long>> frequencyOfTopFrequentItems,
- String fileName, long rowsCount) {
- // NON FARE LA LISTA MA UNA MAPPA
- //List<Tuple2<String, Document>> docList = new LinkedList<Tuple2<String, Document>>();
- Map<String, List<Document>> docMap = new HashMap<>();
- for (Entry<String, Map<String, Long>> entry : frequencyOfTopFrequentItems.entrySet()) {
- String columnName = entry.getKey();
- String datasetColumnKey = fileName.replace(".",",") + "|%#-#%|" + columnName;
- Map<String, Long> topFrequentMap = entry.getValue();
- // FALLA QUI
- List<Document> docList = new LinkedList<>();
- for (Entry<String, Long> topFrequentEntry : topFrequentMap.entrySet()) {
- Integer topFrequentCount = topFrequentMap.entrySet().size();
- String entityName = topFrequentEntry.getKey();
- Long entityOccurrencies = topFrequentEntry.getValue();
- Document datasetAndColumnDocument = new Document("datasetAndColumn", datasetColumnKey);
- Document details = new Document("occurrencies", entityOccurrencies)
- .append("topFrequentCount", topFrequentCount);
- // Qui inizializzi la lista dentro la mappa
- docMap.putIfAbsent(entityName, new LinkedList<>());
- // Qui ottiene la lista associata all'entityName e ci aggiungi il documento
- docMap.get(entityName).add(details);
- }
- }
- /* ora ti giri tutta la mappa e per ogni chiave fai un insertMany */
- for (Entry<String, List<Document> entry : map.entrySet()) {
- String entityName = entry.getKey();
- List<Document> listDocs = entry.getValue();
- GDMENTITYDATABASE.getCollection(entityName).insertMany(listDocs);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement