2020-06-15 11:12:14 +02:00
|
|
|
|
2020-06-09 15:37:46 +02:00
|
|
|
package eu.dnetlib.dhp.oa.graph.dump;
|
|
|
|
|
2020-07-20 17:54:28 +02:00
|
|
|
import eu.dnetlib.dhp.utils.ISLookupClientFactory;
|
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
2020-06-09 15:39:03 +02:00
|
|
|
import org.apache.spark.api.java.function.MapFunction;
|
|
|
|
import org.apache.spark.sql.Dataset;
|
|
|
|
import org.apache.spark.sql.Encoders;
|
|
|
|
import org.apache.spark.sql.SparkSession;
|
|
|
|
|
2020-06-15 11:12:14 +02:00
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.common.HdfsSupport;
|
|
|
|
|
2020-06-09 15:37:46 +02:00
|
|
|
public class Utils {
|
2020-06-15 11:12:14 +02:00
|
|
|
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
|
|
|
|
|
|
|
public static void removeOutputDir(SparkSession spark, String path) {
|
|
|
|
HdfsSupport.remove(path, spark.sparkContext().hadoopConfiguration());
|
|
|
|
}
|
2020-06-09 15:39:03 +02:00
|
|
|
|
2020-06-15 11:12:14 +02:00
|
|
|
public static <R> Dataset<R> readPath(
|
|
|
|
SparkSession spark, String inputPath, Class<R> clazz) {
|
|
|
|
return spark
|
|
|
|
.read()
|
|
|
|
.textFile(inputPath)
|
|
|
|
.map((MapFunction<String, R>) value -> OBJECT_MAPPER.readValue(value, clazz), Encoders.bean(clazz));
|
|
|
|
}
|
2020-07-20 17:54:28 +02:00
|
|
|
|
|
|
|
public static ISLookUpService getIsLookUpService(String isLookUpUrl) {
|
|
|
|
return ISLookupClientFactory.getLookUpService(isLookUpUrl);
|
|
|
|
}
|
2020-06-09 15:37:46 +02:00
|
|
|
}
|