RedisGraph / redisgraph-py

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

Exception: redisgraph.query_result.QueryResult.pretty_print #41

Closed andreaBelmont closed 5 years ago

andreaBelmont commented 5 years ago

Running this code:

import redis
import redisgraph
print(redis.__version__)
from redisgraph import Node, Edge, Graph
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)
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()

raises:

3.2.1
Traceback (most recent call last):
  File "./test.py", line 18, in <module>
    result.pretty_print()
  File "/Users/acortis/my_codes/testbed/PySyft/.env/lib/python3.7/site-packages/redisgraph/query_result.py", line 33, in pretty_print
    tbl.add_row(['No data returned.'])
  File "/Users/acortis/my_codes/testbed/PySyft/.env/lib/python3.7/site-packages/prettytable/prettytable.py", line 928, in add_row
    "Row has incorrect number of values, (actual) %d!=%d (expected)" % (len(row), len(self._field_names)))
Exception: Row has incorrect number of values, (actual) 1!=4 (expected)

I am running redisgraph from docker

docker run -p 6379:6379 -it --rm redislabs/redisgraph
1:C 10 Jun 2019 13:56:15.180 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 10 Jun 2019 13:56:15.180 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 10 Jun 2019 13:56:15.180 # Configuration loaded
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

1:M 10 Jun 2019 13:56:15.181 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 10 Jun 2019 13:56:15.181 # Server initialized
1:M 10 Jun 2019 13:56:15.181 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 10 Jun 2019 13:56:15.182 * <graph> Thread pool created, using 6 threads.
1:M 10 Jun 2019 13:56:15.182 * Module 'graph' loaded from /usr/lib/redis/modules/redisgraph.so
1:M 10 Jun 2019 13:56:15.182 * Ready to accept connections
swilly22 commented 5 years ago

Please see my answer to #40

andreaBelmont commented 5 years ago

mhmhm ... your answer to #40 did not solve the issue with the docker container. Now after installing the new redisgrap py I have this error:

Unknown column type.

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
~/my_codes/testbed/redisgraph/test.py in <module>
     13            RETURN p.name, p.age, v.purpose, c.name"""
     14
---> 15 result = redis_graph.query(query)
     16
     17 # Print resultset

~/my_codes/testbed/redisgraph/.env/lib/python3.7/site-packages/redisgraph/graph.py in query(self, q)
    111         result_set = None
    112         response = self.redis_con.execute_command("GRAPH.QUERY", self.name, q, "--compact")
--> 113         return QueryResult(self, response)
    114
    115     def _execution_plan_to_string(self, plan):

~/my_codes/testbed/redisgraph/.env/lib/python3.7/site-packages/redisgraph/query_result.py in __init__(self, graph, response)
     34             self.parse_statistics(response[0])
     35         else:
---> 36             self.parse_results(response)
     37             self.parse_statistics(response[-1]) # Last element.
     38

~/my_codes/testbed/redisgraph/.env/lib/python3.7/site-packages/redisgraph/query_result.py in parse_results(self, raw_result_set)
     44             return
     45
---> 46         self.result_set = self.parse_records(raw_result_set)
     47
     48     def parse_statistics(self, raw_statistics):

~/my_codes/testbed/redisgraph/.env/lib/python3.7/site-packages/redisgraph/query_result.py in parse_records(self, raw_result_set)
     66             record = []
     67             for idx, cell in enumerate(row):
---> 68                 if self.header[idx][0] == ResultSetColumnTypes.COLUMN_SCALAR:
     69                     record.append(self.parse_scalar(cell))
     70                 elif self.header[idx][0] == ResultSetColumnTypes.COLUMN_NODE:

IndexError: list index out of range
andreaBelmont commented 5 years ago

For your information, updating the docker image to Redis 5.0.5 (00000000/0) 64 bit does not have any efffect on the error

swilly22 commented 5 years ago

Please pull the edge version of RedisGraph from dockerhub docker run -p 6379:6379 -it --rm redislabs/redisgraph:edge

andreaBelmont commented 5 years ago

Still not quite there. This time the test file above does not raise any expections, however the result of pretty_print is not what is expected

In [2]: result.pretty_print()
internal execution time 0.431
swilly22 commented 5 years ago

the result-set is returning empty as the query is looking for a connection between a person and a country, but the graph been created doesn't contains any connections.

I've updated the test file:

import redis
import redisgraph
print(redis.__version__)
from redisgraph import Node, Edge, Graph
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()
python test.py
3.2.1
+----------+-------+-----------+--------+
|  p.name  | p.age | v.purpose | c.name |
+----------+-------+-----------+--------+
| John Doe |   33  |  pleasure | Japan  |
+----------+-------+-----------+--------+

internal execution time 0.2573