age icon indicating copy to clipboard operation
age copied to clipboard

Support for PIPE operator for apache-age-python client

Open czesiu89 opened this issue 2 years ago • 17 comments

Currently we are running queries that require several Relationship (age.models.Edge) types to be filtered out. We tried to approach it with OPTIONAL MATCH but it didn't suite as too well, since it requires first statement to have matches to process with the other. Ended up with something like "MATCH ()-[r]-() WHERE r.type in ["type1", "type2"] RETURN r". In OpenCypher specs there is a mention about PIPE operator that facilitates such OR statements for relationship types and it goes like: "MATCH ()-[r:type1|type2]-() RETURN r. It feels a lot more natural to use. This one gives us "syntax error near |'.

Are there any plans to implement such operator or is it somehow limited?

czesiu89 avatar Apr 27 '23 08:04 czesiu89

Yes PIPE is cutoff. It is no more supported for specifying relationship types in single pattern.

But after checking some doc have you tried using WHERE clause with IN I think this might WORK like WHERE r.type IN ['type1', 'type2']

farakh-shahid avatar May 18 '23 06:05 farakh-shahid

@farakh-shahid That is exactly what @czesiu89 is saying he's using as workaround, indeed.

Is there any reason why PIPE is "no more supported"? Does it imply that Age is not implementing 100% OpenCypher? As I believe it's part of its grammar?

Thanks a lot!

cvanlabe avatar May 18 '23 22:05 cvanlabe

Hi @czesiu89 Any new updates on this? Can you share a bit more about your use-case? It'll help us prioritize.

eyab avatar Aug 22 '23 18:08 eyab

The PIPE operator is a feature of the Nebula Graph Query Language (nGQL) and is not part of OpenCypher. It allows multiple queries to be combined using pipe operators in nGQL. The PIPE operator applies to native nGQL only and is not compatible with OpenCypher

pawankukreja01 avatar Oct 15 '23 19:10 pawankukreja01

@cvanlabe -

@farakh-shahid That is exactly what @czesiu89 is saying he's using as workaround, indeed.

Is there any reason why PIPE is "no more supported"? Does it imply that Age is not implementing 100% OpenCypher? As I believe it's part of its grammar?

Thanks a lot!

Can you please show me where in the openCypher documentation it states the pipe operator was/is supported?

jrgemignani avatar Oct 16 '23 19:10 jrgemignani

@jrgemignani thanks for your response. As I mentioned, it’s visible in the grammar I linked to.

In the documentation, it’s described as early as page 10 in the opencypher reference:

” if we’d like to describe some data such that the relationship could have any one of a set of types, then they can all be listed in the pattern, separating them with the pipe symbol | like this:”

(a)-[r:TYPE1|TYPE2]->(b)

cvanlabe avatar Oct 16 '23 21:10 cvanlabe

I will bring this "oversight" up with the team and see if we can get it added. @rafsun42 @dehowef @muhammadshoaib

jrgemignani avatar Oct 16 '23 21:10 jrgemignani

Btw, the title for this issue is a bit misleading. This issue is for adding the OR operator | to the language for the edge match.

jrgemignani avatar Oct 16 '23 21:10 jrgemignani

@czesiu89 @cvanlabe The work on this operator is currently in progress. It would be useful if you let us know your data model and queries.

rafsun42 avatar Oct 16 '23 21:10 rafsun42

Thanks so much everyone! We can't immediately share our data model we use today. Assume it's a typical graph, which has several nodes connected to other nodes where each connection is a different relation type. Using the OR operator, we can decide which nodes we want to visualize given the used relationships.

I hope this helps.

cvanlabe avatar Oct 23 '23 14:10 cvanlabe

hi, i face a situation where the pipe-OR operator would be usefull, so as my situation is pretty simple i describe it here.

this is the query i tried, in which i want to match synonyms or hyperonyms of a word, and synonym/hyperonyms of synonym/hyperonyms, and synonym/hyperonyms of synonym/hyperonym of synonym/hyperonym of this word (including pattern like: synonym -> hyperonym -> synonym, and so on). so i need variable-length edges and the OR operator.

select * from cypher('graph_dict', $$
    match (s:word {graphic_form: 'know'})-[r:has_synonym|has_hyperonym|has_holonym *1..3]->(t:word)
    return s, t
$$) as (source agtype, target agtype);

with the solution proposed in the beginning of this discussion, it produces an error. this is what i've tried:

select * from cypher('graph_dict', $$
    match (s:word {graphic_form: 'know'})-[r]->(m:word)-[s *0..2]->(t:word)
    where label(r) in ['has_synonym', 'has_hyperonym', 'has_holonym']
    and label(s) in ['has_synonym', 'has_hyperonym', 'has_holonym']
    return l.id, t.graphie
$$) as (source agtype, target agtype);

the error is the following, and it seems that when the second edge is length 0, label() cannot be used (obviously).

ERROR: label() argument must resolve to a vertex or an edge.

my data structure is very simple: vertices are words (with a graphic_form and an id) and edges are relations between these words (has_synonym, has_antonym, has_hyperonym, ...).

thjbdvlt avatar Feb 06 '24 08:02 thjbdvlt

@thjbdvlt PR #1452 implements multiple label support. It has not been approved yet, but you can try it out.

rafsun42 avatar Feb 06 '24 21:02 rafsun42

@rafsun42 thank you! i am currently on PG15 so i cannot compile with it (PR 1452), but i'll try to upgrapde to PG16 soon so i can try it out, because it seems to be what i need! :)

thjbdvlt avatar Feb 07 '24 11:02 thjbdvlt

@thjbdvlt The PR 1452 is actually based on PG15. Do you get a compilation error?

rafsun42 avatar Feb 07 '24 16:02 rafsun42

@rafsun42 unfortunately: yes! but as i am really not a programmer, i have no doubts: it must be because of me not understanding something. anyway, i post a comment directly on the PR 1452 page with logs and description of what i have done, just in case it may help!

thjbdvlt avatar Feb 08 '24 11:02 thjbdvlt

This issue is stale because it has been open 45 days with no activity. Remove "Abondoned" label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 11 '24 00:05 github-actions[bot]

This issue is stale because it has been open 60 days with no activity. Remove "Abondoned" label or comment or this will be closed in 14 days.

github-actions[bot] avatar Jul 14 '24 00:07 github-actions[bot]