Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathSessionPoolExample.py
More file actions
Latest commit
82 lines (63 loc) · 2.32 KB
/
Copy pathSessionPoolExample.py
File metadata and controls
82 lines (63 loc) · 2.32 KB
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
76
77
78
79
80
81
82
#!/usr/bin/env python
# --coding:utf-8--
# Copyright (c) 2022 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
importtime
fromFormatRespimportprint_resp
fromnebula3.common.ttypesimportErrorCode
fromnebula3.ConfigimportSessionPoolConfig
fromnebula3.gclient.netimportConnection
fromnebula3.gclient.net.SessionPoolimportSessionPool
if__name__=="__main__":
ip="127.0.0.1"
port=9669
try:
config=SessionPoolConfig()
# prepare space
conn=Connection()
conn.open(ip, port, 1000)
auth_result=conn.authenticate("root", "nebula")
assertauth_result.get_session_id() !=0
resp=conn.execute(
auth_result._session_id,
"CREATE SPACE IF NOT EXISTS session_pool_test(vid_type=FIXED_STRING(30))",
)
assertresp.error_code==ErrorCode.SUCCEEDED
# insert data need to sleep after create schema
time.sleep(10)
# init session pool
session_pool=SessionPool("root", "nebula", "session_pool_test", [(ip, port)])
assertsession_pool.init(config)
# add schema
resp=session_pool.execute(
"CREATE TAG IF NOT EXISTS person(name string, age int);"
"CREATE EDGE like (likeness double);"
)
time.sleep(6)
# insert vertex
resp=session_pool.execute(
'INSERT VERTEX person(name, age) VALUES "Bob":("Bob", 10), "Lily":("Lily", 9)'
)
assertresp.is_succeeded(), resp.error_msg()
# insert edges
resp=session_pool.execute(
'INSERT EDGE like(likeness) VALUES "Bob"->"Lily":(80.0);'
)
assertresp.is_succeeded(), resp.error_msg()
resp=session_pool.execute('FETCH PROP ON person "Bob" YIELD vertex as node')
assertresp.is_succeeded(), resp.error_msg()
print_resp(resp)
resp=session_pool.execute('FETCH PROP ON like "Bob"->"Lily" YIELD edge as e')
assertresp.is_succeeded(), resp.error_msg()
print_resp(resp)
# drop space
conn.execute(
auth_result._session_id,
"DROP SPACE session_pool_test",
)
print("Example finished")
exceptException:
importtraceback
print(traceback.format_exc())
exit(1)