Mr. MonoChrome
Mr. MonoChrome

Reputation: 1383

less than greater than filtered queries, aerospike

Its been hard for me to find finite documentation on aerospike. Using aerospike filters with or without lua, is it possible for me to :

  1. Order my results server side
  2. Use a filter to do a greater than/less than query

Essentially I want to encode a value(client side) and retrieve the first row from aerospike whos value is greater than the encoded one.

Another way to put it, is opposite of price is right... what is the lowest value i can find in aerospike, whos value is not lower than the one i give.

Id like a simple way, but I am also open to work arounds(or flat out no if its not reasonable/practical)

Upvotes: 4

Views: 1328

Answers (3)

Ronen Botzer
Ronen Botzer

Reputation: 7117

In the past you would have expressed this as a stream UDF, but since release 3.12 a predicate filter would be the correct solution.

Take a look at the PredExp class of the Java client and its examples for building complex filters. Predicate filtering also currently exists for the C, C# and Go clients.

Upvotes: 1

MrBar
MrBar

Reputation: 1108

Basic Sorting is natively supported in large lists (LDT).

In a Large List your key (index) is always ordered in a lexical manner by default.

Please notice that ldt-enabled true directive must be present in the namespace's config area in aerospike.conf

an example with the javascript client

var key = {ns: 'test', set: 'mySet', key: 'myKey'};
var callback = function (status, result) {console.log(status, result)}

var list = client.LargeList(key, 'targetBinName', null, callback));

// add first item (also determinate the list values type) 
list.add(1, callback);

// add multiple items
list.add([0, 2, 4, 5], callback);

list.add(3, callback);

// get all items
list.scan(function (status, list) {
     // list = [0, 1, 2, 3, 4, 5]
})

// select by values range
list.findRange(0, 3, callback)

// filter using udf to do custom gt/lt filtering
list.filter('udfName', callback)

if you need to store objects then you must add a key property that will be the index for sorting, range, duplicates etc (no duplicates are allowed by default)

list.add({key: 1})
list.add([{key: 0},{key: 2}])

I'm sure the other languages drivers have the same methods more or less.

more on Large list in Aerospike docs

Large list docs section in NodeJS client on Github

Upvotes: 1

sunil
sunil

Reputation: 3567

  1. Aerospike does not natively support ordering of data on server-side.
  2. Aerospike supports filters on the query. You can specify a range filter for your need. See the example at this link.

Upvotes: 3

Related Questions