0
votes

I have some images stored in the default cluster in my OrientDB database. I stored them by implementing the code given by the documentation in the case of the use of multiple ORecordByte (for large content): http://orientdb.com/docs/2.1/Binary-Data.html

So, I have two types of object in my default cluster. Binary datas and ODocument whose field 'data' lists to the different record of binary datas.

Some of the ODocument records' RID are used in some other classes. But, the other records are orphanized and I would like to be able to retrieve them.

My idea was to use

select from cluster:default where @rid not in (select myField from MyClass)

But the problem is that I retrieve the other binary datas and I just want the record with the field 'data'.

In addition, I prefer to have a prettier request because I don't think the "not in" clause is really something that should be encouraged. Is there something like a JOIN which return records that are not joined to anything?

Can you help me please?

1
Could you post the schema of your class ? Could you try with "select data from cluster:persona where @rid not in (select mylink from X) and data IS NOT NULL" ? - Alessandro Rota
Hello. First, I am very sorry about the delay. Then, concerning my problem, I have a class Image with a field "content". This class Image contains some information like the file name. Its field "content" contains the RID of the "ODocument" stored in the default cluster. Like specified in the OrientDB documentation, this "ODocument" contains a field listing the different RID of the "binary" records containing the content of the file. My goal is to retrieve the list of those "ODocument" or "binary records" which are not linked to a record of the Image class or a record of the "ODocument". - tlegrand

1 Answers

0
votes

To resolve my problem, I did like that. However, I don't know if it is the right way (the more optimized one) to do it:

I used the following SQL request:

SELECT rid FROM (FIND REFERENCES (SELECT FROM CLUSTER:default)) WHERE referredBy = []

In Java, I execute it with the use of the couple OCommandSQL/OCommandRequest and I retrieve an OrientDynaElementIterable. I just iterate on this last one to retrieve an OrientVertex, contained in another OrientVertex, from where I retrieve the RID of the orpan.

Now, here is some code if it can help someone, assuming that you have an OrientGraphNoTx or an OrientGraph for the 'graph' variable :)

String cmd = "SELECT rid FROM (FIND REFERENCES (SELECT FROM CLUSTER:default)) WHERE referredBy = []";
List<String> orphanedRid = new ArrayList<String>();
OCommandRequest request = graph.command(new OCommandSQL(cmd));
OrientDynaElementIterable objects = request.execute();
Iterator<Object> iterator = objects.iterator();
while (iterator.hasNext()) {
    OrientVertex obj = (OrientVertex) iterator.next();
    OrientVertex orphan = obj.getProperty("rid");
    orphanedRid.add(orphan.getIdentity().toString());
}