Skip to content

Commit

Permalink
Add exp.inf and exp.wildcard methods
Browse files Browse the repository at this point in the history
CLIENT-2378
Add exp.inf and exp.wildcard methods
Add testing for exp.inf, exp.nil, and exp.wildcard
  • Loading branch information
DomPeliniAerospike committed Sep 19, 2023
1 parent a969a6b commit 1ec3643
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/exp.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,22 @@ exports.geo = _valueExp(exp.ops.VAL_GEO, 'value')
*/
exports.nil = () => [{ op: exp.ops.AS_VAL, value: null }]

/**
* Create 'inf' value.
*
* @function
* @return {AerospikeExp}
*/
exports.inf = () => [{ op: exp.ops.AS_VAL, inf: null }]

/**
* Create 'wildcard' value.
*
* @function
* @return {AerospikeExp}
*/
exports.wildcard = () => [{ op: exp.ops.AS_VAL, wildcard: null }]

const _val = _valueExp(exp.ops.AS_VAL, 'value')

/**
Expand Down
2 changes: 2 additions & 0 deletions src/include/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ int get_uint64_property(uint64_t *intp, v8::Local<v8::Object> obj,
char const *prop, const LogInfo *log);
int get_uint32_property(uint32_t *intp, v8::Local<v8::Object> obj,
char const *prop, const LogInfo *log);
void get_inf_property(as_val **value, const LogInfo *log);
void get_wildcard_property(as_val **value, const LogInfo *log);
int get_asval_property(as_val **value, v8::Local<v8::Object> obj,
const char *prop, const LogInfo *log);
int get_string_property(char **strp, v8::Local<v8::Object> obj,
Expand Down
10 changes: 10 additions & 0 deletions src/main/expressions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ int convert_entry(Local<Object> entry_obj, as_exp_entry *entry,
return AS_NODE_PARAM_OK;
}

if (Nan::Has(entry_obj, Nan::New("inf").ToLocalChecked()).FromJust()) {
entry->v.val = NULL;
get_inf_property(&entry->v.val, log);
}

if (Nan::Has(entry_obj, Nan::New("wildcard").ToLocalChecked()).FromJust()) {
entry->v.val = NULL;
get_wildcard_property(&entry->v.val, log);
}

return rc;
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/util/conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,18 @@ int get_optional_bytes_property(uint8_t **bytes, int *size, bool *defined,
return AS_NODE_PARAM_OK;
}

void get_inf_property(as_val **value, const LogInfo *log)
{
Nan::HandleScope scope;
*value = (as_val *)&as_cmp_inf;
}

void get_wildcard_property(as_val **value, const LogInfo *log)
{
Nan::HandleScope scope;
*value = (as_val *)&as_cmp_wildcard;
}

int get_asval_property(as_val **value, Local<Object> obj, const char *prop,
const LogInfo *log)
{
Expand Down
29 changes: 29 additions & 0 deletions test/exp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
const Aerospike = require('../lib/aerospike')
const exp = Aerospike.exp
const op = Aerospike.operations
const maps = Aerospike.maps

const GeoJSON = Aerospike.GeoJSON

Expand Down Expand Up @@ -236,6 +237,34 @@ describe('Aerospike.exp', function () {
})
})

describe('nil', function () {
it('evaluates to true if any expression evaluates to true', async function () {
const key = await createRecord({ tags: { a: 'blue', b: 'green', c: 'yellow' } })

await testNoMatch(key, exp.eq(exp.maps.getByValueRange(exp.binMap('tags'), exp.str('green'), exp.nil(), maps.returnType.COUNT), exp.int(2)))
await testMatch(key, exp.eq(exp.maps.getByValueRange(exp.binMap('tags'), exp.str('green'), exp.nil(), maps.returnType.COUNT), exp.int(1)))
})
})

describe('inf', function () {
it('evaluates to true if any expression evaluates to true', async function () {
const key = await createRecord({ tags: { a: 'blue', b: 'green', c: 'yellow' } })

await testNoMatch(key, exp.eq(exp.maps.getByValueRange(exp.binMap('tags'), exp.inf(), exp.str('green'), maps.returnType.COUNT), exp.int(1)))
await testMatch(key, exp.eq(exp.maps.getByValueRange(exp.binMap('tags'), exp.inf(), exp.str('green'), maps.returnType.COUNT), exp.int(2)))
})

})

describe('wildcard', function () {
it('evaluates to true if any expression evaluates to true', async function () {
const key = await createRecord({ tags: { a: 'blue', b: 'green', c: 'yellow' } })

await testNoMatch(key, exp.eq(exp.maps.getByValueRange(exp.binMap('tags'), exp.inf(), exp.wildcard(), maps.returnType.COUNT), exp.int(2)))
await testMatch(key, exp.eq(exp.maps.getByValueRange(exp.binMap('tags'), exp.inf(), exp.wildcard(), maps.returnType.COUNT), exp.int(3)))
})
})

describe('arithmetic expressions', function () {
describe('int bin add expression', function () {
it('evaluates exp_read op to true if temp bin equals the sum of bin and given value', async function () {
Expand Down

0 comments on commit 1ec3643

Please sign in to comment.