Specify offset/limit for specific node


#1

Hello,

Having a question related to the offset/limit functionality; currently the syntax allows you to specify offset/limit before the get statement.

When you have the following query:

match $x isa Entity1 has attribute1 $y; offset 0; limit 5; get;

{$x id V725135448 isa Entity1; $y val “6” isa attribute1;}

{$y val “6” isa attribute1; $x id V725209176 isa Entity1;}

{$x id V725213272 isa Entity1; $y val “6” isa attribute1;}

{$x id V725233752 isa Entity1; $y val “6” isa attribute1;}

{$x id V725352536 isa Entity1; $y val “6” isa attribute1;}

However, when you specifically request attribute1:

match $x isa Entity1 has attribute1 $y; offset 0; limit 5; get $y;

{$y val “6” isa attribute1;}

If I understand it correctly, the offset/limit works on the subgraph and then the get returns the distinct entries.

However, I would be interested in getting 5 unique entries from attribute1 which I tried with:

match $x isa Entity1 has attribute1 $y; get $y; offset 0; limit 5;

but this is not allowed.

Any suggestions on how I can resolve this?

Cheers,

Greet


#2

So the get part of the query acts like a filter once the answers are obtained. It doesn’t affect the querying. So even
if you specify to get the attributes only it doesn’t affect your answer set hence you get a single unique answer.

If I understand correctly, if you are using the API you can stream your answers and apply limit to the stream.

Something along the lines of (in Java):

tx.graql().parse("match $x isa Entity1 has attribute1 $y; get $y")
.stream()
.limit(5)
.collect(Collectors.toSet());

#3

OK, we’ll look into it and give it a try using the Python driver. Thanks for the response.