RedisGraph - UNWIND 批量查询

RedisGraph - UNWIND batch of queries

我想用 Python API 在 RedisGraph 中执行一批查询,以加快大知识图谱的创建。

Neo4J 中,UNWIND 命令可以被 Neo4J Python API 使用并允许并行化查询。在此代码段中,您可以看到 Python API 如何支持 UNWIND - run 方法将 batch 作为参数。 batch 是字典列表。每个字典都有 head_idtail_idproperties 作为键。

with session.begin_transaction() as tx:  # In this transaction relationships are inserted in the database
    cypher_query = 'UNWIND $batch as row ' \
    'MATCH (head:Node) WHERE head.id = row.head_id ' \
    'MATCH (tail:Node) WHERE tail.id = row.tail_id ' \
    'CREATE (head)-[rel:RELATIONSHIP]->(tail) ' \
    'SET rel += row.properties'

     tx.run(cypher_query, batch=batch)

RedisGraph中,UNWIND也是可用的(因为它是一个Cypher命令)。但是,我不知道如何在 Python API:

中传递批处理
cypher_query = 'UNWIND $batch as row ' \
        'MATCH (head:Node) WHERE head.id = row.head_id ' \
        'MATCH (tail:Node) WHERE tail.id = row.tail_id ' \
        'CREATE (head)-[rel:RELATIONSHIP]->(tail) ' \
        'SET rel += row.properties'
r = redis.StrictRedis()
r.execute_command('GRAPH.QUERY', graph_name, cypher_query)  #No batch can be passed!!

你知道解决办法吗?谢谢。

redisgraph-py 自述文件显示 example 如何通过其 query() 方法传递参数:

...
params = {'purpose':"pleasure"}
query = """MATCH (p:person)-[v:visited {purpose:$purpose}]->(c:country)
     RETURN p.name, p.age, v.purpose, c.name"""

result = redis_graph.query(query, params)
...

如果确实需要用execute_command()代替,可以看看how query() is implemented

这里是 RedisLabs 开发团队的回答:

github.com/RedisGraph/RedisGraph/issues/1293

暂不支持该功能,后续会推出