forked from D-Net/dnet-hadoop
Fixed problem on duplicated identifier
This commit is contained in:
parent
264723ffd8
commit
ec3e238de6
|
@ -14,7 +14,7 @@ import scala.collection.JavaConverters._
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
import scala.util.matching.Regex
|
import scala.util.matching.Regex
|
||||||
|
|
||||||
case class CrossrefDT(doi: String, json:String) {}
|
case class CrossrefDT(doi: String, json:String, timestamp: Long) {}
|
||||||
|
|
||||||
case class mappingAffiliation(name: String) {}
|
case class mappingAffiliation(name: String) {}
|
||||||
|
|
||||||
|
|
|
@ -29,69 +29,90 @@ object SparkMapDumpIntoOAF {
|
||||||
.appName(SparkMapDumpIntoOAF.getClass.getSimpleName)
|
.appName(SparkMapDumpIntoOAF.getClass.getSimpleName)
|
||||||
.master(parser.get("master")).getOrCreate()
|
.master(parser.get("master")).getOrCreate()
|
||||||
|
|
||||||
|
implicit val oafEncoder: Encoder[Oaf] = Encoders.kryo[Oaf]
|
||||||
implicit val mapEncoderPubs: Encoder[Publication] = Encoders.kryo[Publication]
|
implicit val mapEncoderPubs: Encoder[Publication] = Encoders.kryo[Publication]
|
||||||
implicit val mapEncoderRelatons: Encoder[Relation] = Encoders.kryo[Relation]
|
implicit val mapEncoderRelatons: Encoder[Relation] = Encoders.kryo[Relation]
|
||||||
implicit val mapEncoderDatasets: Encoder[oaf.Dataset] = Encoders.kryo[OafDataset]
|
implicit val mapEncoderDatasets: Encoder[oaf.Dataset] = Encoders.kryo[OafDataset]
|
||||||
|
|
||||||
val sc = spark.sparkContext
|
val sc = spark.sparkContext
|
||||||
val targetPath = parser.get("targetPath")
|
val targetPath = parser.get("targetPath")
|
||||||
|
import spark.implicits._
|
||||||
|
|
||||||
|
|
||||||
sc.sequenceFile(parser.get("sourcePath"), classOf[IntWritable], classOf[Text])
|
spark.read.load(parser.get("sourcePath")).as[CrossrefDT]
|
||||||
.map(k => k._2.toString).map(CrossrefImporter.decompressBlob)
|
.flatMap(k => Crossref2Oaf.convert(k.json))
|
||||||
.flatMap(k => Crossref2Oaf.convert(k)).saveAsObjectFile(s"${targetPath}/mixObject")
|
.filter(o => o != null)
|
||||||
|
.write.mode(SaveMode.Overwrite).save(s"$targetPath/mixObject")
|
||||||
val inputRDD = sc.objectFile[Oaf](s"${targetPath}/mixObject").filter(p=> p!= null)
|
|
||||||
|
|
||||||
val distinctPubs:RDD[Publication] = inputRDD.filter(k => k != null && k.isInstanceOf[Publication])
|
|
||||||
.map(k => k.asInstanceOf[Publication]).map { p: Publication => Tuple2(p.getId, p) }.reduceByKey { case (p1: Publication, p2: Publication) =>
|
|
||||||
var r = if (p1 == null) p2 else p1
|
|
||||||
if (p1 != null && p2 != null) {
|
|
||||||
if (p1.getLastupdatetimestamp != null && p2.getLastupdatetimestamp != null) {
|
|
||||||
if (p1.getLastupdatetimestamp < p2.getLastupdatetimestamp)
|
|
||||||
r = p2
|
|
||||||
else
|
|
||||||
r = p1
|
|
||||||
} else {
|
|
||||||
r = if (p1.getLastupdatetimestamp == null) p2 else p1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
r
|
|
||||||
}.map(_._2)
|
|
||||||
|
|
||||||
val pubs:Dataset[Publication] = spark.createDataset(distinctPubs)
|
|
||||||
pubs.write.mode(SaveMode.Overwrite).save(s"${targetPath}/publication")
|
|
||||||
|
|
||||||
|
|
||||||
val distincDatasets:RDD[OafDataset] = inputRDD.filter(k => k != null && k.isInstanceOf[OafDataset])
|
val ds:Dataset[Oaf] = spark.read.load(s"$targetPath/mixObject").as[Oaf]
|
||||||
.map(k => k.asInstanceOf[OafDataset]).map(p => Tuple2(p.getId, p)).reduceByKey { case (p1: OafDataset, p2: OafDataset) =>
|
|
||||||
var r = if (p1 == null) p2 else p1
|
|
||||||
if (p1 != null && p2 != null) {
|
|
||||||
if (p1.getLastupdatetimestamp != null && p2.getLastupdatetimestamp != null) {
|
|
||||||
if (p1.getLastupdatetimestamp < p2.getLastupdatetimestamp)
|
|
||||||
r = p2
|
|
||||||
else
|
|
||||||
r = p1
|
|
||||||
} else {
|
|
||||||
r = if (p1.getLastupdatetimestamp == null) p2 else p1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
r
|
|
||||||
}.map(_._2)
|
|
||||||
|
|
||||||
spark.createDataset(distincDatasets).write.mode(SaveMode.Overwrite).save(s"${targetPath}/dataset")
|
ds.filter(o => o.isInstanceOf[Publication]).map(o => o.asInstanceOf[Publication]).write.save(s"$targetPath/publication")
|
||||||
|
|
||||||
|
ds.filter(o => o.isInstanceOf[Relation]).map(o => o.asInstanceOf[Relation]).write.save(s"$targetPath/relation")
|
||||||
|
|
||||||
|
ds.filter(o => o.isInstanceOf[OafDataset]).map(o => o.asInstanceOf[OafDataset]).write.save(s"$targetPath/dataset")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val distinctRels =inputRDD.filter(k => k != null && k.isInstanceOf[Relation])
|
//
|
||||||
.map(k => k.asInstanceOf[Relation]).map(r=> (s"${r.getSource}::${r.getTarget}",r))
|
//
|
||||||
.reduceByKey { case (p1: Relation, p2: Relation) =>
|
//
|
||||||
if (p1 == null) p2 else p1
|
// sc.sequenceFile(parser.get("sourcePath"), classOf[IntWritable], classOf[Text])
|
||||||
}.map(_._2)
|
// .map(k => k._2.toString).map(CrossrefImporter.decompressBlob)
|
||||||
|
// .flatMap(k => Crossref2Oaf.convert(k)).saveAsObjectFile(s"${targetPath}/mixObject")
|
||||||
val rels: Dataset[Relation] = spark.createDataset(distinctRels)
|
//
|
||||||
|
// val inputRDD = sc.objectFile[Oaf](s"${targetPath}/mixObject").filter(p=> p!= null)
|
||||||
rels.write.mode(SaveMode.Overwrite).save(s"${targetPath}/relations")
|
//
|
||||||
|
// val distinctPubs:RDD[Publication] = inputRDD.filter(k => k != null && k.isInstanceOf[Publication])
|
||||||
|
// .map(k => k.asInstanceOf[Publication]).map { p: Publication => Tuple2(p.getId, p) }.reduceByKey { case (p1: Publication, p2: Publication) =>
|
||||||
|
// var r = if (p1 == null) p2 else p1
|
||||||
|
// if (p1 != null && p2 != null) {
|
||||||
|
// if (p1.getLastupdatetimestamp != null && p2.getLastupdatetimestamp != null) {
|
||||||
|
// if (p1.getLastupdatetimestamp < p2.getLastupdatetimestamp)
|
||||||
|
// r = p2
|
||||||
|
// else
|
||||||
|
// r = p1
|
||||||
|
// } else {
|
||||||
|
// r = if (p1.getLastupdatetimestamp == null) p2 else p1
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// r
|
||||||
|
// }.map(_._2)
|
||||||
|
//
|
||||||
|
// val pubs:Dataset[Publication] = spark.createDataset(distinctPubs)
|
||||||
|
// pubs.write.mode(SaveMode.Overwrite).save(s"${targetPath}/publication")
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// val distincDatasets:RDD[OafDataset] = inputRDD.filter(k => k != null && k.isInstanceOf[OafDataset])
|
||||||
|
// .map(k => k.asInstanceOf[OafDataset]).map(p => Tuple2(p.getId, p)).reduceByKey { case (p1: OafDataset, p2: OafDataset) =>
|
||||||
|
// var r = if (p1 == null) p2 else p1
|
||||||
|
// if (p1 != null && p2 != null) {
|
||||||
|
// if (p1.getLastupdatetimestamp != null && p2.getLastupdatetimestamp != null) {
|
||||||
|
// if (p1.getLastupdatetimestamp < p2.getLastupdatetimestamp)
|
||||||
|
// r = p2
|
||||||
|
// else
|
||||||
|
// r = p1
|
||||||
|
// } else {
|
||||||
|
// r = if (p1.getLastupdatetimestamp == null) p2 else p1
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// r
|
||||||
|
// }.map(_._2)
|
||||||
|
//
|
||||||
|
// spark.createDataset(distincDatasets).write.mode(SaveMode.Overwrite).save(s"${targetPath}/dataset")
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// val distinctRels =inputRDD.filter(k => k != null && k.isInstanceOf[Relation])
|
||||||
|
// .map(k => k.asInstanceOf[Relation]).map(r=> (s"${r.getSource}::${r.getTarget}",r))
|
||||||
|
// .reduceByKey { case (p1: Relation, p2: Relation) =>
|
||||||
|
// if (p1 == null) p2 else p1
|
||||||
|
// }.map(_._2)
|
||||||
|
//
|
||||||
|
// val rels: Dataset[Relation] = spark.createDataset(distinctRels)
|
||||||
|
//
|
||||||
|
// rels.write.mode(SaveMode.Overwrite).save(s"${targetPath}/relations")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
<name>sparkExecutorCores</name>
|
<name>sparkExecutorCores</name>
|
||||||
<description>number of cores used by single executor</description>
|
<description>number of cores used by single executor</description>
|
||||||
</property>
|
</property>
|
||||||
<property>
|
<!-- <property>-->
|
||||||
<name>timestamp</name>
|
<!-- <name>timestamp</name>-->
|
||||||
<description>Timestamp for incremental Harvesting</description>
|
<!-- <description>Timestamp for incremental Harvesting</description>-->
|
||||||
</property>
|
<!-- </property>-->
|
||||||
|
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
|
@ -30,29 +30,29 @@
|
||||||
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
|
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
|
||||||
</kill>
|
</kill>
|
||||||
|
|
||||||
<action name="ResetWorkingPath">
|
<!-- <action name="ResetWorkingPath">-->
|
||||||
<fs>
|
<!-- <fs>-->
|
||||||
<delete path='${workingPath}/input/crossref/index_dump'/>
|
<!-- <delete path='${workingPath}/input/crossref/index_dump'/>-->
|
||||||
<!-- <mkdir path='${workingPath}/input/crossref'/>-->
|
<!--<!– <mkdir path='${workingPath}/input/crossref'/>–>-->
|
||||||
</fs>
|
<!-- </fs>-->
|
||||||
<ok to="ImportCrossRef"/>
|
<!-- <ok to="ImportCrossRef"/>-->
|
||||||
<error to="Kill"/>
|
<!-- <error to="Kill"/>-->
|
||||||
</action>
|
<!-- </action>-->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<action name="ImportCrossRef">
|
<!-- <action name="ImportCrossRef">-->
|
||||||
<java>
|
<!-- <java>-->
|
||||||
<job-tracker>${jobTracker}</job-tracker>
|
<!-- <job-tracker>${jobTracker}</job-tracker>-->
|
||||||
<name-node>${nameNode}</name-node>
|
<!-- <name-node>${nameNode}</name-node>-->
|
||||||
<main-class>eu.dnetlib.doiboost.crossref.CrossrefImporter</main-class>
|
<!-- <main-class>eu.dnetlib.doiboost.crossref.CrossrefImporter</main-class>-->
|
||||||
<arg>-t</arg><arg>${workingPath}/input/crossref/index_dump_1</arg>
|
<!-- <arg>-t</arg><arg>${workingPath}/input/crossref/index_dump_1</arg>-->
|
||||||
<arg>-n</arg><arg>${nameNode}</arg>
|
<!-- <arg>-n</arg><arg>${nameNode}</arg>-->
|
||||||
<arg>-ts</arg><arg>${timestamp}</arg>
|
<!-- <arg>-ts</arg><arg>${timestamp}</arg>-->
|
||||||
</java>
|
<!-- </java>-->
|
||||||
<ok to="End"/>
|
<!-- <ok to="End"/>-->
|
||||||
<error to="Kill"/>
|
<!-- <error to="Kill"/>-->
|
||||||
</action>
|
<!-- </action>-->
|
||||||
|
|
||||||
|
|
||||||
<action name="ExtractCrossrefToOAF">
|
<action name="ExtractCrossrefToOAF">
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
--driver-memory=${sparkDriverMemory}
|
--driver-memory=${sparkDriverMemory}
|
||||||
${sparkExtraOPT}
|
${sparkExtraOPT}
|
||||||
</spark-opts>
|
</spark-opts>
|
||||||
<arg>--sourcePath</arg><arg>${workingPath}/input/crossref/index_dump,${workingPath}/input/crossref/index_dump_1,${workingPath}/crossref/index_dump</arg>
|
<arg>--sourcePath</arg><arg>${workingPath}/input/crossref/crossref_ds</arg>
|
||||||
<arg>--targetPath</arg><arg>${workingPath}/input/crossref</arg>
|
<arg>--targetPath</arg><arg>${workingPath}/input/crossref</arg>
|
||||||
<arg>--master</arg><arg>yarn-cluster</arg>
|
<arg>--master</arg><arg>yarn-cluster</arg>
|
||||||
</spark>
|
</spark>
|
||||||
|
@ -78,26 +78,26 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<action name="GenerateDataset">
|
<!-- <action name="GenerateDataset">-->
|
||||||
<spark xmlns="uri:oozie:spark-action:0.2">
|
<!-- <spark xmlns="uri:oozie:spark-action:0.2">-->
|
||||||
<master>yarn-cluster</master>
|
<!-- <master>yarn-cluster</master>-->
|
||||||
<mode>cluster</mode>
|
<!-- <mode>cluster</mode>-->
|
||||||
<name>ExtractCrossrefToOAF</name>
|
<!-- <name>ExtractCrossrefToOAF</name>-->
|
||||||
<class>eu.dnetlib.doiboost.crossref.CrossrefDataset</class>
|
<!-- <class>eu.dnetlib.doiboost.crossref.CrossrefDataset</class>-->
|
||||||
<jar>dhp-doiboost-${projectVersion}.jar</jar>
|
<!-- <jar>dhp-doiboost-${projectVersion}.jar</jar>-->
|
||||||
<spark-opts>
|
<!-- <spark-opts>-->
|
||||||
--executor-memory=${sparkExecutorMemory}
|
<!-- --executor-memory=${sparkExecutorMemory}-->
|
||||||
--executor-cores=${sparkExecutorCores}
|
<!-- --executor-cores=${sparkExecutorCores}-->
|
||||||
--driver-memory=${sparkDriverMemory}
|
<!-- --driver-memory=${sparkDriverMemory}-->
|
||||||
${sparkExtraOPT}
|
<!-- ${sparkExtraOPT}-->
|
||||||
</spark-opts>
|
<!-- </spark-opts>-->
|
||||||
<arg>--sourcePath</arg><arg>/data/doiboost/crossref/cr_dataset</arg>
|
<!-- <arg>--sourcePath</arg><arg>/data/doiboost/crossref/cr_dataset</arg>-->
|
||||||
<arg>--targetPath</arg><arg>/data/doiboost/crossref/crossrefDataset</arg>
|
<!-- <arg>--targetPath</arg><arg>/data/doiboost/crossref/crossrefDataset</arg>-->
|
||||||
<arg>--master</arg><arg>yarn-cluster</arg>
|
<!-- <arg>--master</arg><arg>yarn-cluster</arg>-->
|
||||||
</spark>
|
<!-- </spark>-->
|
||||||
<ok to="End"/>
|
<!-- <ok to="End"/>-->
|
||||||
<error to="Kill"/>
|
<!-- <error to="Kill"/>-->
|
||||||
</action>
|
<!-- </action>-->
|
||||||
|
|
||||||
<end name="End"/>
|
<end name="End"/>
|
||||||
</workflow-app>
|
</workflow-app>
|
Loading…
Reference in New Issue