RedisGraph / redisgraph-py

RedisGraph python client
https://redisgraph.io
BSD 3-Clause "New" or "Revised" License
189 stars 49 forks source link

Cannot run a simple query. Need help! #51

Closed mingen-pan closed 5 years ago

mingen-pan commented 5 years ago

I am new to RedisGraph. My python version is 3.6.

I have a simple graph: (:Person {name: John}) --[:Work]-->(:Job {type: Software Engineer}).

I tried query at redis-cli, and it works fine and return

127.0.0.1:6379> GRAPH.Query Toy "Match (p) return p"
1) 1) "p"
2) 1) 1) 1) 1) "id"
            2) (integer) 0
         2) 1) "labels"
            2) 1) "Person"
         3) 1) "properties"
            2) 1) 1) "name"
                  2) "John"
   2) 1) 1) 1) "id"
            2) (integer) 1
         2) 1) "labels"
            2) 1) "Job"
         3) 1) "properties"
            2) 1) 1) "type"
                  2) "Software Engineer"
3) 1) "Query internal execution time: 0.507900 milliseconds"

However, when I tried this query at redisgraph-py, I got an error.

Here is my code,

import redis
from redisgraph import Node, Edge, Graph

r = redis.Redis(host='localhost', port=6379)
redis_graph = Graph('Toy', r)
query = 'Match (p) RETURN p'
result = redis_graph.query(query)
print(result)

The error stack is

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2066, in <module>
    main()
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2060, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1411, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1418, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/augustinpan/Documents/Columbia/FlyBrainLab/grapharcana/grapharcana/dialects/test.py", line 10, in <module>
    result = redis_graph.query(query)
  File "/Users/augustinpan/Documents/Columbia/FlyBrainLab/grapharcana/venv/lib/python3.6/site-packages/redisgraph/client.py", line 160, in query
    return QueryResult(result_set, statistics)
  File "/Users/augustinpan/Documents/Columbia/FlyBrainLab/grapharcana/venv/lib/python3.6/site-packages/redisgraph/query_result.py", line 17, in __init__
    self.parsed_statistics = self._retrieve_data_from_statistics(statistics)
  File "/Users/augustinpan/Documents/Columbia/FlyBrainLab/grapharcana/venv/lib/python3.6/site-packages/redisgraph/query_result.py", line 45, in _retrieve_data_from_statistics
    self.LABELS_ADDED: self._get_value(self.LABELS_ADDED, statistics),
  File "/Users/augustinpan/Documents/Columbia/FlyBrainLab/grapharcana/venv/lib/python3.6/site-packages/redisgraph/query_result.py", line 57, in _get_value
    stat = stat.decode()
AttributeError: 'list' object has no attribute 'decode'

My debugger shows the response from self.redis_con.execute_command("GRAPH.QUERY", self.name, q) like

<class 'list'>: [[b'p'], [[[[b'id', 0], [b'labels', [b'Person']], [b'properties', [[b'name', b'John']]]]], [[[b'id', 1], [b'labels', [b'Job']], [b'properties', [[b'type', b'Software Engineer']]]]]], [b'Query internal execution time: 0.298000 milliseconds']]
mingen-pan commented 5 years ago

I just realized pip install redisgraph will download version 1.7, which leads to this bug.

When I pip for the latest master branch, problem solved.