Skip to content
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

Querying with "UNION" is causing a parsing issue when setting a column null in one clause. #90

Open
aleckushner opened this issue Sep 29, 2020 · 1 comment

Comments

@aleckushner
Copy link

To summarize, if a union is desired where one column is null for one of the query clauses, there does not seem to be a way to get the parser to work upon querying because it gets thrown off by the differing types and the parser's internal header only allowing one type.

To elaborate on the specific example experiencing this issue, there are nodes with labels "person" or "role". Relationships are "contains" and are either a role-node contains another role-node, or a role-node contains a person-node. In order to get all of the person-nodes contained by a certain role-node, we need

  1. all of the person-nodes directly contained by the role-node
  2. all person-nodes contained by role-nodes which are contained by the role-node (and so on with nesting).

Let's say the role for which we want all of the people in it has a property "code" which is "engineer" and let's say we want the role each member is directly in as well as the member.
The first part can be accomplished by this query:
MATCH (:role {code: "engineer"})-[:contains]->(member:person) return null AS child_role, member
The second part is similar and can be accomplished by this query:
MATCH (:role {code: "engineer"})-[:parent*]->(child_role:role)-[:contains]->(member:person) return child_role, member

The issue when running this query with a union is the parse fails. This seems to be because the null child_role and the node child_role are different types.

There is a work around something like the following to avoid the null which works.

MATCH (root_role:role {code: "engineer"})-[:contains]->(member:person) return root_role AS child_role, member
UNION
MATCH (:role {code: "engineer"})-[:parent*]->(child_role:role)-[:contains]->(member:person) return child_role, member

@swilly22
Copy link
Contributor

Testing on the current version of RedisGraph 2.2.8
I've ran the simplified query: RETURN null AS A, 3 AS B UNION RETURN 1 AS A, 2 AS B

Snippet:

import redis
from redisgraph import Graph

r = redis.Redis(host='localhost', port=6379)
redis_graph = Graph('g', r)
result = redis_graph.query("return null AS A, 3 AS B UNION RETURN 1 AS A, 2 AS B")
result.pretty_print()

And this is the result I got:

python ./union_test.py
+------+---+
|  A   | B |
+------+---+
| None | 3 |
|  1   | 2 |
+------+---+

Cached execution 0.0
internal execution time 0.3316

Is it possible that you're using an older version of RedisGraph or RedisGraph-py ?

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

No branches or pull requests

3 participants