-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: cast params #273 * handle None of params * lint: make black happy * docs and example added with UT coverage * docs of result set as primitive * fix structure to make the cast non-breaking (#350) * make linter happy * minor fix * remove list cast * fix NList usage * fix test * chore: polish readme --------- Co-authored-by: 盐粒 Yanli <[email protected]>
- Loading branch information
1 parent
e876666
commit 6672e51
Showing
5 changed files
with
294 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import time | ||
|
||
from nebula3.gclient.net import ConnectionPool | ||
from nebula3.Config import Config | ||
from nebula3.common import ttypes | ||
|
||
# define a config | ||
config = Config() | ||
connection_pool = ConnectionPool() | ||
connection_pool.init([("127.0.0.1", 9669)], config) | ||
|
||
# get session from the connection pool | ||
client = connection_pool.get_session("root", "nebula") | ||
client.execute("CREATE SPACE IF NOT EXISTS test(vid_type=FIXED_STRING(30));") | ||
|
||
|
||
time.sleep( | ||
6 | ||
) # two cycles of heartbeat, by default of a NebulaGraph cluster, we will need to sleep 20s | ||
|
||
client.execute( | ||
"USE test;" | ||
"CREATE TAG IF NOT EXISTS person(name string, age int);" | ||
"CREATE EDGE IF NOT EXISTS like (likeness double);" | ||
) | ||
|
||
# prepare NebulaGraph Byte typed parameters | ||
|
||
bval = ttypes.Value() | ||
bval.set_bVal(True) | ||
ival = ttypes.Value() | ||
ival.set_iVal(3) | ||
sval = ttypes.Value() | ||
sval.set_sVal("Bob") | ||
|
||
params = {"p1": ival, "p2": bval, "p3": sval} | ||
|
||
|
||
# we could pass NebulaGraph Raw byte params like params, they will be evaluated in server side: | ||
resp = client.execute_parameter( | ||
"RETURN abs($p1)+3 AS col1, (toBoolean($p2) AND false) AS col2, toLower($p3)+1 AS col3", | ||
params, | ||
) | ||
|
||
# It may be not dev friendly to prepare i.e. a list of string typed params, actually NebulaGrap python client supports to pass premitive typed parms, too. | ||
|
||
params_premitive = { | ||
"p1": 3, | ||
"p2": True, | ||
"p3": "Bob", | ||
"p4": ["Bob", "Lily"], | ||
} | ||
|
||
resp = client.execute_py_params( | ||
"RETURN abs($p1)+3 AS col1, (toBoolean($p2) and false) AS col2, toLower($p3)+1 AS col3", | ||
params_premitive, | ||
) | ||
|
||
resp = client.execute_py_params( | ||
"MATCH (v) WHERE id(v) in $p4 RETURN id(v) AS vertex_id", | ||
params_premitive, | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.