Skip to content

Commit 502cd0c

Browse files
committed
Include temporal attributes in sameUniversityKnows factor table
1 parent a4675f3 commit 502cd0c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main/scala/ldbc/snb/datagen/factors/FactorGenerationStage.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ object FactorGenerationStage extends DatagenStage with Logging {
101101
.alias("Knows")
102102
.cache()
103103

104+
private def undirectedKnowsTemporal(personKnowsPerson: DataFrame) =
105+
personKnowsPerson
106+
.select(
107+
expr("stack(2, Person1Id, Person2Id, creationDate, deletionDate, Person2Id, Person1Id, creationDate, deletionDate)")
108+
.as(Seq("Person1Id", "Person2Id", "creationDate", "deletionDate"))
109+
)
110+
.alias("Knows")
111+
.cache()
112+
104113
private def nHops(relationships: DataFrame, n: Int, joinKeys: (String, String), sample: Option[DataFrame => DataFrame] = None): DataFrame = {
105114
val (leftKey, rightKey) = joinKeys
106115
relationships
@@ -433,14 +442,17 @@ object FactorGenerationStage extends DatagenStage with Logging {
433442
},
434443
"sameUniversityKnows" -> LargeFactor(PersonKnowsPersonType, PersonStudyAtUniversityType) { case Seq(personKnowsPerson, studyAt) =>
435444
val size = Math.max(Math.ceil(personKnowsPerson.rdd.getNumPartitions / 10).toInt, 1)
436-
undirectedKnows(personKnowsPerson)
445+
undirectedKnowsTemporal(personKnowsPerson)
437446
.join(studyAt.as("studyAt1"), $"studyAt1.personId" === $"knows.person1Id")
438447
.join(studyAt.as("studyAt2"), $"studyAt2.personId" === $"knows.person2Id")
439448
.where($"studyAt1.universityId" === $"studyAt2.universityId")
440449
.select(
441450
$"knows.person1Id".as("person1Id"),
442-
$"knows.person2Id".as("person2Id")
451+
$"knows.person2Id".as("person2Id"),
452+
functions.greatest($"knows.creationDate", $"studyAt1.creationDate", $"studyAt2.creationDate").alias("creationDate"),
453+
functions.least($"knows.deletionDate", $"studyAt1.deletionDate", $"studyAt2.deletionDate").alias("deletionDate")
443454
)
455+
.where($"creationDate" < $"deletionDate")
444456
.coalesce(size)
445457
}
446458
)

0 commit comments

Comments
 (0)