RedisGraph / redisgraph-py

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

Properties conversion in the Redis-set response #42

Closed Guttz closed 5 years ago

Guttz commented 5 years ago

When converting the properties with the new redis-set format, I'm getting properties strings with the byte annotation inside the dict keys and values instead of decoded.

image

Investigating a bit I found(query_result.py : 125): image

Is this the expected or should the above be value.decode() instead of casting to string?

Guttz commented 5 years ago

Also, in the second property above, the value of "operations" has both" and'switched which makes a bit harder to use some string manipulation.

swilly22 commented 5 years ago

Hi @Guttz, When setting up your Redis connection try specifying: r=Redis(decode_responses=True)

Please let me know if that helped.

Guttz commented 5 years ago

Hey @swilly22, it would make sense for that to solve the problem. However, when doing that the following happens:

  File "/home/guttz/Documents/hydraeco/hydra-python-agent/venv/lib/python3.6/site-packages/redisgraph/query_result.py", line 57, in _get_value
    stat = stat.decode()
AttributeError: 'str' object has no attribute 'decode'

That happens because all statistics come as str already. Did a quick fix to see if that's the only problem:

image

With that, no error is thrown but the result-set conversion somehow fails and I get and unparsed result_set as the img:

image

jeffreylovitz commented 5 years ago

Hi @Guttz,

It looks like the redisgraph-py package installed in your 3.6 environment is an older version, which won't properly handle the new result format. (The error reported on line 57 refers to code that was replaced in #28).

Can you try replacing the older package with one built from source? From the redisgraph-py root, this will require some command like pip install --user .

If this doesn't resolve the issue, it would be great if you could provide a code snippet to reproduce the issue!

Guttz commented 5 years ago

Hey @jeffreylovitz, you're right. I forgot to rebuild after checking out the branch to test @swilly22's solution. With his suggestion, it's working now. Thanks!

One last question, when running"MATCH(p) RETURN p.members", for example, I will not get a result_set:

{"members" : "a,b,c.."}

Instead, I get straight up the string with the value

"a,b,c.."

So, every time I query for properties, and not nodes, I should expect the return with no dict in the response, right?

jeffreylovitz commented 5 years ago

@Guttz Awesome, glad that worked!

Any query that returns values produces a result set, which is essentially a table that has columns, in order, corresponding to the entities or properties specified in your RETURN clause. A query like: "MATCH ()-[e]->(p) RETURN e, p.members" Will have the relationship e at at the first offset into the result set and the scalar value corresponding to the members property at the second.

The Python client performs a fair bit of local caching on things like property keys to reduce the package size for returning full nodes or relationships, but in general I would expect returning scalar values to be more performant when possible.

Guttz commented 5 years ago

Oh, I understand better now. Thanks a lot for the clarifications @jeffreylovitz.

The issue was solved, I'll keep an eye for updates and the 2.0 release.