LET block, $parent and $current

703 views
Skip to first unread message

Riccardo Tasso

unread,
Sep 4, 2013, 10:17:46 AM9/4/13
to orient-...@googlegroups.com
Hi, I'm trying to write a complex query, in the form:

SELECT @rid, $var FROM MainClass
LET $var = (SELECT FROM OtherClass WHERE ...)

For each element of MainClass, I should find a set of elements of OtherClass (e.g. otherField), filtered using the value of a field of MainClass (e.g. mainField).
Is it right that, inside a LET block, the $parent variable represents the current element of MainClass?
Is it right that, the $current variable represents the current element of OtherClass?

Thanks,
   Riccardo

Luca Garulli

unread,
Sep 4, 2013, 10:30:23 AM9/4/13
to orient-database
Hi,
$parent represent tha parent context, so if you want to get the parent record you've to use:

$parent.$current

The other assumption is correct.

Lvc@



--
 
---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Riccardo Tasso

unread,
Sep 4, 2013, 11:12:39 AM9/4/13
to orient-...@googlegroups.com
I have a problem.

SELECT flatten($var) FROM #14:0 LET $var = ( SELECT $current.otherField, $current.$parent.mainField FROM MainClass )

I expect this query returns a list of documents, each one with otherField and mainField, while mainField is never returned.

What's up?
Riccardo

Luca Garulli

unread,
Sep 4, 2013, 11:19:39 AM9/4/13
to orient-database
Hi,
try to use:

$parent.$current

instead of:

$current.$parent

Lvc@

Riccardo Tasso

unread,
Sep 8, 2013, 12:35:14 PM9/8/13
to orient-...@googlegroups.com

No way Luca,
   I tried each possible combination and it doesn't work... Can you suggest me a workaround?

Cheers,
   Riccardo

Luca Garulli

unread,
Sep 8, 2013, 12:59:02 PM9/8/13
to orient-database
Hi Riccardo,
try to put as result $parent.$current and see what is printed.

Lvc@

Riccardo Tasso

unread,
Sep 9, 2013, 2:47:30 AM9/9/13
to orient-...@googlegroups.com
Both those queries return a resultset whose size is equal to size of OtherClass (as expected), but without any field (except the negative @RID field):
SELECT flatten($var) FROM #14:0 LET $var = ( SELECT $parent.$current FROM OtherClass)
SELECT flatten($var) FROM #14:0 LET $var = ( SELECT $current.$parent FROM OtherClass)

Thanks,
   Riccardo


2013/9/8 Luca Garulli <l.ga...@gmail.com>

Luca Garulli

unread,
Sep 9, 2013, 9:21:30 AM9/9/13
to orient-database
Hi Riccardo,
can you expose your database somewhere (nuvolabase.com?) or provide us a script to reproduce it?

Lvc@

Riccardo Tasso

unread,
Sep 9, 2013, 11:25:29 AM9/9/13
to orient-...@googlegroups.com
Try with this script:

create database memory:temp admin admin memory graph

create class MyClass
insert into MyClass set myField = 1 # assigned to #11:0
insert into MyClass set myField = 2

create class OtherClass
insert into OtherClass set otherField = 11
insert into OtherClass set otherField = 22

select flatten($var) from #11:0 LET $var = (SELECT $current.$parent FROM OtherClass)

I hope it's enough.
Riccardo


2013/9/9 Luca Garulli <l.ga...@gmail.com>

Luca Garulli

unread,
Sep 9, 2013, 11:48:00 AM9/9/13
to orient-database
Hi Riccardo,
thanks for the test case! I found the bug: it was on setting of parent context on sub-queries executed in LET clause.

Fixed in "develop" and in few minutes online on sonatype as 1.6.0-SNAPSHOT.

Lvc@

Riccardo Tasso

unread,
Sep 10, 2013, 4:50:12 AM9/10/13
to orient-...@googlegroups.com
Any chance to have the fix also in 1.5 brach?

Cheers,
   Riccardo

Luca Garulli

unread,
Sep 10, 2013, 7:25:39 AM9/10/13
to orient-database
Hi Riccardo,
sorry but the 1.6 is planned in few days, so the 1.5.1 was last version of 1.5 branch.

