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

size() method returns different result from inside of IF() statement #8263

Closed
v1nsai opened this issue May 14, 2018 · 4 comments
Closed

size() method returns different result from inside of IF() statement #8263

v1nsai opened this issue May 14, 2018 · 4 comments
Assignees
Labels
Milestone

Comments

@v1nsai
Copy link

v1nsai commented May 14, 2018

I opened a StackOverflow ticket on this recently but I believe it is actually a bug.

OrientDB Version: 3.0.0

Java Version: 1.8.0_171

OS: Ubuntu 16.04

Expected behavior

$3.size() should be greater than 0 for both of the following scripts

LET $1 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='hildigrimTook';
LET $2 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='adalgrimTook';
LET $3 = SELECT INTERSECT($1, $2).size();
LET $4 = CREATE EDGE Begets FROM (SELECT FROM Creature WHERE uniquename='hildigrimTook') TO (SELECT FROM Creature WHERE uniquename='adalgrimTook');
SELECT $3.size();
LET $1 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='hildigrimTook';
LET $2 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='adalgrimTook';
LET $3 = SELECT INTERSECT($1, $2).size();
LET $4 = CREATE EDGE Begets FROM (SELECT FROM Creature WHERE uniquename='hildigrimTook') TO (SELECT FROM Creature WHERE uniquename='adalgrimTook');
IF($3.size() > 0 {
    return 'Edge already exists'
}
IF($3.size() == 0 {
    return $4;
}

Actual behavior

Calling $3.size() is 0 when called from inside of an IF() statement, but > 0 when called from a SELECT, so $4 is called every time and creates duplicate edges.

Steps to reproduce

The following creates a duplicate edge instead of correctly reading $3.size() and returning 'Edge already exists'.

LET $1 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='hildigrimTook';
LET $2 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='adalgrimTook';
LET $3 = SELECT INTERSECT($1, $2).size();
LET $4 = CREATE EDGE Begets FROM (SELECT FROM Creature WHERE uniquename='hildigrimTook') TO (SELECT FROM Creature WHERE uniquename='adalgrimTook');
IF($3.size() > 0 {
    return 'Edge already exists'
}
IF($3.size() == 0 {
    return $4;
}
@luigidellaquila
Copy link
Member

Hi @v1nsai

Thank you very much for reporting, I'm working on this now

Thanks

Luigi

@luigidellaquila
Copy link
Member

Hi @v1nsai

I pushed a fix to develop branch, the new snapshot is already available.

Just please consider that the LET statements are evaluated early, so in your case the edge is created anyway.
What you probably need is something as follows:

LET $1 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='hildigrimTook';
LET $2 = SELECT expand(bothE(Begets)) FROM Creature WHERE uniquename='adalgrimTook';
LET $3 = SELECT INTERSECT($1, $2).size();
uniquename='hildigrimTook') TO (SELECT FROM Creature WHERE uniquename='adalgrimTook');
IF($3.size() > 0 {
    return 'Edge already exists'
}
IF($3.size() == 0 {
    LET $4 = CREATE EDGE Begets FROM (SELECT FROM Creature WHERE 
    return $4;
}

Thanks

Luigi

@luigidellaquila
Copy link
Member

@v1nsai
Copy link
Author

v1nsai commented May 16, 2018

Thanks for the code fix, that really helped! I actually was calling $3.INTERSECT.size() just in case anyone from Google happens upon this.

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

2 participants