FETCHPLAN - How to LINK / LINKSET when pointing to same record ?

201 views
Skip to first unread message

Gaurav Dhiman

unread,
Apr 19, 2014, 5:36:12 AM4/19/14
to orient-...@googlegroups.com
How to fetch all related records (LINK / LINKSET) in a case if two or more links point to same record ?

Example:
Lets say the class (A) have links createByUser, modifiedByUser and allUsers pointing to same record (#10:3) of OUser class.

If we specify FETCHPLAN ("*:-1") to fetch deep level records, only one link is expanded (allUsers), rest other two (createByUser, modifiedByUser) are not expanded. The reason for this is that all three link points to same OUser record.

SELECT FROM A FETCHPLAN *:-1

Query:
In above case, how to expand all three links even if they are pointing to same record ?

Regards,
Gaurav

Luca Garulli

unread,
Apr 20, 2014, 4:48:36 AM4/20/14
to orient-database
Hi Gaurav,
this is to avoid cyclic references. Think to the case you've the same RID in your graph: it would be recursively infinite. But in your case could have sense to just always expand records even if already expanded.

AFAIK we don't have such setting on fetch-plan. May you create a new issue? It's very easy to implement it.

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/d/optout.

Gaurav Dhiman

unread,
Apr 20, 2014, 5:30:55 AM4/20/14
to orient-...@googlegroups.com

Hi Luca,

Thanks for response.

Yes I knew that its done to avoid cyclic reference else fetch will for in infinite loop.

My point is, this check for cyclic reference should only be applied if infinite depth (-1) is given in fetch plan. Also as you suggested, additional option to avoid cyclic check can also be given but that will be prone to user errors, if cyclic check is avoided in case of infinite depth.

I will create the feature request in bug system. Is thee some workaround for now. I am using 1.7rc1 version.

Regards,
Gaurav

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/KWF1qYr2yNk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.

Gaurav Dhiman

unread,
Apr 20, 2014, 5:36:22 AM4/20/14
to orient-...@googlegroups.com

Cyclic reference check should be avoided if the fetch plan do not have infinite depth (cases where depth is greater or equal to 0).

What you think ?

Regards,
Gaurav

Gaurav Dhiman

unread,
Apr 20, 2014, 2:18:29 PM4/20/14
to orient-...@googlegroups.com
Luca, here is the request in bug system:

If its not of much work, can it be added in next stable release ?

Regards,
Gaurav



On Sunday, April 20, 2014 3:06:22 PM UTC+5:30, Gaurav Dhiman wrote:

Cyclic reference check should be avoided if the fetch plan do not have infinite depth (cases where depth is greater or equal to 0).

What you think ?

Regards,
Gaurav

On Apr 20, 2014 3:00 PM, "Gaurav Dhiman" wrote:

Hi Luca,

Thanks for response.

Yes I knew that its done to avoid cyclic reference else fetch will for in infinite loop.

My point is, this check for cyclic reference should only be applied if infinite depth (-1) is given in fetch plan. Also as you suggested, additional option to avoid cyclic check can also be given but that will be prone to user errors, if cyclic check is avoided in case of infinite depth.

I will create the feature request in bug system. Is thee some workaround for now. I am using 1.7rc1 version.

Regards,
Gaurav

On Apr 20, 2014 2:19 PM, "Luca Garulli" wrote:
Hi Gaurav,
this is to avoid cyclic references. Think to the case you've the same RID in your graph: it would be recursively infinite. But in your case could have sense to just always expand records even if already expanded.

AFAIK we don't have such setting on fetch-plan. May you create a new issue? It's very easy to implement it.

Lvc@

On 19 April 2014 11:36, Gaurav Dhiman wrote:
How to fetch all related records (LINK / LINKSET) in a case if two or more links point to same record ?

Example:
Lets say the class (A) have links createByUser, modifiedByUser and allUsers pointing to same record (#10:3) of OUser class.

If we specify FETCHPLAN ("*:-1") to fetch deep level records, only one link is expanded (allUsers), rest other two (createByUser, modifiedByUser) are not expanded. The reason for this is that all three link points to same OUser record.

SELECT FROM A FETCHPLAN *:-1

Query:
In above case, how to expand all three links even if they are pointing to same record ?

Regards,
Gaurav

--

---
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-database+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

---
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/KWF1qYr2yNk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-database+unsubscribe@googlegroups.com.

Gaurav Dhiman

unread,
Apr 21, 2014, 8:39:37 AM4/21/14
to orient-...@googlegroups.com
Hi Luca,

I have filed a request on bug system, but till it comes in next release, is there any workaround for this.
I am using 1.7-rc1

I will appreciate, if you can let me know the work around to get things going.

Regards,
Gaurav

Luca Garulli

unread,
Apr 23, 2014, 10:06:03 AM4/23/14
to orient-database
Hi Guarav,
I'm sorry, but we've a roadmap and paying clients so we can't work on issues like this because are not critical. Even if you tweet for help every day :-)

You can do a workaround by parsing the returning JSON and put real objects by RID. We do this on OrientDB JS library.
Lvc@

Gaurav Dhiman

unread,
Apr 24, 2014, 9:39:24 AM4/24/14
to orient-...@googlegroups.com
Thanks Luca. I have no other option, but to catch you on Twitter, as you are sometimes missing from this group :-)

Your pointer worked. As you suggested, I am able to resolve it by parsing JSON and replacing RIDs with related objects.
Whenever time permits, you can add this small feature in OrientDB, that will be great.

Thanks again !

For reference of others, below is the code from OrientDB JS driver (https://github.com/orientechnologies/orientdb/blob/master/server/src/site/js/orientdb-api.js) which replaces RIDs with related objects to make the whole JSON complete:

ODatabase.prototype.parseConnections = function(obj) {
if (typeof obj == 'object') {
var linkMap = {
"foo" : 0
};
linkMap = this.createObjectsLinksMap(obj, linkMap);
if (linkMap["foo"] == 1) {
linkMap = this.putObjectInLinksMap(obj, linkMap);
if (linkMap["foo"] == 2) {
obj = this.getObjectFromLinksMap(obj, linkMap);
}
}
}
return obj;
}

ODatabase.prototype.createObjectsLinksMap = function(obj, linkMap) {
for ( var field in obj) {
if (!obj.hasOwnProperty(field)) {
continue;
}
var value = obj[field];
if (typeof value == 'object') {
this.createObjectsLinksMap(value, linkMap);
} else {
if (typeof value == 'string') {
if (value.length > 0 && value.charAt(0) == '#') {
if (!linkMap.hasOwnProperty(value)) {
linkMap["foo"] = 1;
linkMap[value] = null;
}
}
}
}
}
return linkMap;
}

ODatabase.prototype.putObjectInLinksMap = function(obj, linkMap) {
for ( var field in obj) {
if (!obj.hasOwnProperty(field)) {
continue;
}
var value = obj[field];
if (typeof value == 'object') {
this.putObjectInLinksMap(value, linkMap);
} else {
if (field == '@rid' && value.length > 0
&& linkMap.hasOwnProperty(value)
&& linkMap[value] === null) {
linkMap["foo"] = 2;
linkMap[value] = obj;
}
}
}
return linkMap;
}

ODatabase.prototype.getObjectFromLinksMap = function(obj, linkMap) {
for ( var field in obj) {
if (!obj.hasOwnProperty(field)) {
continue;
}
var value = obj[field];
if (typeof value == 'object') {
this.getObjectFromLinksMap(value, linkMap);
} else {
if (field != '@rid' && value.length > 0
&& value.charAt(0) == '#' && linkMap[value] != null) {
obj[field] = linkMap[value];
}
}
}
return obj;
}

Regards,
Gaurav

Jonathan Rosen

unread,
May 16, 2014, 2:41:06 PM5/16/14
to orient-...@googlegroups.com
I would like to second this request. It doesn't make sense to have a graph database, where you want to fetch data 1 or 2 levels deep, and have to recursively parse the json in order to do rid replacement on missing objects. This is broken functionality. In cases of self-referencing objects, there should be a "recursion limit". However, in the case of connected objects that don't contain links (i.e. strings), why aren't values always substituted?

For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';r
...
Reply all
Reply to author
Forward
0 new messages