Skip to content

Commit 1c77843

Browse files
committed
FactorGen: Optimize personNumFriendForums, personNumFriendComments, personNumFriendPosts tables
1 parent 88013ca commit 1c77843

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,14 @@ object FactorGenerationStage extends DatagenStage with Logging {
494494
frequency(posts, value = $"post.id", by = Seq($"Person.id"))
495495
},
496496
"personNumFriendPosts" -> Factor(PersonType, PersonKnowsPersonType, PostType) { case Seq(person, personKnowsPerson, post) =>
497-
val posts = person
497+
val personPosts = person
498498
.as("Person")
499-
.join(undirectedKnows(personKnowsPerson).as("knows1"), $"Person.id" === $"knows1.Person1Id", "leftouter")
500-
.join(post.as("post"), $"post.CreatorPersonId" === $"knows1.Person2Id", "leftouter")
501-
frequency(posts, value = $"post.id", by = Seq($"Person.id"))
499+
.join(post.as("Post"), $"Post.CreatorPersonId" === $"Person.id", "leftouter")
500+
val numPersonPosts = frequency(personPosts, value = $"Post.id", by = Seq($"Person.id"), agg = count)
501+
.select($"Person.id".as("Person1Id"), $"frequency")
502+
val friendPosts = numPersonPosts.as("numPersonPosts")
503+
.join(undirectedKnows(personKnowsPerson).as("knows"), $"numPersonPosts.Person1Id" === $"knows.Person2Id", "leftouter")
504+
frequency(friendPosts, value = $"frequency", by = Seq($"knows.Person1Id"), agg = sum)
502505
},
503506
"personNumFriendOfFriendPosts" -> Factor(PersonType, PersonKnowsPersonType, PostType) { case Seq(person, personKnowsPerson, post) =>
504507
val posts = person
@@ -516,11 +519,14 @@ object FactorGenerationStage extends DatagenStage with Logging {
516519
frequency(comments, value = $"comment.id", by = Seq($"Person.id"))
517520
},
518521
"personNumFriendComments" -> Factor(PersonType, PersonKnowsPersonType, CommentType) { case Seq(person, personKnowsPerson, comment) =>
519-
val comments = person
522+
val personComments = person
520523
.as("Person")
521-
.join(undirectedKnows(personKnowsPerson).as("knows1"), $"Person.id" === $"knows1.Person1Id", "leftouter")
522-
.join(comment.as("comment"), $"comment.CreatorPersonId" === $"knows1.Person2Id", "leftouter")
523-
frequency(comments, value = $"comment.id", by = Seq($"Person.id"))
524+
.join(comment.as("Comment"), $"Comment.CreatorPersonId" === $"Person.id", "leftouter")
525+
val numPersonComments = frequency(personComments, value = $"Comment.id", by = Seq($"Person.id"), agg = count)
526+
.select($"Person.id".as("Person1Id"), $"frequency")
527+
val friendComments = numPersonComments.as("numPersonComments")
528+
.join(undirectedKnows(personKnowsPerson).as("knows"), $"numPersonComments.Person1Id" === $"knows.Person2Id", "leftouter")
529+
frequency(friendComments, value = $"frequency", by = Seq($"knows.Person1Id"), agg = sum)
524530
},
525531
// likes
526532
"personLikesNumMessages" -> Factor(PersonType, PersonLikesCommentType, PersonLikesPostType) { case Seq(person, personLikesComment, personLikesPost) =>
@@ -534,28 +540,26 @@ object FactorGenerationStage extends DatagenStage with Logging {
534540
},
535541
// tags
536542
"personNumTags" -> Factor(PersonHasInterestTagType) { case Seq(interest) =>
537-
frequency(interest, value = $"TagId", by = Seq($"personId"))
543+
frequency(interest, value = $"TagId", by = Seq($"PersonId"))
538544
},
539545
"personNumFriendTags" -> Factor(PersonHasInterestTagType, PersonKnowsPersonType) { case Seq(interest, personKnowsPerson) =>
540-
val personNumTags = frequency(interest, value = $"TagId", by = Seq($"personId"), agg = count)
546+
val personNumTags = frequency(interest, value = $"TagId", by = Seq($"PersonId"), agg = count)
541547
.select($"personId".as("Person1Id"), $"frequency")
542-
543548
val friendTags = personNumTags.as("personNumTags")
544549
.join(undirectedKnows(personKnowsPerson).as("knows"), $"personNumTags.Person1Id" === $"knows.Person2Id", "leftouter")
545-
546550
frequency(friendTags, value = $"frequency", by = Seq($"knows.Person1Id"), agg = sum)
547551
},
548552
// forums
549553
"personNumForums" -> Factor(ForumHasMemberType) { case Seq(hasMember) =>
550554
frequency(hasMember, value = $"ForumId", by = Seq($"PersonId"))
551555
},
552556
"personNumFriendForums" -> Factor(ForumHasMemberType, PersonKnowsPersonType) { case Seq(hasMember, personKnowsPerson) =>
553-
frequency(
554-
undirectedKnows(personKnowsPerson).as("knows")
555-
.join(hasMember, $"PersonId" === $"knows.Person2Id", "leftouter"),
556-
value = $"ForumId",
557-
by = Seq($"knows.Person1Id")
558-
)
557+
val personNumForums = frequency(hasMember, value = $"ForumId", by = Seq($"PersonId"), agg = count)
558+
.select($"PersonId".as("Person1Id"), $"frequency")
559+
val friendForums = personNumForums.as("personNumForums")
560+
.join(undirectedKnows(personKnowsPerson).as("knows"), $"personNumForums.Person1Id" === $"knows.Person2Id", "leftouter")
561+
frequency(friendForums, value = $"frequency", by = Seq($"knows.Person1Id"), agg = sum)
562+
559563
},
560564
"personNumFriendOfFriendForums" -> Factor(ForumHasMemberType, PersonKnowsPersonType) { case Seq(hasMember, personKnowsPerson) =>
561565
frequency(

0 commit comments

Comments
 (0)