npgall/cqengine

Does engine support LIMIT queries?

Opened this issue · 4 comments

for example

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

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.

ldwnt commented

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.

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.

ldwnt commented

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