From 8a1b42ff21c055135b62d4c07c56e9a201ab5e55 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Tue, 7 Jul 2020 18:21:35 +0200 Subject: [PATCH] added check to verify that dump contains at least one product --- .../oa/graph/dump/SparkSplitForCommunity.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/SparkSplitForCommunity.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/SparkSplitForCommunity.java index eec170955..8efeacdee 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/SparkSplitForCommunity.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/SparkSplitForCommunity.java @@ -98,13 +98,17 @@ public class SparkSplitForCommunity implements Serializable { } private static void printResult(String c, Dataset result, String outputPath) { - result - .filter(r -> containsCommunity(r, c)) - .repartition(1) - .write() - .option("compression", "gzip") - .mode(SaveMode.Append) - .json(outputPath + "/" + c); + Dataset community_products = result + .filter(r -> containsCommunity(r, c)); + + if(community_products.count() > 0){ + community_products.repartition(1) + .write() + .option("compression", "gzip") + .mode(SaveMode.Overwrite) + .json(outputPath + "/" + c); + } + } private static boolean containsCommunity(Result r, String c) {