Orientdb: SELECTING a set of RIDs in batch query no longer working in 3.x

Created on 15 Jun 2018  路  8Comments  路  Source: orientechnologies/orientdb

OrientDB Version: 3.0.2

Java Version: Java 8

OS: MacOS

Expected behavior

The following used to work in 2.x:

BEGIN;
INSERT INTO Test SET id="1", prop1 = "val_1", prop2 = "a";
INSERT INTO Test SET id="2", prop1 = "val_2", prop2 = "a";
INSERT INTO Test SET id="3", prop1 = "val_3", prop2 = "b";
INSERT INTO Test SET id="4", prop1 = "val_4", prop2 = "b";

LET x = SELECT @rid FROM Test WHERE prop2 = "a";
LET y = SELECT FROM $x;
COMMIT;
RETURN $y;

Actual behavior

This is not working in 3.x. The returned error is "Class not found: $x". The following style syntax still works:

SELECT FROM [#15:9, #15:10]

So selecting from a set of RID works. It seems that in 2.x in some form the first select in the batch returned something that could be selected or updated or deleted. Now it seems to return a set of OResultInternal objects. In 2.x it returned a set of ODocuments. It's possible that selecting from a variable is not supported now? Or it's possible that the set of OResults do not interact with subsequent SELECT or DELETE statements.

Is there a correct syntax for this in 3.x?

question

All 8 comments

I did notice that this seems to work:

BEGIN;
LET x = SELECT FROM (SELECT @rid FROM Test WHERE prop2 = "a");
COMMIT;
RETURN $x;

So in part the issue seems to be when the result of the first select is put into a variable, not the general approach of selecting from a previously selected result set.

Hi @mmacfadden

The problem here is that $x is a normal identifier in v 3.0, so the executor treats it as a class name.

You can make it work with a small change in the syntax though:

LET y = SELECT expand($x);

Thanks

Luigi

Thanks for the TIP @luigidellaquila . This does solve one of our problems, but here is another more complicated version:

BEGIN;
LET models = SELECT @rid as rid FROM index:Model.id WHERE key = :modelId;
LET model = $models[0].rid;
LET dvs = SELECT @rid as rid FROM DataValue WHERE id =:id AND model = $model;
LET dv = $dvs[0].rid;
LET childrenToDelete = SELECT expand(children) FROM $dv;
DELETE FROM (TRAVERSE children FROM $childrenToDelete);
UPDATE $dv SET children = [];
COMMIT;

In this case the interesting part is

LET childrenToDelete = SELECT expand(children) FROM $dv;

There is probably a simpler way to do much of this. But the main point is that we are trying to select a projection from a set (or single) RID. I don't see a way to use the syntax you provided to achieve this. I think I made my original example to simple. I was trying to show the simplest form of the problem I was having.

Doing something like this does not work:

LET childrenToDelete = SELECT expand(children) FROM expand($dv);

This returns "function call as target is not supported yet". As does the updated if it is modified along the lines of your suggestion:

UPDATE expand($dv) SET children = [];

Hi @mmacfadden

I don't know if I got it right, but probably this will do the trick:

LET childrenToDelete = SELECT expand($dv.children) 

Thanks

Luigi

@luigidellaquila I think that might work for the SELECT statement. I am not sure what to do about the UPDATE versions though:

UPDATE $dv SET children = [];

P.S. I am really liking 3.x so far!

Try this ;-)

UPDATE (SELECT expand($dv) SET children = []);

Thanks

Luigi

Sorry

UPDATE (SELECT expand($dv)) SET children = [];

@luigidellaquila This worked! I did a little clean up and this syntax also worked:

DELETE FROM (SELECT expand($variable));

Thanks for the excellent community support!

Was this page helpful?
0 / 5 - 0 ratings