python可以实现对nebula数据库的批量写入与读取操作吗?

如题

可以定义一下批量么?

如果通过 GraphD client(就是接受 nGQL 的接口),单行写入指令本身就支持批量的,而且也可以通过 ; 发出多行的请求。

如果通过 StorageClient 可以扫点和边 https://github.com/vesoft-inc/nebula-python/blob/3f05be5cc395eea8c46e59cd79ffa23c7d63e346/example/ScanVertexEdgeExample.py#L58

1 个赞

您好,批量的定义其实就是多条的写入,用户在前端上传数据,并且用户在页面上定义TAG,EDGE,后台根据用户的定义,将TAG,EDGE映射到数据库中,再将用户上传的数据,导入到数据库中。因为数据是中文的,‘INSERT VERTEX player(name, age) VALUES “player100”:(“詹姆斯”, 42)’ ,这样插入的方式 是语法问题还是中文就是写不进去呢?

好滴,那可以在 python 上拼接一行多点比如,中文是没问题的:

(root@nebula) [basketballplayer]> insert vertex player(name,age) values "player1119":("张三", 30), "player1120":("李四", 30);
Execution succeeded (time spent 3353/40773 us)

❯ ipython
Python 3.9.7 (default, Oct 12 2021, 22:38:23)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from nebula2.gclient.net import ConnectionPool
   ...: from nebula2.Config import Config
   ...: # define a config
   ...: config = Config()
   ...: config.max_connection_pool_size = 10
   ...: # init connection pool
   ...: connection_pool = ConnectionPool()
   ...: # if the given servers are ok, return true, else return false
   ...: ok = connection_pool.init([('192.168.8.127', 9669)], config)

In [2]: session = connection_pool.get_session('root', 'nebula')
   ...:
   ...:
[2021-11-26 17:30:24,394]:Get connection to ('192.168.8.127', 9669)

In [3]: session.execute("""
   ...: USE basketballplayer;
   ...: insert vertex player(name,age) values "player1119":("张三", 30), "player1120":("李四", 30);
   ...: """)
Out[3]: ResultSet(None)

In [4]: test = session.execute("""
   ...: USE basketballplayer;
   ...: insert vertex player(name,age) values "player1119":("张三", 30), "player1120":("李四", 30);
   ...: """)

In [5]: test.is_succeeded()
Out[5]: True

1 个赞

太感谢您了!非常感谢!像TAG EDGE 这定义的时候必须是英文的包括其对应属性的定义例如name,age? 第二个问题就是,从数据库中导出数据,也可以实现批量式的吗?

您客气,的确,TAG 名字还不支持 UTF-8,如果您强烈需要可以来 github issue 上表达您的意愿哈,这会影响社区 roadmap 的优先级哦

https://github.com/vesoft-inc/nebula/issues/2120

好的,马上去

1 个赞

此话题已在最后回复的 7 天后被自动关闭。不再允许新回复。