Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpredictable TRAVERSE results. #9101

Closed
mmacfadden opened this issue Jan 1, 2020 · 0 comments
Closed

Unpredictable TRAVERSE results. #9101

mmacfadden opened this issue Jan 1, 2020 · 0 comments
Assignees
Labels
Milestone

Comments

@mmacfadden
Copy link
Contributor

OrientDB Version: 3.0.26

Java Version: OpenJDK 11

OS:Linux

Expected behavior

Traversal of a property will only traverse that property

Actual behavior

Unpredictable traversal is happening.

Steps to reproduce

1. Create Classes

CREATE CLASS Model;
CREATE PROPERTY Model.id String;

CREATE CLASS DataValue;
CREATE PROPERTY DataValue.id String;

CREATE CLASS ObjectValue EXTENDS DataValue;
CREATE PROPERTY ObjectValue.children LINKMAP DataValue;

CREATE CLASS ArrayValue EXTENDS DataValue;
CREATE PROPERTY ArrayValue.children LINKLIST DataValue;

CREATE CLASS StringValue EXTENDS DataValue;
CREATE PROPERTY StringValue.value String;

CREATE PROPERTY DataValue.model LINK Model;
CREATE PROPERTY Model.data LINK ObjectValue;

2. Create Data

LET model = INSERT INTO Model SET id = "model";

LET objectString = INSERT INTO StringValue SET id="objectString", model=$model[0], value="objectString";
LET arrayString = INSERT INTO StringValue SET id="arrayString", model=$model[0], value="arrayString";

LET objectChild = INSERT INTO ObjectValue SET id="objectChild", model=$model[0], children={};
LET arrayChild = INSERT INTO ArrayValue SET id="arrayChild", model=$model[0], children=[];
LET stringChild = INSERT INTO StringValue SET id="stringChild", model=$model[0], value="stringChild";

LET root = INSERT INTO ObjectValue SET id="root", model=$model[0], children={};

UPDATE ObjectValue SET children.objectChild = $objectChild[0] WHERE id = "root";
UPDATE ObjectValue SET children.arrayChild = $arrayChild[0] WHERE id = "root";
UPDATE ObjectValue SET children.stringChild = $stringChild[0] WHERE id = "root";

UPDATE ObjectValue SET children.objectString = $objectString[0] WHERE id = "objectChild";

UPDATE ArrayValue SET children = [$arrayString[0]] WHERE id = "arrayChild";

UPDATE Model SET data = $root[0];

3. Inspect results

Step 1

Just SELECT the data.

SELECT FROM DataValue;

1-select_data_values

We see all of the DataValues properly created.

Step 2

Try to traverse all children from the root ObjectValue.

TRAVERSE children FROM (SELECT FROM DataValue WHERE id = "root");

2-traverse 'children' From Root

As mentioned in #9099, this will not traverse the root elements children LINKMAP.

Step 3

Try to traverse using children.values() from the root ObjectValue.

TRAVERSE children.values() FROM (SELECT FROM DataValue WHERE id = "root");

3-traverse_children_values_from_root

The traversal through the LINKMAP works. But there are two issues. First, why do we have the Model object in the traversal? It is not traversable via the children property. Also, the arrayString value which is a child of the arrayChild ArrayValue is missing.

Step 4

Since there seems to be something odd with the ArrayValue, try to traverse using children.values() from the arrayChild ArrayValue.

TRAVERSE children.values() FROM (SELECT FROM DataValue WHERE id = "arrayChild");

4_traverse_children_values_from_array

Here we directly see that the Model is coming from the traversal of the ArrayValue. And that the ArrayValue's children are not properly being traversed.

Step 5

Let's just verify that a traversal of the normal children properly will work from the arrayChild.

TRAVERSE children FROM (SELECT FROM DataValue WHERE id = "arrayChild");

5_traverse_children_from_array

The Model is gone and we do get the StringValue.

Step 6

Try traversing on both children and children.values() from the root;

TRAVERSE children, children.values() FROM (SELECT FROM DataValue WHERE id = "root");

6_traverse_children_and_values_from_root

Now we get all the values we WANT, but we are still incorrectly getting the Model.

Step 7

Use an additional SELECT to filter on the DataValue class.

SELECT FROM (TRAVERSE children, children.values() FROM (SELECT FROM DataValue WHERE id = "root")) WHERE @class INSTANCEOF "DataValue";

7_filter_traversal_on_datavalue_class

Now we finally get what we wanted.

4. Discussion

This seems a bit messy, and probably a bit inefficient. We have multiple projections, and an extra SELECT. Fixing #9099, may avoid this problem because we would not have to call .values() in the first place. But this still seems like a bug.

@tglman tglman added the bug label Jun 1, 2020
@tglman tglman added this to the 3.0.x milestone Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants