Limit number of records in aerospike select query
Asked Answered
J

2

12

I am trying to query using aql (Aerospike Query Language) in aerospike set.
Suppose there are 1000 records and I want to read any 10 records. Usually I would query something like :

select * from test.demo limit 10;

How do I query the same using aql ?

Joellenjoelly answered 19/9, 2014 at 6:34 Comment(0)
S
5

2024 Edit on a really old (and obsolete) question Yes, AQL can use LIMIT. See https://aerospike.com/docs/tools/aql/querying_records#filter-on-indexed-bins

The JDBC driver can do a limit too. See https://github.com/aerospike/aerospike-jdbc/blob/main/docs/examples.md

Original answer from 2014:

At the moment you cannot do that in aql, but you can use the BETWEEN predicate to define a range to the query.

When you use the C-client (or one of the language clients that wrap around it) a scan (as_scan_foreach) can be limited by setting the percentage field of the as_scan struct.

Sidman answered 19/9, 2014 at 14:8 Comment(2)
This is such a basic requirement, 4 years later they still don't have this in their AQL CLI.Irrelievable
It exists as basic server functionality for many years, and the JDBC driver leverages. For your convenience github.com/aerospike/aerospike-jdbc/blob/main/docs/examples.md - also AQL has been able to do a LIMIT for a very long time, so not sure why in 2023 you commented otherwise.Sidman
H
1

Here is an example of 'scan' in Java.

    **this.client.scanAll(scanPolicy, "test", "demo", new ScanCallback() {

        @Override
        public void scanCallback(Key key, Record record) throws AerospikeException {
            System.out.println("Record: " + record);

        }
    });**

That there is no order implied in a 'scan', records are returned to your application in the order they are received from the nodes in the cluster.

Harmonious answered 19/9, 2014 at 14:29 Comment(1)
Hmm... I think because of this randomness Aerospike will not be a fit for pagination?Trinitrophenol

© 2022 - 2024 — McMap. All rights reserved.