Skip to content

Exception: redisgraph.query_result.QueryResult.pretty_print #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andreaBelmont opened this issue Jun 10, 2019 · 6 comments
Closed

Exception: redisgraph.query_result.QueryResult.pretty_print #41

andreaBelmont opened this issue Jun 10, 2019 · 6 comments
Labels

Comments

@andreaBelmont
Copy link

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
Copy link
Contributor

Please see my answer to #40

@andreaBelmont
Copy link
Author

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
Copy link
Author

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
Copy link
Contributor

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

@andreaBelmont
Copy link
Author

andreaBelmont commented Jun 10, 2019

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants