UNWIND - templated queries

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 to solve this problem efficiently? Thanks.

1 Like