I would like to execute a batch of queries in RedisGraph with the Python API in order to speed up the creation of big knowledge graphs.
In Neo4J, the UNWIND command can be used by the Neo4J Python API and allows to parallelize queries. In this snippet, you can seen how the Python API supports UNWIND – the run
method takes batch
as parameter. batch
is a list of dictionaries. Every dictionary has head_id
, tail_id
and properties
as keys.
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)
In RedisGraph, UNWIND is also available (as it is a Cypher command). However, I don’t know how to pass a batch in the 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!!
Do you know a solution? Thanks.
2
Answers
Here the answer from the RedisLabs dev team:
github.com/RedisGraph/RedisGraph/issues/1293
As of now, the feature is not supported, but will be introduced in the future.
The
redisgraph-py
README shows an example of how to pass parameters via itsquery()
method:If you really need to use
execute_command()
instead, you can take a look at howquery()
is implemented.