1
0
Fork 0

first phase of data preparation. For each result type (parallel) it produces the possible updates

This commit is contained in:
Miriam Baglioni 2020-04-16 15:58:42 +02:00
parent 243013cea3
commit 548ba915ac
1 changed files with 37 additions and 6 deletions

View File

@ -10,19 +10,19 @@ import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext; import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.Dataset; import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Encoders; import org.apache.spark.sql.Encoders;
import org.apache.spark.sql.SaveMode;
import org.apache.spark.sql.SparkSession; import org.apache.spark.sql.SparkSession;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional;
import static eu.dnetlib.dhp.PropagationConstant.*; import static eu.dnetlib.dhp.PropagationConstant.*;
import static eu.dnetlib.dhp.common.SparkSessionSupport.runWithSparkHiveSession; import static eu.dnetlib.dhp.common.SparkSessionSupport.runWithSparkHiveSession;
public class PrepareResultOrcidAssociation { public class PrepareResultOrcidAssociationStep1 {
private static final Logger log = LoggerFactory.getLogger(PrepareResultOrcidAssociation.class); private static final Logger log = LoggerFactory.getLogger(PrepareResultOrcidAssociationStep1.class);
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@ -64,13 +64,14 @@ public class PrepareResultOrcidAssociation {
if (isTest(parser)) { if (isTest(parser)) {
removeOutputDir(spark, outputPath); removeOutputDir(spark, outputPath);
} }
prepareInfo(spark, inputPath, outputPath, resultClazz, resultType); prepareInfo(spark, inputPath, outputPath, resultClazz, resultType, allowedsemrel);
}); });
} }
private static <R extends Result> void prepareInfo(SparkSession spark, String inputPath, private static <R extends Result> void prepareInfo(SparkSession spark, String inputPath,
String outputPath, Class<R> resultClazz, String outputPath, Class<R> resultClazz,
String resultType) { String resultType,
List<String> allowedsemrel) {
//read the relation table and the table related to the result it is using //read the relation table and the table related to the result it is using
final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext()); final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
@ -81,8 +82,38 @@ public class PrepareResultOrcidAssociation {
log.info("Reading Graph table from: {}", inputPath + "/" + resultType); log.info("Reading Graph table from: {}", inputPath + "/" + resultType);
Dataset<R> result = readPathEntity(spark, inputPath + "/" + resultType, resultClazz); Dataset<R> result = readPathEntity(spark, inputPath + "/" + resultType, resultClazz);
result.createOrReplaceTempView("result");
getPossibleResultOrcidAssociation(spark, allowedsemrel, outputPath);
} }
private static void getPossibleResultOrcidAssociation(SparkSession spark, List<String> allowedsemrel, String outputPath){
String query = " select target resultId, author authorList" +
" from (select id, collect_set(named_struct('name', name, 'surname', surname, 'fullname', fullname, 'orcid', orcid)) author " +
" from ( " +
" select id, MyT.fullname, MyT.name, MyT.surname, MyP.value orcid " +
" from result " +
" lateral view explode (author) a as MyT " +
" lateral view explode (MyT.pid) p as MyP " +
" where MyP.qualifier.classid = 'ORCID') tmp " +
" group by id) r_t " +
" join (" +
" select source, target " +
" from relation " +
" where datainfo.deletedbyinference = false " +
getConstraintList(" relclass = '" ,allowedsemrel) + ") rel_rel " +
" on source = id";
spark.sql(query)
.as(Encoders.bean(ResultOrcidList.class))
.toJSON()
.write()
.mode(SaveMode.Append)
.option("compression","gzip")
.text(outputPath)
;
}
} }