Describe the bug
The logical operator || in rejson is currently broken that if one of the conditions ored together returns no data the results from other predicates are all ignored and the result is set to empty.
To reproduce
>>> import json
>>> from redis import asyncio as aioredis
>>> redis = aioredis.from_url("redis://some-url", encoding="utf-8", decode_responses=True)
>>> payload = [
{"first": "Joe", "nickname": "Master", "last": "Weider"},
{"first": "Arnold", "nickname": "Arnie", "last": "Schwarzenegger"},
{"first": "Dorian", "nickname": "The Shadow", "last": "Yates"},
{"first": "Lee", "nickname": "", "last": "Haney"},
{"first": "Phil", "middle": "Gift", "last": "Heath"},
]
>>> await redis.execute_command('json.set', "names", '$', json.dumps(payload))`
The line below works as expected
>>> json.loads(await redis.execute_command('json.get', 'names', ('$.*[?((@.first == "Joe" && @.last == "Weider")||(@.first == "Dorian" && @.last == "Yates"))]')))
[{'first': 'Joe', 'nickname': 'Master', 'last': 'Weider'}, {'first': 'Dorian', 'nickname': 'The Shadow', 'last': 'Yates'}]
Whereas replacing "Yates" with "Gray" does not and return []
>>> json.loads(await redis.execute_command('json.get', 'names', ('$.*[?((@.first == "Joe" && @.last == "Weider")||(@.first == "Dorian" && @.last == "Gray"))]')))
[]
Expected behavior
We expect to return one record for "Joe Weider"
>>> json.loads(await redis.execute_command('json.get', 'names', ('$.*[?((@.first == "Joe" && @.last == "Weider")||(@.first == "Dorian" && @.last == "Gray"))]')))
[{'first': 'Joe', 'nickname': 'Master', 'last': 'Weider'}]
Additional information
It appears that the or operator || nullifies the entire result when one record fails to meet the predicate, which is not correct. The expected behavior is to get the remaining records where the predicates have matched.
Comment From: oranagra
please open in https://github.com/RedisJSON/RedisJSON