forked from gaolk/graph-database-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathquery_runner.py
75 lines (58 loc) · 2.16 KB
/
query_runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
############################################################
# Copyright (c) 2015-now, TigerGraph Inc.
# All rights reserved
# It is provided as it is for benchmark reproducible purpose.
# anyone can use it for benchmark purpose with the
# acknowledgement to TigerGraph.
# Author: Mingxi Wu [email protected]
############################################################
# from neo4j.v1 import GraphDatabase, basic_auth
import redis
import requests
import config
class QueryRunner():
def __init__(self):
pass
def KN(self, root):
pass
def SSSP(self, root):
pass
def PG(self):
pass
def WCC(self):
pass
def LCC(self):
pass
class RedisGraphQueryRunner(QueryRunner):
def __init__(self, graphid, label, url="127.0.0.1:6379"):
QueryRunner.__init__(self)
ip, port = url.split(':')
self.graphid = graphid
self.label = label
self.driver = redis.Redis(ip, int(port))
def KN(self, root, depth):
try:
query = "MATCH (s:%s)-[*%d]->(t) WHERE s.id=%d RETURN count(t)" % (self.label, int(depth), int(root))
result = self.driver.execute_command('graph.query', self.graphid, query)
except Exception as e: # timeout, we return -1, reset session
print("Exception: %s" % e)
raise e
return -1
else:
return float(result[1][0][0])
# TigerGraph query runner (compatible with v2.1.8)
class TigerGraphQueryRunner(QueryRunner):
def __init__(self, url=config.TIGERGRAPH_HTTP):
QueryRunner.__init__(self)
self.session = requests.Session()
self.url = url
def KN(self, root, depth):
result = self.session.get(self.url + "/query/khop", params={'start_node': root, "depth": depth}).json()
return result["results"][0]["Start.size()"]
def PG(self, iteration):
result = self.session.get(self.url + "/query/pagerank",
params={'iteration': iteration, "dampingFactor": 0.8}).json()
print (result)
def WCC(self):
result = self.session.get(self.url + "/query/wcc").json()
print (result)