0
votes

I'm currently working on orientdb, and I'm having a hard time how to merge to rows or a two result. I just want to merge the two vertex in an edge, i tried unionall but it doesn't work in my side, please help me.

I already used unionall, unwind, and bothV() but not working.

person and company is a vertex
is_working is an edge(from(person), to(company))
i want to merge the result of the two vertices
ex. select expand(bothV()) from is_working where in = '13:3'
i just want to get all users that is working on the specific company.
expected result:
{name: "Randolf", gender: "Male", company_name:"Name of the company"},
{name: "Jefferson", gender: "Male", company_name:"Name of the company"}

I already tried the code below
select person, company.* from (select person, in('is_working') as company from(select expand(out('is_working')) from #13:2) unwind company)

select expand($all) let
@a = (select expand(in('is_working') from company where @rid = '13:2'),
@b = (select expand(in('is_working').out('is_working')) from company where @rid = '13:2'),
@all = unionall(@a, @b)

Nothing error but it doesn't show any result. when i tried
"select expand(bothV()) from is_working where in = '13:3'"
there is a result but it's not merge.
by the way the 13:2 and 13:3 is the RID of my company

1

1 Answers

0
votes

Assuming (for simplicity, anything carried out in the active-orient console)

> V.create_class :company, :person
# INFO->CREATE CLASS company EXTENDS V
# INFO->CREATE CLASS person EXTENDS V
 => [Company, Person] 
> E.create_class :is_working
# INFO->CREATE CLASS is_working EXTENDS E
 => IS_WORKING 
> c = Company.create name: 'C'
# INFO->CREATE VERTEX company set name = 'C'
> c.assign via: IS_WORKING, vertex: Person.create( name: 'A')
# INFO->CREATE VERTEX person set name = 'A'
# INFO->CREATE EDGE is_working from #41:0 to #49:0 
> Person.create( name: 'B').assign( via: IS_WORKING, vertex: c)
# INFO->CREATE VERTEX person set name = 'B'
# INFO->CREATE EDGE is_working from #50:0 to #41:0 

you got (active-orient specific)

 c.edges.to_human
 => ["<IS_WORKING[#58:0] :.: 50:0->{  }->41:0>", "<IS_WORKING[#57:0] :.: 41:0->{  }->49:0>"] 

which is basically our setup, i guess

Then

 > c.nodes( :out, via: IS_WORKING).to_human
 # INFO->select  outE('is_working').in  from #41:0 
 => ["<Person[49:0]: in: {IS_WORKING=>1}, name : A>"] 
 > c.nodes( :in, via: IS_WORKING).to_human
 # INFO->select  inE('is_working').out  from #41:0 
 => ["<Person[50:0]: out: {IS_WORKING=>1}, name : B>"] 
 > c.nodes( :both, via: IS_WORKING).to_human
 # INFO->select  both('is_working')  from #41:0 
 => ["<Person[49:0]: in: {IS_WORKING=>1}, name : A>", 
     "<Person[50:0]: out: {IS_WORKING=>1}, name : B>"] 

I guess, the last query covers your case

The expanded version:

> t.nodes( :both, via: IS_WORKING, expand: true)
# INFO->select  expand (  both('is_working')  ) from #41:0