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

Gremlin ".count()" ignores ".has" queries with boolean properties #1674

Closed
docbacardi opened this issue Jul 26, 2024 · 3 comments
Closed

Gremlin ".count()" ignores ".has" queries with boolean properties #1674

docbacardi opened this issue Jul 26, 2024 · 3 comments
Assignees
Labels
bug Something isn't working fixed
Milestone

Comments

@docbacardi
Copy link
Contributor

ArcadeDB Version:

ArcadeDB Server v24.6.1 (build fbc1c77c7e1c52197abdd8661e5b34749babf3d6/1721708610769/main)

OS and JDK Version:

Running on Linux 6.5.0-45-generic - OpenJDK 64-Bit Server VM 17.0.11

Expected behavior

Counting vertices with a .has(...).count() query using a property with a boolean type should only include matching vertices in the result.

Actual behavior

The .has(...) part of the query is ignored and the total number of vertices is returned.

Steps to reproduce

All commands are executed in the console on a fresh download of the 24.6.1 build.

First a database is created, then a vertex of type A and a boolean property b:

> create database testdb

Database 'testdb' created
{testdb}> set language = sql

Set language to sql
{testdb}> CREATE VERTEX TYPE A;

+---------+------------------+
|NAME     |VALUE             |
+---------+------------------+
|operation|create vertex type|
|typeName |A                 |
+---------+------------------+
Command executed in 28ms
{testdb}> CREATE PROPERTY A.b BOOLEAN;

+------------+---------------+
|NAME        |VALUE          |
+------------+---------------+
|operation   |create property|
|typeName    |A              |
|propertyName|b              |
+------------+---------------+
Command executed in 11ms

Now 4 instances of A are created. 2 have b set to true, 1 has b set to false and 1 has no b property:

{testdb}> set language = gremlin

Set language to gremlin
{testdb}> g.addV('A').property('b', true);

VERTEX @type:A @rid:#1:0
+----+-----+
|NAME|VALUE|
+----+-----+
|b   |true |
+----+-----+
Command executed in 619ms
{testdb}> g.addV('A').property('b', true);

VERTEX @type:A @rid:#4:0
+----+-----+
|NAME|VALUE|
+----+-----+
|b   |true |
+----+-----+
Command executed in 4ms
{testdb}> g.addV('A').property('b', false);

VERTEX @type:A @rid:#7:0
+----+-----+
|NAME|VALUE|
+----+-----+
|b   |false|
+----+-----+
Command executed in 5ms
{testdb}> g.addV('A');

VERTEX @type:A @rid:#10:0
Command executed in 3ms
{testdb}> g.V().hasLabel('A')

+----+-----+-----+-----+
|#   |@RID |@TYPE|b    |
+----+-----+-----+-----+
|0   |#1:0 |A    |true |
|1   |#4:0 |A    |true |
|2   |#7:0 |A    |false|
|3   |#10:0|A    |<n...|
+----+-----+-----+-----+
Command executed in 21ms

There are 2 vertices which have b set to 'true':

{testdb}> g.V().hasLabel('A').has('b',true);

+----+----+-----+----+
|#   |@RID|@TYPE|b   |
+----+----+-----+----+
|0   |#1:0|A    |true|
|1   |#4:0|A    |true|
+----+----+-----+----+
Command executed in 27ms

But count() returns 4:

{testdb}> g.V().hasLabel('A').has('b',true).count();

+------+-----+
|NAME  |VALUE|
+------+-----+
|result|4    |
+------+-----+
Command executed in 5ms

There is 1 vertex which has b set to false:

{testdb}> g.V().hasLabel('A').has('b',false);

VERTEX @type:A @rid:#7:0
+----+-----+
|NAME|VALUE|
+----+-----+
|b   |false|
+----+-----+
Command executed in 4ms

But count() returns 4:

{testdb}> g.V().hasLabel('A').has('b',false).count();

+------+-----+
|NAME  |VALUE|
+------+-----+
|result|4    |
+------+-----+
Command executed in 3ms

Counting the vertices without b works as expected:

{testdb}> g.V().hasLabel('A').not(has('b'));

VERTEX @type:A @rid:#10:0
Command executed in 11ms
{testdb}> g.V().hasLabel('A').not(has('b')).count();

+------+-----+
|NAME  |VALUE|
+------+-----+
|result|1    |
+------+-----+
Command executed in 4ms
@lvca lvca self-assigned this Jul 28, 2024
@lvca lvca added the bug Something isn't working label Jul 28, 2024
@lvca lvca added this to the 24.8.1 milestone Jul 28, 2024
@lvca
Copy link
Contributor

lvca commented Jul 28, 2024

Thanks or the detailed test case. Checking the issue, the ArcadeDB gremlin processor uses the native count as an optimization when it shouldn't because of the existent condition. Working on it.

lvca added a commit that referenced this issue Jul 28, 2024
@lvca
Copy link
Contributor

lvca commented Jul 28, 2024

Fixed

@lvca lvca closed this as completed Jul 28, 2024
@lvca lvca added the fixed label Jul 28, 2024
@docbacardi
Copy link
Contributor Author

Thank you for the quick help. It works like a charm now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants