EDIT : see at bottom for reproduce the problem on a smaller stat/schema set
I'm experimenting around OrientDB time-series use case and I'm trying to chain each levels of two trees. So I did this sql batch :
let $w1 = select expand(W1[2406]) from #12:2;
let $w2 = select expand(W1[2407]) from #12:2;
let $d1 = select expand(D1[4]) from $w1;
let $d2 = select expand(D1[0]) from $w2;
let $h1 = select expand(H1[23]) from $d1;
let $h2 = select expand(H1[0]) from $d2;
let $m1 = select expand(M1[59]) from $h1;
let $m2 = select expand(M1[0]) from $h2;
update $w1 set next = $w2;
update $w2 set previous = $w1;
update $d1 set next = $d2;
update $d2 set previous = $d1;
update $h1 set next = $h2;
update $h2 set previous = $h1;
update $m1 set next = $m2;
update $m2 set previous = $m1;
But I get this error on the first update:
The field 'W1.next' has been declared as LINK but the value is not a record or a record-id
...That I don't understand because when I try :
return [$w1, $w2, $d1, $d2, $h1, $h2, $m1, $m2];
I get the records as expected...
So two questions :
(Note : I would like to stay in sql/batch sql)
the classes are like this :
Symbol{
W1 : LINKMAP W1
}
W1 {
next : LINK W1
previous : LINK W1
D1 : LINKMAP D1
}
D1 {
next : LINK D2
previous : LINK D2
H1 : LINKMAP H1
}
H1 [...]
M1 [...]
EDIT : How to reproduce the problem on a smaller data set :
Schema creation :
create class A extends V;
create class B extends V;
create property A.B LINKMAP B;
create property B.B LINK B;
note : A.B is an array-like of B elements, B.B is a 1to1 link
dummy values to insert :
insert into B CONTENT {}
insert into B CONTENT {}
now, get the rids of the two dummies to insert into A
select from B
now insert as follow the two items (#13:0
and #13:1
in my case)
insert into A(B) values ({'0' : #13:0, '1' : #13:1})
insert into A(B) values ({'0' : #13:0, '1' : #13:1})
Finally, try this batch :
let $b1 = select expand(B[0]) from A;
let $b2 = select expand(B[1]) from A;
update $b1 SET B = $b2;
update $b2 SET B = $b1;
you see the error
The field 'B.B' has been declared as LINK but the value is not a record or a record-id
but if you do that :
let $b1 = select expand(B[0]) from A;
let $b2 = select expand(B[1]) from A;
return $b1;
and
let $b1 = select expand(B[0]) from A;
let $b2 = select expand(B[1]) from A;
return $b2;
and
let $b1 = select expand(B[0]) from A;
let $b2 = select expand(B[1]) from A;
return {'b1': $b1, 'b2' : $b2};
you can see that they are not collections, but really records
EDIT2 The solution provided by Isavio works, but I would like to know why it does since in the previous results, they doesn't seem to be collection?
let $b1 = select expand(B[0]) from A;
let $b2 = select expand(B[1]) from A;
update $b1 SET B = $b2[0];
update $b2 SET B = $b1[0];
Could be possible that the result of update is a collection of records? Can you try using:
.....
update $w1 set next = $w2[0];
....
EDIT
I think using the LET will result always a collection.