RedisGraph / redisgraph-py

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

Persisting numerical data issue #21

Closed tomas-wood closed 5 years ago

tomas-wood commented 5 years ago

Running

from redisgraph import Graph, Node, Edge
import redis

r = redis.Redis(host='localhost', port=6379)
redis_graph = Graph("tester", r)

node = Node(label="node", properties={repr(0): repr(0.999)})
redis_graph.add_node(node)
redis_graph.commit()

raises this error.

---------------------------------------------------------------------------
ResponseError                             Traceback (most recent call last)
<ipython-input-59-64b5fab620d5> in <module>()
----> 1 redis_graph.commit()

/home/thomas/code/redisgraph-py/redisgraph/client.pyc in commit(self)
    134             query = query[:-1]
    135
--> 136         return self.query(query)
    137
    138     def query(self, q):

/home/thomas/code/redisgraph-py/redisgraph/client.pyc in query(self, q)
    142         statistics = None
    143         result_set = None
--> 144         response = self.redis_con.execute_command("GRAPH.QUERY", self.name, q)
    145
    146         result_set = response[0]

/home/thomas/.local/lib/python2.7/site-packages/redis/client.pyc in execute_command(self, *args, **options)
    753         try:
    754             connection.send_command(*args)
--> 755             return self.parse_response(connection, command_name, **options)
    756         except (ConnectionError, TimeoutError) as e:
    757             connection.disconnect()

/home/thomas/.local/lib/python2.7/site-packages/redis/client.pyc in parse_response(self, connection, command_name, **options)
    766         "Parses a response from the Redis server"
    767         try:
--> 768             response = connection.read_response()
    769         except ResponseError:
    770             if EMPTY_RESPONSE in options:

/home/thomas/.local/lib/python2.7/site-packages/redis/connection.pyc in read_response(self)
    636             raise e
    637         if isinstance(response, ResponseError):
--> 638             raise response
    639         return response
    640
ResponseError: Syntax error at offset 26 near '0'

redis-cli monitor shows:

root@169dfff796c7:/data# redis-cli monitor
OK
1545136430.786817 [0 172.17.0.1:39970] "GRAPH.QUERY" "social" "CREATE (gntugkruwj:node{0:\"0.999\"})"
swilly22 commented 5 years ago

Hi @huawei-tomas, When specifying node attributes, attribute name in this case 0 should be an unquoted string which starts with a character from the set: [_A-Za-z].

tomas-wood commented 5 years ago

Okay that helped, but now I'm getting an error whenever the value (not the key) representation is in scientific notation.

Traceback (most recent call last):
  File "adjacency.py", line 82, in <module>
    main()
  File "adjacency.py", line 73, in main
    redis_graph = generate_random_graph()
  File "adjacency.py", line 49, in generate_random_graph
    redis_graph.commit()
  File "/home/thomas/code/redisgraph-py/redisgraph/client.py", line 136, in commit
    return self.query(query)
  File "/home/thomas/code/redisgraph-py/redisgraph/client.py", line 144, in query
    response = self.redis_con.execute_command("GRAPH.QUERY", self.name, q)
  File "/home/thomas/.local/lib/python2.7/site-packages/redis/client.py", line 755, in execute_command
    return self.parse_response(connection, command_name, **options)
  File "/home/thomas/.local/lib/python2.7/site-packages/redis/client.py", line 768, in parse_response
    response = connection.read_response()
  File "/home/thomas/.local/lib/python2.7/site-packages/redis/connection.py", line 638, in read_response
    raise response
redis.exceptions.ResponseError: Syntax error at offset 1804838 near 'e-05'

Is there a reason scientific notation inside strings seems to be disallowed?

swilly22 commented 5 years ago

@huawei-tomas Indeed scientific notation should be supported, Currently we can only handle numerics which follow these patterns:

[0-9]*.[0-9]+ [0-9]+

We'll have to extend our grammar to accommodate scientific notation. Would you mind moving this Issue over to RedisGraph repository

Thank you!

tomas-wood commented 5 years ago

Will do thanks!