Skip to content

Different behavior of SQL statement when used within SQL function #8286

@mollox

Description

@mollox

OrientDB Version: 3.0.1 (official docker image)

Expected behavior

We ware trying to retrieve out vertices of a hierarchical structure in two different ways:
Via traverse, where all traversed vertices appear only once.
But we also need to retrieve them multiple times if they have multiple in edges (for counting in some scenarios). For that way we use the MATCH syntax.
Now when creating SQL functions with these statements, we expect the same result of the functions as when we execute the statements directly.

Actual behavior

Actually, when creating a SQL function with a MATCH statement, the function behaves like a traverse, but when executed directly, the multiple linked vertices appear multiple times.

Steps to reproduce

Simple data creation for reproducing:

CREATE CLASS C EXTENDS V
CREATE PROPERTY C.ID INTEGER

CREATE CLASS C_C EXTENDS E

INSERT INTO C (ID) VALUES (1)
INSERT INTO C (ID) VALUES (2)
INSERT INTO C (ID) VALUES (3)
INSERT INTO C (ID) VALUES (4)

CREATE EDGE C_C FROM (SELECT FROM C WHERE ID = 1) TO (SELECT FROM C WHERE ID = 2)
CREATE EDGE C_C FROM (SELECT FROM C WHERE ID = 1) TO (SELECT FROM C WHERE ID = 3)
CREATE EDGE C_C FROM (SELECT FROM C WHERE ID = 2) TO (SELECT FROM C WHERE ID = 4)
CREATE EDGE C_C FROM (SELECT FROM C WHERE ID = 3) TO (SELECT FROM C WHERE ID = 4)

Calculating vertices where they should only appear once (works, getting all 4 vertices):

TRAVERSE out() FROM (SELECT FROM C WHERE ID = 1)

Calculating vertex where they should appear multiple times (works when directly executed, getting vertice with ID 4 two times):

MATCH {class: C, where: (ID = 1)}.out(){as: result, while: (true)} RETURN result

Calculating vertices where they should appear multiple times from a function (does not work as expected, getting vertex with ID 4 only once, like traverse):

CREATE FUNCTION test "MATCH {class: C, where: (ID = 1)}.out(){as: result, while: (true)} RETURN result" LANGUAGE SQL

SELECT test()

Can be reproduced from console or within OrientDB Studio.

Metadata

Metadata

Labels

buglegacy not used anymore

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions