cqengine icon indicating copy to clipboard operation
cqengine copied to clipboard

Does engine support LIMIT queries?

Open unclepaul84 opened this issue 5 years ago • 4 comments

for example

SELECT * FROM cars ORDER BY MAKE LIMIT 1,1000;

unclepaul84 avatar Oct 02 '20 01:10 unclepaul84

No this is not supported inside SQL queries currently. However you can do this on the Java side, by calling resultSet.stream().limit() for the results that you get from an SQL query.

I will leave this issue open though, as a feature request, because I think it could be a useful feature.

npgall avatar Oct 02 '20 21:10 npgall

No this is not supported inside SQL queries currently. However you can do this on the Java side, by calling resultSet.stream().limit() for the results that you get from an SQL query.

I will leave this issue open though, as a feature request, because I think it could be a useful feature.

Does it support something like "limit" in other query apis? If not, retrieving a lot of items from a collection may cost a lot of time.

ldwnt avatar Jun 21 '21 07:06 ldwnt

I don't think that should be a problem. The engine only serves data via Streams and Iterables - which are "pull based" mechanisms. For CQEngine APIs which have those return types, it is up to the application to decide how many items it wants to pull from the Stream/Iterable. The amount of work that the engine will do is proportional to the number of objects the application pulls.

In the case of Streams, the application can use the stream().limit() method, and in the case of Iterables, it can either stop iterating early itself, or use Guava's Iterables.limit() to do the same thing.

npgall avatar Jun 28 '21 10:06 npgall

I don't think that should be a problem. The engine only serves data via Streams and Iterables - which are "pull based" mechanisms. For CQEngine APIs which have those return types, it is up to the application to decide how many items it wants to pull from the Stream/Iterable. The amount of work that the engine will do is proportional to the number of objects the application pulls.

In the case of Streams, the application can use the stream().limit() method, and in the case of Iterables, it can either stop iterating early itself, or use Guava's Iterables.limit() to do the same thing.

I see, thanks for elaboration

ldwnt avatar Jun 29 '21 02:06 ldwnt