Lvc@

Carlo Polisini

unread,
Nov 25, 2014, 7:11:53 AM11/25/14
to orient-...@googlegroups.com
My use case is exactly what described in this topic, at least in the first post, but I don't get expected results:

I have defined those two tables, and I am using Document DB on Orient 1.7.8:

Galaxy:
----+------+-----+-------------+--------
#   |@RID  |stars|name         |creator 
----+------+-----+-------------+--------
0   |#13:37|[2]  |milkyway     |zeus    
1   |#13:38|[1]  |coffeeway    |topolino
2   |#13:39|null |cappuccinoway|topolino

Star
----+------+-------+--------+---------
#   |@RID  |planets|name    |creator  
----+------+-------+--------+---------
0   |#15:37|[1]    |Centauri|zeus     
1   |#15:38|null   |Leone   |poseidone
2   |#15:39|null   |Orione  |poseidone

I want to simply select the galaxies that contains at least 1 star with the same creator, so I should get the record #13:37 or #15:37 if I select the child field.

I tried the following but I get 0 results:

select expand($var) from Galaxy LET $var = (SELECT from star where $parent.$current.creator = creator) 

or adding explicit $current in the subquery I get same result:

select expand($var) from Galaxy LET $var = (SELECT from star where $parent.$current.creator = $current.creator)


Another strange thing is that $parent.$current seems to references always the last record of the table:

select expand($var) from Galaxy LET $var = (SELECT expand($parent.$current) from star)

gives:

----+------+-------------+--------
#   |@RID  |name         |creator 
----+------+-------------+--------
0   |#13:39|cappuccinoway|topolino
1   |#13:39|cappuccinoway|topolino
2   |#13:39|cappuccinoway|topolino
3   |#13:39|cappuccinoway|topolino
4   |#13:39|cappuccinoway|topolino
5   |#13:39|cappuccinoway|topolino
6   |#13:39|cappuccinoway|topolino
7   |#13:39|cappuccinoway|topolino
8   |#13:39|cappuccinoway|topolino
----+------+-------------+--------


Any suggestions? To me this a very simple and basic, and I think I am missing some OrientDB syntax structure.

Marcel Pitch

unread,
Dec 17, 2014, 9:42:28 AM12/17/14
to orient-...@googlegroups.com
Hi Carlo,

I'm working on 2.0-M3 and I've exactly the same problem.

Did you fin a workaround for it ?


Marcel P.

Carlo Polisini

unread,
Dec 17, 2014, 9:59:16 AM12/17/14
to orient-...@googlegroups.com
Hi Marcel, 
unfortunately I havent found any solutions, I had to drop some features from the app since this bug...

My feeling is that devs are busy with new release of OrientDB 2.0, and in general that OrientDB works better if used in graph mode since you have bidirectional links between entities and querying data will be much easier.



--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/Xvvs2v4KBMs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Carlo Polisini

Marcel Pitch

unread,
Dec 17, 2014, 10:53:46 AM12/17/14
to orient-...@googlegroups.com
OK,
Thanks Carlo,

Sorry, I didn't precise but I'm working with graph DB and the result is the same.

A test can be easy done by executing this request :

SELECT @rid, $var FROM <VertexClass> LET $var = (SELECT FROM $parent.$current)

The @rid in $var are always the last record one...

Strange...

Or may be, I don't understand the way how to use $parent.$current...

I will ask...

Marcel Pitch

unread,
Dec 18, 2014, 4:53:36 AM12/18/14
to orient-...@googlegroups.com
Hi Carlo,

I've downloaded the latest 2.0-RC1 version this morning and that solves my problem.

Carlo Polisini

unread,
Dec 18, 2014, 4:56:24 AM12/18/14
to orient-...@googlegroups.com
That's very good!! Thanks for the feedback!

2014-12-18 10:53 GMT+01:00 Marcel Pitch <marcel...@gmail.com>:
Hi Carlo,

I've downloaded the latest 2.0-RC1 version this morning and that solves my problem.

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/Xvvs2v4KBMs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Carlo Polisini
Reply all
Reply to author
Forward
0 new messages