Returning nodes and edges in a query

Hi,

Let us consider a demo schema mentioned as follows:
node1 -(edge1) -> node2
I want to return node1 edge1 and node2 using querying. Tried the following query:
start = {node1.*};
v = select s,e,n from start:s-(edge1:e)->node2:n;
print v
Error: extraneous input ‘from’ expecting {INTO, ‘,’}

Also I tried the following query:
start = {node1.*};
select s,e,n into v from start:s-(edge1:e)->node2:n;
print v;
No error but getting a null output.
Looking for a help to prepare the query, which works.

Thanks

I’m impressed the second one did anything at all.

OK, so edges live in a slightly different world to vertices. In my dreams we will resolve this dichotomy at some point, but there are practical ways we usually do this.

What you need is to stuff the edges into an accumulator, and print them seperately. We fixed up the print routine so you will get back all the attributes as well (unlike an accumulator of VERTEX).

so for your routine, and I’m coding blind, so please forgive any dumb errors:

SetAccum @@my_edges;
start = {node1.*};

v = select n from start:s-(edge1:e)->node2:n
accum
@@my_edges += e;

v = v UNION Start;

print v, @@my_edges;

Note I’m assuming all the Start vertices are intersting. If not, you’ll need to filter them first with something like:

Start = select v from Start:v where v.outdegree(“edge1”) > 0;

There are other ways of doing the same thing, but this is probably the most idiomatic.

SetAccum @@my_edges;
start = {node1.*};
v = select s,n from start:s-(edge1:e)->node2:n;
accum @@my_edges += e;
v = v UNION Start;
print v, @@my_edges;

(5, 17) Error: extraneous input ‘from’ expecting {INTO, ‘,’}
(6, 2) Error: mismatched input ‘accum’ expecting {ACCUM, GROUP, HAVING, LIMIT, ORDER, PER, POST_ACCUM, SAMPLE, WHERE, ‘[’, ‘;’}

I have one more question. How will we identify the source and destination nodes for edges ??

You’ve got an extra semicolon in there.

You can always store the source/destination vertices in different vertex sets e.g.:

v_destination = select n from start:s-(edge1:e)->node2:n
accum
@@my_edges += e;

v_start = select s from start:s-(edge1:e)->node2:n;

You wouldn’t need the filter then either.

(3, 2) Error: The accumulator type SetAccum must specify a data type.
The edges will contain different attributes of different datatype. what must be the datatype for my_edges accumulator ??

Did you try SetAccum<EDGE> @@my_edges; ?

1 Like

+1 for Mark’s suggestion.

1 Like

It works, thank you for the help

1 Like