LDBC queries checked

Summary:
- checked existing queries and added new ones
- minor changes to LDBC setup

Reviewers: teon.banek, buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D737
This commit is contained in:
florijan 2017-09-01 15:39:32 +02:00
parent 7294f7812e
commit 21550d3bb1
25 changed files with 199 additions and 6 deletions

View File

@ -6,7 +6,8 @@ import sys
from neo4j.v1 import GraphDatabase, basic_auth
# Initialize driver and create session.
driver = GraphDatabase.driver('bolt://localhost:7687',
port = sys.argv[2] if len(sys.argv) > 2 else '7687'
driver = GraphDatabase.driver('bolt://localhost:%s' % port,
auth=basic_auth('', ''),
encrypted=False)
session = driver.session()

View File

@ -0,0 +1,2 @@
Person,Country,Year
30786325583618,Laos,2010

View File

@ -0,0 +1,2 @@
Person1,Person2
17592186055119,8796093025131

View File

@ -0,0 +1,3 @@
person_id: 17592186052613
message.creationDate <= 1354060800000
limit 20

View File

@ -0,0 +1,2 @@
person_id, messageX_createionDate, duration, countryX_name, countryY_name
17592186055119,1306886400000,42,Laos,Scotland

View File

@ -0,0 +1,2 @@
person_id, post_creationDate, duration
21990232559429, 1335830400000, 1e10

View File

@ -0,0 +1,2 @@
person_id, membership_joinDate
8796093030404, 1347062400000

View File

@ -0,0 +1,2 @@
Person_id|Tag
30786325583618|Angola

View File

@ -0,0 +1,2 @@
Person_id
17592186053137

View File

@ -0,0 +1,2 @@
Person_id
24189255818757

View File

@ -0,0 +1,2 @@
Person_id, message_creationDate
13194139542834, 1324080000000

View File

@ -0,0 +1,13 @@
MATCH (person:Person {id:"30786325583618"})-[:KNOWS*1..2]-(friend:Person)
WHERE not(person=friend)
WITH DISTINCT friend
MATCH (friend)-[worksAt:WORK_AT]->(company:Organisation)-[:IS_LOCATED_IN]->(:Place {name:"Laos"})
WHERE worksAt.workFrom < 2010
RETURN
friend.id AS friendId,
friend.firstName AS friendFirstName,
friend.lastName AS friendLastName,
company.name AS companyName,
worksAt.workFrom AS workFromYear
ORDER BY workFromYear ASC, tointeger(friendId) ASC, companyName DESC
LIMIT 20;

View File

@ -0,0 +1,13 @@
MATCH (person:Person {id:"30786325583618"})-[:KNOWS*1..2]-(friend:Person)
WHERE not(person=friend)
WITH DISTINCT friend
MATCH (friend)-[worksAt:WORK_AT]->(company:Organisation)-[:IS_LOCATED_IN]->(:Place {name:"Laos"})
WHERE worksAt.workFrom < 2010
RETURN
friend.id AS friendId,
friend.firstName AS friendFirstName,
friend.lastName AS friendLastName,
company.name AS companyName,
worksAt.workFrom AS workFromYear
ORDER BY workFromYear ASC, tointeger(friendId) ASC, companyName DESC
LIMIT 20;

View File

@ -0,0 +1,7 @@
MATCH (person1:Person {id:"17592186055119"}), (person2:Person {id:"8796093025131"})
OPTIONAL MATCH path = shortestPath((person1)-[:KNOWS*..15]-(person2))
RETURN
CASE path IS NULL
WHEN true THEN -1
ELSE length(path)
END AS pathLength;

View File

@ -0,0 +1,7 @@
MATCH (person1:Person {id:"17592186055119"}), (person2:Person {id:"8796093025131"})
OPTIONAL MATCH (person1)-bfs[r](a, b | type(a) = "KNOWS", 15)-(person2)
RETURN
CASE r IS NULL
WHEN true THEN -1
ELSE size(r) + 1
END AS pathLength;

View File

@ -0,0 +1,14 @@
MATCH (:Person {id:"17592186052613"})-[:KNOWS]-(friend:Person)<-[:HAS_CREATOR]-(message)
WHERE message.creationDate <= 1354060800000 AND (message:Post OR message:Comment)
RETURN
friend.id AS personId,
friend.firstName AS personFirstName,
friend.lastName AS personLastName,
message.id AS messageId,
CASE exists(message.content)
WHEN true THEN message.content
ELSE message.imageFile
END AS messageContent,
message.creationDate AS messageDate
ORDER BY messageDate DESC, toInt(messageId) ASC
LIMIT 20;

View File

@ -0,0 +1,14 @@
MATCH (:Person {id:"17592186052613"})-[:KNOWS]-(friend:Person)<-[:HAS_CREATOR]-(message)
WHERE message.creationDate <= 1354060800000 AND (message:Post OR message:Comment)
RETURN
friend.id AS personId,
friend.firstName AS personFirstName,
friend.lastName AS personLastName,
message.id AS messageId,
CASE message.content is not null
WHEN true THEN message.content
ELSE message.imageFile
END AS messageContent,
message.creationDate AS messageDate
ORDER BY messageDate DESC, tointeger(messageId) ASC
LIMIT 20;

View File

@ -0,0 +1,29 @@
MATCH (person:Person {id:"17592186055119"})-[:KNOWS*1..2]-(friend:Person)<-[:HAS_CREATOR]-(messageX),
(messageX)-[:IS_LOCATED_IN]->(countryX:Place)
WHERE
not(person=friend)
AND not((friend)-[:IS_LOCATED_IN]->()-[:IS_PART_OF]->(countryX))
AND countryX.name="Laos" AND messageX.creationDate>=1306886400000
AND messageX.creationDate<1306886400042
WITH friend, count(DISTINCT messageX) AS xCount
MATCH (friend)<-[:HAS_CREATOR]-(messageY)-[:IS_LOCATED_IN]->(countryY:Place)
WHERE
countryY.name="Scotland"
AND not((friend)-[:IS_LOCATED_IN]->()-[:IS_PART_OF]->(countryY))
AND messageY.creationDate>={4}
AND messageY.creationDate<{5}
WITH
friend.id AS friendId,
friend.firstName AS friendFirstName,
friend.lastName AS friendLastName,
xCount,
count(DISTINCT messageY) AS yCount
RETURN
friendId,
friendFirstName,
friendLastName,
xCount,
yCount,
xCount + yCount AS xyCount
ORDER BY xyCount DESC, toInt(friendId) ASC
LIMIT 10;

View File

@ -1,11 +1,11 @@
MATCH (person:Person {id:"21990232559429"})-[:KNOWS]-(:Person)<-[:HAS_CREATOR]-(post:Post)-[:HAS_TAG]->(tag:Tag)
WHERE post.creationDate >= toInt(1335830400000) AND post.creationDate < toInt(1339027200000)
WHERE post.creationDate >= 1335830400000 AND post.creationDate < 1345830400000
OPTIONAL MATCH (tag)<-[:HAS_TAG]-(oldPost:Post)-[:HAS_CREATOR]->(:Person)-[:KNOWS]-(person)
WHERE oldPost.creationDate < toInt(1335830400000)
WHERE oldPost.creationDate < 1335830400000
WITH tag, post, length(collect(oldPost)) AS oldPostCount
WHERE oldPostCount=0
RETURN
tag.name AS tagName,
length(collect(post)) AS postCount
ORDER BY postCount DESC, tagName ASC
LIMIT toInt(10);
LIMIT 10;

View File

@ -1,5 +1,5 @@
MATCH (person:Person {id:"21990232559429"})-[:KNOWS]-(:Person)<-[:HAS_CREATOR]-(post:Post)-[:HAS_TAG]->(tag:Tag)
WHERE post.creationDate >= 1335830400000 AND post.creationDate < 1339027200000
WHERE post.creationDate >= 1335830400000 AND post.creationDate < 1345830400000
OPTIONAL MATCH (tag)<-[:HAS_TAG]-(oldPost:Post)-[:HAS_CREATOR]->(:Person)-[:KNOWS]-(person)
WHERE oldPost.creationDate < 1335830400000
WITH tag, post, size(collect(oldPost)) AS oldPostCount

View File

@ -0,0 +1,14 @@
MATCH
(person:Person {id:"30786325583618"})-[:KNOWS*1..2]-(friend:Person),
(friend)<-[:HAS_CREATOR]-(friendPost:Post)-[:HAS_TAG]->(knownTag:Tag {name:"Angola"})
WHERE not(person=friend)
MATCH (friendPost)-[:HAS_TAG]->(commonTag:Tag)
WHERE not(commonTag=knownTag)
WITH DISTINCT commonTag, knownTag, friend
MATCH (commonTag)<-[:HAS_TAG]-(commonPost:Post)-[:HAS_TAG]->(knownTag)
WHERE (commonPost)-[:HAS_CREATOR]->(friend)
RETURN
commonTag.name AS tagName,
count(commonPost) AS postCount
ORDER BY postCount DESC, tagName ASC
LIMIT 20;

View File

@ -0,0 +1,16 @@
MATCH
(person:Person {id:"30786325583618"})-[:KNOWS*1..2]-(friend:Person),
(friend)<-[:HAS_CREATOR]-(friendPost:Post)-[:HAS_TAG]->(knownTag:Tag {name:"Angola"})
WHERE not(person=friend)
MATCH (friendPost)-[:HAS_TAG]->(commonTag:Tag)
WHERE not(commonTag=knownTag)
WITH DISTINCT commonTag, knownTag, friend
MATCH (commonTag)<-[:HAS_TAG]-(commonPost:Post)-[:HAS_TAG]->(knownTag)
OPTIONAL MATCH (commonPost)-[cpCreator:HAS_CREATOR]->(friend)
WITH commonTag, commonPost
WHERE cpCreator is not null
RETURN
commonTag.name AS tagName,
count(commonPost) AS postCount
ORDER BY postCount DESC, tagName ASC
LIMIT 20;

View File

@ -0,0 +1,21 @@
MATCH (person:Person {id:"17592186053137"})<-[:HAS_CREATOR]-(message)<-[like:LIKES]-(liker:Person)
WITH liker, message, like.creationDate AS likeTime, person
ORDER BY likeTime DESC, toInt(message.id) ASC
WITH
liker,
head(collect({msg: message, likeTime: likeTime})) AS latestLike,
person
RETURN
liker.id AS personId,
liker.firstName AS personFirstName,
liker.lastName AS personLastName,
latestLike.likeTime AS likeTime,
latestLike.msg.id AS messageId,
CASE exists(latestLike.msg.content)
WHEN true THEN latestLike.msg.content
ELSE latestLike.msg.imageFile
END AS messageContent,
latestLike.likeTime - latestLike.msg.creationDate AS latencyAsMilli,
not((liker)-[:KNOWS]-(person)) AS isNew
ORDER BY likeTime DESC, toInt(personId) ASC
LIMIT 10;

View File

@ -0,0 +1,23 @@
MATCH (person:Person {id:"17592186053137"})<-[:HAS_CREATOR]-(message)<-[like:LIKES]-(liker:Person)
WITH liker, message, like.creationDate AS likeTime, person
ORDER BY likeTime DESC, tointeger(message.id) ASC
WITH
liker,
collect(message)[0] AS latestLike_msg,
collect(likeTime)[0] AS latestLike_time,
person
OPTIONAL MATCH (liker)-[liker_knows_person:KNOWS]-(person)
RETURN
liker.id AS personId,
liker.firstName AS personFirstName,
liker.lastName AS personLastName,
latestLike_time AS likeTime,
latestLike_msg.id AS messageId,
CASE latestLike_msg.content is not null
WHEN true THEN latestLike_msg.content
ELSE latestLike_msg.imageFile
END AS messageContent,
latestLike_time - latestLike_msg.creationDate AS latencyAsMilli,
liker_knows_person is null AS isNew
ORDER BY likeTime DESC, tointeger(personId) ASC
LIMIT 10;

View File

@ -5,7 +5,7 @@ RETURN DISTINCT
friend.firstName AS personFirstName,
friend.lastName AS personLastName,
message.id AS messageId,
CASE message.content IS null
CASE message.content IS not null
WHEN true THEN message.content
ELSE message.imageFile
END AS messageContent,