bitnine-oss / agensgraph

AgensGraph, a transactional graph database based on PostgreSQL
http://www.agensgraph.org
Other
1.33k stars 148 forks source link

Predicates functions want jsonb, not list #514

Open pebbe opened 4 years ago

pebbe commented 4 years ago

In the AgensGraph Developer Manual, there are some Predicates functions, that should work on lists.

But when I try to use these, I get an error, saying a jsonb was expected, while it got a list:

peter=# match p = (n1)-[r:rel*2]->(n2)
peter-# where all(x in r where x.id is null)
peter-# return count(p);
ERROR:  jsonb is expected but edge[]

When I convert the list to a jsonb, the error disappears, but I get zero results:

peter=# match p = (n1)-[r:rel*2]->(n2)
peter-# where all(x in to_jsonb(r) where x.id is null)
peter-# return count(p);
 count 
-------
 0

But that's wrong. There are matching patterns:

peter=# match p = (n1)-[r1:rel]->()-[r2:rel]->(n2)
peter-# where r1.id is null and r2.id is null
peter-# return count(p);
 count  
--------
 214868

So how do I use the functions all(), any(), none(), and single() ?

4j4y commented 3 years ago

Can you try this once?

match p = (n1)-[r:rel*2]->(n2)
where all(x in to_jsonb(r) where x.properties.id is null)
pebbe commented 3 years ago

Can you try this once?

match p = (n1)-[r:rel*2]->(n2)
where all(x in to_jsonb(r) where x.properties.id is null)

Yes, that works. Thanks.

j616 commented 3 years ago

I've just run into a similar thing with the form

WHERE ALL(
  r in relationships(p) WHERE ((type(r) = 'Contributes') OR (type(r) = 'Produces'))
)

using to_jsonb on the relationships clause makes in happy but then type is unhappy because jsonb can't be cast to edge.

4j4y commented 3 years ago

I agree agensgraph documentation is not that great. I am also struggling to figure out the connected component size in a undirected graph with the number of nodes as less as 15 and between any two nodes, there is a maximum of one edge guaranteed. I am applying a filter on edge property but it's taking too much time. More details in #522 .

@pebbe @j616 could you help me out here if you have come across this type of usecase.