Parameters Issue

Hello,

I am not sure I fully understand how parameters can be provided using JSON, but I have encountered an issue I can’t solve. Using python and the python RedisGraph module:
redisgraph

This is an exact paste from the example given:

import redis
from redisgraph import Node, Edge, Graph, Path

r = redis.Redis(host='localhost', port=6379)

redis_graph = Graph('social', r)

john = Node(label='person', properties={'name': 'John Doe', 'age': 33, 'gender': 'male', 'status': 'single'})
redis_graph.add_node(john)

japan = Node(label='country', properties={'name': 'Japan'})
redis_graph.add_node(japan)

edge = Edge(john, 'visited', japan, properties={'purpose': 'pleasure'})
redis_graph.add_edge(edge)

redis_graph.commit()

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

result = redis_graph.query(query)

# Print resultset
result.pretty_print()

# Use parameters
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)

# Print resultset
result.pretty_print()

Focus is on:

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)

Works fine for me, but when I try to run this slightly modified code:

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

result = redis_graph.query(query, params)

It trows and error:

---------------------------------------------------------------------------
ResponseError                             Traceback (most recent call last)
<ipython-input-44-eafe4fde3be8> in <module>
      4 		   RETURN p.name, p.age, v.purpose, c.name"""
      5 
----> 6 result = redis_graph.query(query, params)
      7 
      8 # Print resultset

~\AppData\Local\Programs\Python\Python37-32\lib\site-packages\redisgraph\graph.py in query(self, q, params)
    128         result_set = None
    129 
--> 130         response = self.redis_con.execute_command("GRAPH.QUERY", self.name, q, "--compact")
    131         return QueryResult(self, response)
    132 

~\AppData\Local\Programs\Python\Python37-32\lib\site-packages\redis\client.py in execute_command(self, *args, **options)
    899         try:
    900             conn.send_command(*args)
--> 901             return self.parse_response(conn, command_name, **options)
    902         except (ConnectionError, TimeoutError) as e:
    903             conn.disconnect()

~\AppData\Local\Programs\Python\Python37-32\lib\site-packages\redis\client.py in parse_response(self, connection, command_name, **options)
    913         "Parses a response from the Redis server"
    914         try:
--> 915             response = connection.read_response()
    916         except ResponseError:
    917             if EMPTY_RESPONSE in options:

~\AppData\Local\Programs\Python\Python37-32\lib\site-packages\redis\connection.py in read_response(self)
    754 
    755         if isinstance(response, ResponseError):
--> 756             raise response
    757         return response
    758 

ResponseError: errMsg: Invalid input 'a': expected PROFILE line: 1, column: 2, offset: 1 errCtx: params={'purpose': 'pleasure'} MATCH (p:person)-[v:visited {$params}]->(c:cou... errCtxOffset: 1

Is this an unsupported use case or there is a bug in the module? As far as I understand its a normal use case in Cypher. I would idealy want to use it when setting properties with the SET clause.

The redisgraph-py client doesn’t accept full JSON as its parameter argument; it simply expects a dictionary of key-value parameter pairs.

Going through the Cypher Docs of Neo4j I see that there is the ability to use nested dictionaries, is that not supported in RedisGraph?

One of the examples in the docs:

### 2.6.5. Create node with properties

Parameters. 

{
  "props" : {
    "name" : "Andy",
    "position" : "Developer"
  }
}

Query. 

CREATE ($props)

Maps are not supported as a type (see https://oss.redislabs.com/redisgraph/cypher_support/#types), so AFAIK the answer is no.

After reading on maps in the Neo4j docs, I am not sure if this counts towards mappings though? It seems odd that they would implement a single level dictionaries but skip nested ones for parameter inputs.

Confirmed: The map data type, isn’t supported. This is a mapping case.

Maps are planned to be part of the next version 2.4.
You might want to follow issues on github.