Skip to content

Commit 88013ca

Browse files
committed
FactorGen: Optimize computation of personNumFriendOfFriendPosts table, reformat function to one line
1 parent d7a3d76 commit 88013ca

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ object FactorGenerationStage extends DatagenStage with Logging {
484484
.join(undirectedKnows(personKnowsPerson).as("knows"), $"Person1.id" === $"knows.Person1Id", "leftouter")
485485
.join(personNumFriends.as("personNumFriends"), $"personNumFriends.Person1Id" === $"knows.Person2Id", "leftouter")
486486

487-
frequency(knows2, value = $"frequency", by = Seq($"Person1.id"), agg = sum)
487+
frequency(knows2, value = $"frequency", by = Seq($"knows.Person1Id"), agg = sum)
488488
},
489489
// posts
490490
"personNumPosts" -> Factor(PersonType, PostType) { case Seq(person, post) =>
@@ -534,27 +534,20 @@ object FactorGenerationStage extends DatagenStage with Logging {
534534
},
535535
// tags
536536
"personNumTags" -> Factor(PersonHasInterestTagType) { case Seq(interest) =>
537-
frequency(
538-
interest,
539-
value = $"TagId",
540-
by = Seq($"personId")
541-
)
537+
frequency(interest, value = $"TagId", by = Seq($"personId"))
542538
},
543539
"personNumFriendTags" -> Factor(PersonHasInterestTagType, PersonKnowsPersonType) { case Seq(interest, personKnowsPerson) =>
544-
frequency(
545-
undirectedKnows(personKnowsPerson).as("knows")
546-
.join(interest, $"personId" === $"knows.Person2Id", "leftouter"),
547-
value = $"TagId",
548-
by = Seq($"knows.Person1Id")
549-
)
540+
val personNumTags = frequency(interest, value = $"TagId", by = Seq($"personId"), agg = count)
541+
.select($"personId".as("Person1Id"), $"frequency")
542+
543+
val friendTags = personNumTags.as("personNumTags")
544+
.join(undirectedKnows(personKnowsPerson).as("knows"), $"personNumTags.Person1Id" === $"knows.Person2Id", "leftouter")
545+
546+
frequency(friendTags, value = $"frequency", by = Seq($"knows.Person1Id"), agg = sum)
550547
},
551548
// forums
552549
"personNumForums" -> Factor(ForumHasMemberType) { case Seq(hasMember) =>
553-
frequency(
554-
hasMember,
555-
value = $"ForumId",
556-
by = Seq($"PersonId")
557-
)
550+
frequency(hasMember, value = $"ForumId", by = Seq($"PersonId"))
558551
},
559552
"personNumFriendForums" -> Factor(ForumHasMemberType, PersonKnowsPersonType) { case Seq(hasMember, personKnowsPerson) =>
560553
frequency(
@@ -575,11 +568,7 @@ object FactorGenerationStage extends DatagenStage with Logging {
575568
},
576569
// companies
577570
"personNumCompanies" -> Factor(PersonWorkAtCompanyType) { case Seq(workAt) =>
578-
frequency(
579-
workAt,
580-
value = $"CompanyId",
581-
by = Seq($"PersonId")
582-
)
571+
frequency(workAt, value = $"CompanyId", by = Seq($"PersonId"))
583572
},
584573
"personNumFriendCompanies" -> Factor(PersonWorkAtCompanyType, PersonKnowsPersonType) { case Seq(workAt, personKnowsPerson) =>
585574
frequency(

0 commit comments

Comments
 (0)