Skip to content

Commit

Permalink
Format and some optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinglu committed Dec 7, 2022
1 parent 68b8bb2 commit 8fe4150
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 57 deletions.
7 changes: 3 additions & 4 deletions nebula/queries/interactive-complex-10.ngql
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ WITH person, collect(id(friend)) AS friends
MATCH (person:Person)-[:KNOWS*2]-(friend)-[:IS_LOCATED_IN]->(city:Place)
WHERE id(friend) != $personId AND id(friend) NOT IN friends
WITH person, city, friend, datetime(friend.Person.birthday) as birthday
WHERE (birthday.month==$month AND birthday.day>=21) OR
(birthday.month==($month%12)+1 AND birthday.day<22)
WHERE (birthday.month==$month AND birthday.day>=21) OR (birthday.month==($month%12)+1 AND birthday.day<22)
WITH DISTINCT friend AS f, city AS c, person AS p
OPTIONAL MATCH (f)<-[:POST_HAS_CREATOR]-(post:Post)
OPTIONAL MATCH (p)-[:HAS_INTEREST]->(m), (post)-[:HAS_TAG]->(m)
WITH f AS friend, c AS city, post, CASE WHEN count(m) > 0 THEN 1 ELSE 0 END AS cnt
WITH friend, city, sum(cnt) AS commonPostCount, count(post) AS postCount
WITH f AS friend, c AS city, id(post) AS postId, CASE WHEN count(id(m)) > 0 THEN 1 ELSE 0 END AS cnt
WITH friend, city, sum(cnt) AS commonPostCount, count(postId) AS postCount
RETURN toInteger(substr(id(friend), 2)) AS personId,
friend.Person.firstName AS personFirstName,
friend.Person.lastName AS personLastName,
Expand Down
16 changes: 15 additions & 1 deletion nebula/queries/interactive-complex-11.ngql
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
GO 1 TO 2 STEPS FROM $personId OVER KNOWS BIDIRECT WHERE KNOWS._dst != $personId YIELD distinct KNOWS._dst AS friendId | GO FROM $-.friendId OVER WORK_AT WHERE WORK_AT.workFrom < $workFromYear YIELD $-.friendId AS friendId, $^.Person.firstName AS firstName, $^.Person.lastName AS lastName, WORK_AT.workFrom AS workFrom, WORK_AT._dst AS orgId| GO FROM $-.orgId OVER IS_LOCATED_IN WHERE $$.Place.name == $countryName YIELD toInteger(substr($-.friendId, 2)) AS personId, $-.firstName AS personFirstName, $-.lastName AS personLastName, $^.Organisation.name AS organizationName, $-.workFrom AS organizationWorkFromYear | ORDER BY $-.organizationWorkFromYear ASC, $-.personId ASC, $-.organizationName DESC | LIMIT 10
GO 1 TO 2 STEPS FROM $personId OVER KNOWS BIDIRECT WHERE KNOWS._dst != $personId YIELD distinct KNOWS._dst AS friendId |
GO FROM $-.friendId OVER WORK_AT WHERE WORK_AT.workFrom < $workFromYear
YIELD $-.friendId AS friendId,
$^.Person.firstName AS firstName,
$^.Person.lastName AS lastName,
WORK_AT.workFrom AS workFrom,
WORK_AT._dst AS orgId |
GO FROM $-.orgId OVER IS_LOCATED_IN WHERE $$.Place.name == $countryName
YIELD toInteger(substr($-.friendId, 2)) AS personId,
$-.firstName AS personFirstName,
$-.lastName AS personLastName,
$^.Organisation.name AS organizationName,
$-.workFrom AS organizationWorkFromYear |
ORDER BY $-.organizationWorkFromYear ASC, $-.personId ASC, $-.organizationName DESC |
LIMIT 10
10 changes: 5 additions & 5 deletions nebula/queries/interactive-complex-12.ngql
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
MATCH (tag1:`Tag`)-[:HAS_TYPE|IS_SUBCLASS_OF*0..6]->(baseTagClass:Tagclass)
WHERE tag1.`Tag`.name == $tagClassName OR baseTagClass.Tagclass.name == $tagClassName
WITH collect(id(tag1)) as T
MATCH (p:Person)-[:KNOWS]-(friend:Person)<-[:COMMENT_HAS_CREATOR]-(comment1:`Comment`)-[:REPLY_OF_POST]->(:Post)-[:HAS_TAG]->(tag2:`Tag`)
WHERE id(p) == $personId AND id(tag2) in T
MATCH (p:Person)-[:KNOWS]-(friend:Person)<-[:COMMENT_HAS_CREATOR]-(comment1:`Comment`),
(tag1:`Tag`)<-[:HAS_TAG]-(:Post)<-[:REPLY_OF_POST]->(comment1:`Comment`)
WHERE id(p) == $personId
RETURN
toInteger(substr(id(friend),2)) AS personId,
friend.Person.firstName AS personFirstName,
friend.Person.lastName AS personLastName,
collect(DISTINCT tag2.`Tag`.name) AS tagNames,
collect(DISTINCT tag1.`Tag`.name) AS tagNames,
count(DISTINCT id(comment1)) AS replyCount
ORDER BY
replyCount DESC,
personId ASC
LIMIT 20
LIMIT 20
4 changes: 3 additions & 1 deletion nebula/queries/interactive-complex-13.ngql
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
find shortest path from $person1Id to $person2Id over KNOWS BIDIRECT yield path as p|yield collect(length($-.p)) AS l | yield case size($-.l) when 0 then -1 else $-.l[0] end;
find shortest path from $person1Id to $person2Id over KNOWS BIDIRECT yield path as p |
yield collect(length($-.p)) AS l |
yield case size($-.l) when 0 then -1 else $-.l[0] end;
16 changes: 8 additions & 8 deletions nebula/queries/interactive-complex-14.ngql
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ WITH
[idx IN range(1, size(pathNodes)-1) | [prev IN [pathNodes[idx-1]] | [curr IN [pathNodes[idx]] | [prev, curr]]]] AS vertList
UNWIND vertList AS c
WITH c[0][0][0] AS prev, c[0][0][1] AS curr, personIdsInPath
OPTIONAL MATCH (curr)<-[:COMMENT_HAS_CREATOR]-(comm:`Comment`), (prev)<-[:POST_HAS_CREATOR]-(:Post)<-[:REPLY_OF_POST]-(comm)
WITH count(comm) AS cnt1, prev, curr, personIdsInPath
OPTIONAL MATCH (prev)<-[:COMMENT_HAS_CREATOR]-(comm:`Comment`), (curr)<-[:POST_HAS_CREATOR]-(:Post)<-[:REPLY_OF_POST]-(comm)
WITH count(comm) AS cnt2, cnt1, prev, curr, personIdsInPath
OPTIONAL MATCH (prev)<-[:COMMENT_HAS_CREATOR]-(comm:`Comment`)-[:REPLY_OF_COMMENT]->(comm2:`Comment`), (curr)<-[:COMMENT_HAS_CREATOR]-(comm2)
WITH count(comm) AS cnt3, cnt1, cnt2, prev, curr, personIdsInPath
OPTIONAL MATCH (curr)<-[:COMMENT_HAS_CREATOR]-(comm:`Comment`)-[:REPLY_OF_COMMENT]->(comm2:`Comment`), (prev)<-[:COMMENT_HAS_CREATOR]-(comm2)
WITH count(comm) AS cnt4, cnt1, cnt2, cnt3, prev, curr, personIdsInPath
OPTIONAL MATCH (curr)<-[:COMMENT_HAS_CREATOR]-(comm:`Comment`), (prev)<-[:POST_HAS_CREATOR]-(:Post)<-[:REPLY_OF_POST]-(comm:`Comment`)
WITH count(id(comm)) AS cnt1, prev, curr, personIdsInPath
OPTIONAL MATCH (prev)<-[:COMMENT_HAS_CREATOR]-(comm:`Comment`), (curr)<-[:POST_HAS_CREATOR]-(:Post)<-[:REPLY_OF_POST]-(comm:`Comment`)
WITH count(id(comm)) AS cnt2, cnt1, prev, curr, personIdsInPath
OPTIONAL MATCH (prev)<-[:COMMENT_HAS_CREATOR]-(:`Comment`)-[:REPLY_OF_COMMENT]->(comm:`Comment`), (curr)<-[:COMMENT_HAS_CREATOR]-(comm:`Comment`)
WITH count(id(comm)) AS cnt3, cnt1, cnt2, prev, curr, personIdsInPath
OPTIONAL MATCH (curr)<-[:COMMENT_HAS_CREATOR]-(:`Comment`)-[:REPLY_OF_COMMENT]->(comm:`Comment`), (prev)<-[:COMMENT_HAS_CREATOR]-(comm:`Comment`)
WITH count(id(comm)) AS cnt4, cnt1, cnt2, cnt3, prev, curr, personIdsInPath
RETURN personIdsInPath, sum(cnt1 + cnt2 + 0.5 * cnt3 + 0.5 * cnt4) AS pathWeight
ORDER BY pathWeight DESC, personIdsInPath ASC
33 changes: 24 additions & 9 deletions nebula/queries/interactive-complex-2.ngql
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
GO FROM $personId OVER KNOWS BIDIRECT YIELD KNOWS._dst AS friendId
| GO FROM $-.friendId OVER POST_HAS_CREATOR, COMMENT_HAS_CREATOR REVERSELY WHERE (COMMENT_HAS_CREATOR.creationDate is not EMPTY and COMMENT_HAS_CREATOR.creationDate <= $maxDate) or (POST_HAS_CREATOR.creationDate is not EMPTY and POST_HAS_CREATOR.creationDate <= $maxDate)
GO FROM $personId OVER KNOWS BIDIRECT YIELD KNOWS._dst AS friendId |
GO FROM $-.friendId OVER POST_HAS_CREATOR, COMMENT_HAS_CREATOR REVERSELY
WHERE
(COMMENT_HAS_CREATOR.creationDate is not EMPTY and COMMENT_HAS_CREATOR.creationDate <= $maxDate) or (POST_HAS_CREATOR.creationDate is not EMPTY and POST_HAS_CREATOR.creationDate <= $maxDate)
YIELD
toInteger(substr($-.friendId, 2)) AS personId,
$^.Person.firstName AS personFirstName,
$^.Person.lastName AS personLastName,
toInteger(substr(id($$), 2)) AS messageId,
CASE WHEN COMMENT_HAS_CREATOR.content is not EMPTY THEN COMMENT_HAS_CREATOR.content ELSE CASE size(POST_HAS_CREATOR.imageFile) WHEN 0 THEN POST_HAS_CREATOR.content ELSE POST_HAS_CREATOR.imageFile END END AS messageContent,
CASE WHEN COMMENT_HAS_CREATOR.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR.creationDate ELSE POST_HAS_CREATOR.creationDate END AS messageCreationDate
| ORDER BY $-.messageCreationDate DESC, $-.messageId ASC | LIMIT 20
toInteger(substr($-.friendId, 2)) AS personId,
$^.Person.firstName AS personFirstName,
$^.Person.lastName AS personLastName,
toInteger(substr(id($$), 2)) AS messageId,
CASE
WHEN COMMENT_HAS_CREATOR.content is not EMPTY
THEN COMMENT_HAS_CREATOR.content
ELSE
CASE size(POST_HAS_CREATOR.imageFile)
WHEN 0 THEN POST_HAS_CREATOR.content
ELSE POST_HAS_CREATOR.imageFile
END
END AS messageContent,
CASE
WHEN COMMENT_HAS_CREATOR.creationDate is not EMPTY
THEN COMMENT_HAS_CREATOR.creationDate
ELSE POST_HAS_CREATOR.creationDate
END AS messageCreationDate |
ORDER BY $-.messageCreationDate DESC, $-.messageId ASC |
LIMIT 20
24 changes: 12 additions & 12 deletions nebula/queries/interactive-complex-4.ngql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
MATCH (person:Person)-[:KNOWS]-(:Person)<-[:POST_HAS_CREATOR]-(post:Post)-[:HAS_TAG]->(`tag`:`Tag`)
WHERE id(person) == $personId AND post.Post.creationDate >= $startDate AND post.Post.creationDate < $endDate
WITH person, count(post) AS postsOnTag, `tag`
OPTIONAL MATCH (person)-[:KNOWS]-()<-[:POST_HAS_CREATOR]-(oldPost:Post)-[:HAS_TAG]->(`tag`)
WHERE oldPost.Post.creationDate < $startDate
WITH person, postsOnTag, `tag`, count(oldPost) AS cp
WHERE cp == 0
RETURN
`tag`.`Tag`.name AS tagName,
sum(postsOnTag) AS postCount
ORDER BY postCount DESC, tagName ASC
limit 10
MATCH (person:Person)-[:KNOWS]-(:Person)<-[:POST_HAS_CREATOR]-(post:Post), (post)-[:HAS_TAG]->(`tag`:`Tag`)
WHERE id(person) == $personId AND post.Post.creationDate >= $startDate AND post.Post.creationDate < $endDate
WITH person, count(post) AS postsOnTag, `tag`
OPTIONAL MATCH (person)-[:KNOWS]-()<-[:POST_HAS_CREATOR]-(oldPost:Post), (oldPost)-[:HAS_TAG]->(`tag`)
WHERE oldPost.Post.creationDate < $startDate
WITH person, postsOnTag, `tag`, count(oldPost) AS cp
WHERE cp == 0
RETURN
`tag`.`Tag`.name AS tagName,
sum(postsOnTag) AS postCount
ORDER BY postCount DESC, tagName ASC
LIMIT 10
8 changes: 7 additions & 1 deletion nebula/queries/interactive-complex-6.ngql
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
GO 1 to 2 steps from $personId over KNOWS bidirect where KNOWS._dst <> $personId yield distinct KNOWS._dst as friend | GO from $-.friend over POST_HAS_CREATOR reversely yield distinct POST_HAS_CREATOR._dst as friendPost | GO from $-.friendPost over HAS_TAG where $$.`Tag`.name==$tagName yield distinct HAS_TAG._src as postWithSpecifiedTag | GO from $-.postWithSpecifiedTag over HAS_TAG where $$.`Tag`.name<>$tagName yield distinct $$.`Tag`.name as otherTagName, HAS_TAG._src as commonPost | group by $-.otherTagName yield $-.otherTagName as otherTagName, count($-.commonPost) as postCount | order by $-.postCount desc, $-.otherTagName ASC | limit 10
GO 1 to 2 steps from $personId over KNOWS bidirect where KNOWS._dst <> $personId yield distinct KNOWS._dst as friend |
GO from $-.friend over POST_HAS_CREATOR reversely yield distinct POST_HAS_CREATOR._dst as friendPost |
GO from $-.friendPost over HAS_TAG where $$.`Tag`.name==$tagName yield distinct HAS_TAG._src as postWithSpecifiedTag |
GO from $-.postWithSpecifiedTag over HAS_TAG where $$.`Tag`.name<>$tagName yield distinct $$.`Tag`.name as otherTagName, HAS_TAG._src as commonPost |
group by $-.otherTagName yield $-.otherTagName as otherTagName, count($-.commonPost) as postCount |
order by $-.postCount desc, $-.otherTagName ASC |
limit 10
17 changes: 5 additions & 12 deletions nebula/queries/interactive-complex-7.ngql
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
MATCH (person:Person)<-[:POST_HAS_CREATOR|COMMENT_HAS_CREATOR]-(message)<-[like:LIKES_COMMENT|LIKES_POST]-(liker:Person)
WHERE id(person) == $personId
WITH
liker,
message,
like.creationDate AS likeTime,
person,
id(message) AS messageId
ORDER BY
likeTime DESC,
messageId ASC
WHERE id(person) == $personId
WITH liker, message, like.creationDate AS likeTime, person, id(message) AS messageId
ORDER BY likeTime DESC, messageId ASC
WITH
liker,
head(collect({msg:message, likeTime:likeTime})) AS latestLike,
person
OPTIONAL MATCH (liker)-[e:KNOWS]-(person)
OPTIONAL MATCH (person)-[e:KNOWS]-(liker)
RETURN
toInteger(substr(id(liker), 2)) AS personId,
liker.Person.firstName AS personFirstName,
Expand All @@ -31,4 +24,4 @@ RETURN
ORDER BY
likeCreationDate DESC,
personId ASC
LIMIT 20
LIMIT 20
12 changes: 11 additions & 1 deletion nebula/queries/interactive-complex-8.ngql
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
GO FROM $personId OVER POST_HAS_CREATOR, COMMENT_HAS_CREATOR REVERSELY YIELD id($$) AS messageId | GO FROM $-.messageId OVER REPLY_OF_COMMENT, REPLY_OF_POST REVERSELY YIELD id($$) AS commentId | GO FROM $-.commentId OVER COMMENT_HAS_CREATOR YIELD COMMENT_HAS_CREATOR._dst AS personId, $$.Person.firstName AS personFirstName, $$.Person.lastName AS personLastName, $^.`Comment`.creationDate AS commentCreationDate, toInteger(substr($-.commentId, 2)) AS commentId, $^.`Comment`.content AS commentContent |ORDER BY $-.commentCreationDate DESC, $-.commentId ASC|LIMIT 20
GO FROM $personId OVER POST_HAS_CREATOR, COMMENT_HAS_CREATOR REVERSELY YIELD id($$) AS messageId |
GO FROM $-.messageId OVER REPLY_OF_COMMENT, REPLY_OF_POST REVERSELY YIELD id($$) AS commentId |
GO FROM $-.commentId OVER COMMENT_HAS_CREATOR
YIELD COMMENT_HAS_CREATOR._dst AS personId,
$$.Person.firstName AS personFirstName,
$$.Person.lastName AS personLastName,
$^.`Comment`.creationDate AS commentCreationDate,
toInteger(substr($-.commentId, 2)) AS commentId,
$^.`Comment`.content AS commentContent |
ORDER BY $-.commentCreationDate DESC, $-.commentId ASC |
LIMIT 20
20 changes: 17 additions & 3 deletions nebula/queries/interactive-complex-9.ngql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
$-.personFirstName AS personFirstName,
$-.personLastName AS personLastName,
toInteger(substr(id($$), 2)) AS messageId,
CASE WHEN COMMENT_HAS_CREATOR.content is not EMPTY THEN COMMENT_HAS_CREATOR.content ELSE CASE size(POST_HAS_CREATOR.imageFile) WHEN 0 THEN POST_HAS_CREATOR.content ELSE POST_HAS_CREATOR.imageFile END END AS messageContent,
CASE WHEN COMMENT_HAS_CREATOR.creationDate is not EMPTY THEN COMMENT_HAS_CREATOR.creationDate ELSE POST_HAS_CREATOR.creationDate END AS messageCreationDate
| ORDER BY $-.messageCreationDate DESC, $-.messageId ASC | LIMIT 20
CASE
WHEN COMMENT_HAS_CREATOR.content is not EMPTY
THEN COMMENT_HAS_CREATOR.content
ELSE
CASE size(POST_HAS_CREATOR.imageFile)
WHEN 0
THEN POST_HAS_CREATOR.content
ELSE POST_HAS_CREATOR.imageFile
END
END AS messageContent,
CASE
WHEN COMMENT_HAS_CREATOR.creationDate is not EMPTY
THEN COMMENT_HAS_CREATOR.creationDate
ELSE POST_HAS_CREATOR.creationDate
END AS messageCreationDate
| ORDER BY $-.messageCreationDate DESC, $-.messageId ASC
| LIMIT 20

0 comments on commit 8fe4150

Please sign in to comment.