Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "aerospike-client-c"]
path = aerospike-client-c
url = https://github.com/aerospike/aerospike-client-c.git
branch = master
branch = stage
5 changes: 5 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
'src/main/map_operations.cc',
'src/main/bit_operations.cc',
'src/main/hll_operations.cc',
'src/main/cdt_operations.cc',
'src/main/metrics.cc',
'src/main/policy.cc',
'src/main/query.cc',
Expand Down Expand Up @@ -142,6 +143,8 @@
'src/main/commands/udf_register.cc',
'src/main/commands/udf_remove.cc',
'src/main/enums/abort_status.cc',
'src/main/enums/cdt_op_context.cc',
'src/main/enums/cdt_ctx_type.cc',
'src/main/enums/commit_status.cc',
'src/main/enums/txn_state.cc',
'src/main/enums/txn_capacity.cc',
Expand All @@ -161,6 +164,8 @@
'src/main/enums/batch_type.cc',
'src/main/enums/query_duration.cc',
'src/main/enums/privilege_code.cc',
'src/main/enums/exp_path_select_flags.cc',
'src/main/enums/exp_path_modify_flags.cc',
'src/main/enums/exp_read_flags.cc',
'src/main/enums/exp_write_flags.cc',
'src/main/stats.cc',
Expand Down
1 change: 1 addition & 0 deletions lib/aerospike.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ exports.filter = require('./filter')
*/
const exp = exports.exp = require('./exp')
exp.type = as.exp.type
exp.loopVarPart = as.exp.loopVarPart

/**
* @summary POSIX regex compilation flags.
Expand Down
42 changes: 35 additions & 7 deletions lib/cdt_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@

const as = require('bindings')('aerospike.node')
const exp = as.exp
const cdtCtxType = as.cdtCtxType

/** @private **/
const LIST_INDEX = 0x10
const EXP = cdtCtxType.EXP
/** @private **/
const LIST_RANK = 0x11
const LIST_INDEX = cdtCtxType.LIST_INDEX
/** @private **/
const LIST_VALUE = 0x13
const LIST_RANK = cdtCtxType.LIST_RANK
/** @private **/
const MAP_INDEX = 0x20
const LIST_VALUE = cdtCtxType.LIST_VALUE
/** @private **/
const MAP_RANK = 0x21
const MAP_INDEX = cdtCtxType.MAP_INDEX
/** @private **/
const MAP_KEY = 0x22
const MAP_RANK = cdtCtxType.MAP_RANK
/** @private **/
const MAP_VALUE = 0x23
const MAP_KEY = cdtCtxType.MAP_KEY
/** @private **/
const MAP_VALUE = cdtCtxType.MAP_VALUE
/** @private **/
const int32Max = 2147483647
/** @private **/
Expand Down Expand Up @@ -221,6 +224,31 @@ class CdtContext {
return this.add(MAP_VALUE, value)
}

/**
* @summary At the current context, causes a query to return a list of all the children
* of the current item. For a map, this will recurse into the map elements.
* For a list, this will include all the children in the list.
*
* @param {any} value - Map value
* @return {CdtContext} Updated CDT context, so calls can be chained.
*/
addAllChildren () {
return this.add(EXP)
}

/**
* @summary All children of the current level will be selected, and then the filter expression
* is applied to each item in turn. Items that cause the expression to evaluate to true will be added to the
* list of items returned in a query for this level. Items that cause the expression to evaluate to false
* will be filtered out
*
* @param {any} value - Map value
* @return {CdtContext} Updated CDT context, so calls can be chained.
*/
addAllChildrenWithFilter (exp) {
return this.add(EXP, exp)
}

/** @private **/
add (type, value) {
this.items.push([type, value])
Expand Down
166 changes: 166 additions & 0 deletions lib/exp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const as = require('bindings')('aerospike.node')
const exp = as.exp
const writeFlags = as.expWriteFlags
const readFlags = as.expReadFlags
const pathSelectFlags = as.expPathSelectFlags
const pathModifyFlags = as.expPathModifyFlags
const loopVarPart = as.exp.loopVarPart
const cdtOpContext = as.cdtOpContext
const BIN_TYPE_UNDEF = 0

/**
Expand Down Expand Up @@ -155,6 +159,7 @@ exports.bool = _valueExp(exp.ops.VAL_BOOL, 'boolVal')
*/
exports.int = _valueExp(exp.ops.VAL_INT, 'intVal')
const _int = exports.int
const _rtype = _valueExp(exp.ops.VAL_RTYPE, 'intVal')

/**
* Create 64 bit unsigned integer value.
Expand Down Expand Up @@ -1006,6 +1011,54 @@ exports.var = (varName) => [
..._rawStr(varName)
]

const _loopVar = (type) => (varId) => [
{ op: exp.ops.LOOPVAR, count: 3 },
..._int(type),
..._int(varId)
]

/**
* Assign variable to an expression that can be accessed later.
* Requires server version 5.6.0+.
*
* @function
* @param {string} varid Variable name.
* @return {AerospikeExp} A variable name expression pair.
*/
exports.loopVarFloat = _loopVar(exp.type.FLOAT)
exports.loopVarInt = _loopVar(exp.type.INT)
exports.loopVarList = _loopVar(exp.type.LIST)
exports.loopVarMap = _loopVar(exp.type.MAP)
exports.loopVarStr = _loopVar(exp.type.STR)
exports.loopVarBlob = _loopVar(exp.type.BLOB)
exports.loopVarBool = _loopVar(exp.type.BOOL)
exports.loopVarNil = _loopVar(exp.type.NIL)
exports.loopVarGeoJSON = _loopVar(exp.type.GEOJSON)
exports.loopVarHLL = _loopVar(exp.type.HLL)

exports.selectByPath = (bin, valueType, flags, ctx) => [
{ op: exp.ops.CALL, count: 5 },
..._rtype(valueType),
..._int(exp.sys.CALL_CDT),
{ op: exp.ops.CALL_VOP_START, count: 3 },
..._int(cdtOpContext.SELECT),
{ op: exp.ops.CTX, ctx },
..._int(flags),
...bin
]

exports.modifyByPath = (bin, valueType, modExp, flags, ctx) => [
{ op: exp.ops.CALL, count: 5 },
..._rtype(valueType),
..._int(exp.sys.CALL_CDT | exp.sys.FLAG_MODIFY_LOCAL),
{ op: exp.ops.CALL_VOP_START, count: 4 },
..._int(cdtOpContext.SELECT),
{ op: exp.ops.CTX, ctx },
..._int(flags | 4),
{ op: exp.ops.MERGE, exp: modExp },
...bin
]

/**
* The {@link module:aerospike/exp/lists|aerospike/exp/lists} module defines functions
* for expressions on the List datatype.
Expand Down Expand Up @@ -1101,3 +1154,116 @@ exports.expWriteFlags = {
*/
EVAL_NO_FAIL: writeFlags.EVAL_NO_FAIL
}

/**
*
* @readonly
* @enum {number}
* @description Path expression select operation flags. Use BITWISE OR to combine flags.
*/
exports.pathSelectFlags = {
/**
* Return a tree from the root (bin) level to the bottom of the tree,
* with only non-filtered out nodes.
* @const {number}
*/
MATCHING_TREE: pathSelectFlags.MATCHING_TREE,

/**
* Return the list of the values of the nodes finally selected by the context.
* For maps, this returns the value of each (key, value) pair.
* @const {number}
*/
VALUE: pathSelectFlags.VALUE,

/**
* Return the list of the values of the nodes finally selected by the context.
* This is a synonym for AS_EXP_PATH_SELECT_VALUE to make it clear in your
* source code that you're expecting a list.
* @const {number}
*/
LIST_VALUE: pathSelectFlags.LIST_VALUE,

/**
* Return the list of map values of the nodes finally selected by the context.
* This is a synonym for AS_EXP_PATH_SELECT_VALUE to make it clear in your
* source code that you're expecting a map. See also
* AS_EXP_PATH_SELECT_MAP_KEY_VALUE.
* @const {number}
*/
MAP_VALUE: pathSelectFlags.MAP_VALUE,

/**
* Returns the list of map (key, value) pairs of the nodes finally selected
* by the context. This is a synonym for setting both
* AS_EXP_PATH_SELECT_MAP_KEY and AS_EXP_PATH_SELECT_MAP_VALUE bits together.
* @const {number}
*/
MAP_KEY: pathSelectFlags.MAP_KEY,

MAP_KEY_VALUE: pathSelectFlags.MAP_KEY_VALUE,

/**
* If the expression in the context hits an invalid type (e.g., selects
* as an integer when the value is a string), do not fail the operation;
* just ignore those elements. Interpret an expression that returns UNKNOWN
* as false instead.
* @const {number}
*/
NO_FAIL: pathSelectFlags.NO_FAIL
}

/**
*
* @readonly
* @enum {number}
* @description Path expression modify operation flags.
*/
exports.pathModifyFlags = {
/**
* If the expression in the context hits an invalid type, the operation
* will fail. This is the default behavior.
* @const {number}
*/
DEFAULT: pathModifyFlags.DEFAULT,

/**
* If the expression in the context hits an invalid type (e.g., selects
* as an integer when the value is a string), do not fail the operation;
* just ignore those elements. Interpret UNKNOWN as false instead.
* @const {number}
*/
NO_FAIL: pathModifyFlags.NO_FAIL
}

/**
*
* @readonly
* @enum {number}
* @description Loop variable parts for expression loop variables.
* Used to specify which part of a loop variable to access during iteration.
*/
exports.loopVarPart = {
/**
* Access the key part of the loop variable.
* For maps, this refers to the map key.
* For lists, this refers to the list index.
*
* @const {number}
*/
KEY: loopVarPart.KEY,

/**
* Access the value part of the loop variable.
* For maps, this refers to the map value.
* For lists, this refers to the list item value.
* @const {number}
*/
VALUE: loopVarPart.VALUE,

/**
* Returns a list of indexes.
* @const {number}
*/
INDEX: loopVarPart.INDEX
}
36 changes: 36 additions & 0 deletions lib/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
*/
const as = require('bindings')('aerospike.node')
const ops = as.scalarOperations
const cdtOps = as.cdtOperations
/**
* @class module:aerospike/operations~Operation
* @protected
Expand Down Expand Up @@ -192,3 +193,38 @@ exports.touch = function (ttl) {
exports.delete = function () {
return new Operation(ops.DELETE, undefined)
}

/**
* @summary CDT select operation.
*
* @description Returns true on success. Otherwise an error occurred.
*
* @param {number} [ttl=Aerospike.ttl.NAMESPACE_DEFAULT] - The new, relative TTL to set for the record, when it is touched.
* @returns {Operation} Operation that can be passed to the {@link Client#operate} command.
*
* @since v3.14.0
*/
exports.selectByPath = function (bin, context, flags) {
return new Operation(cdtOps.SELECT_BY_PATH, bin, {
context,
flags
})
}

/**
* @summary CDT Modify operation.
*
* @description Returns true on success. Otherwise an error occurred.
*
* @param {number} [ttl=Aerospike.ttl.NAMESPACE_DEFAULT] - The new, relative TTL to set for the record, when it is touched.
* @returns {Operation} Operation that can be passed to the {@link Client#operate} command.
*
* @since v3.14.0
*/
exports.modifyByPath = function (bin, context, modExp, flags) {
return new Operation(cdtOps.MODIFY_BY_PATH, bin, {
modExp,
context,
flags
})
}
2 changes: 2 additions & 0 deletions out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
link eth0 state up
link eth0 state up in 0
5 changes: 5 additions & 0 deletions src/include/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

v8::Local<v8::Object> auth_mode_enum_values();
v8::Local<v8::Object> bitwise_enum_values();
v8::Local<v8::Object> cdtCtxType();
v8::Local<v8::Object> cdtOpContext();
v8::Local<v8::Object> cdt_opcode_values();
v8::Local<v8::Object> generation_policy_values();
v8::Local<v8::Object> hll_enum_values();
v8::Local<v8::Object> indexDataType();
Expand All @@ -43,6 +46,8 @@ v8::Local<v8::Object> ttl_enum_values();
v8::Local<v8::Object> batchTypes();
v8::Local<v8::Object> queryDuration();
v8::Local<v8::Object> privilegeCode();
v8::Local<v8::Object> expPathModifyFlags();
v8::Local<v8::Object> expPathSelectFlags();
v8::Local<v8::Object> expReadFlags();
v8::Local<v8::Object> expWriteFlags();
v8::Local<v8::Object> abortStatus();
Expand Down
6 changes: 5 additions & 1 deletion src/include/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

extern "C" {
#include <aerospike/as_status.h>
#include <aerospike/as_operations.h>
}

Expand All @@ -38,10 +39,12 @@ int add_hll_op(as_operations *ops, uint32_t opcode, v8::Local<v8::Object> op,
LogInfo *log);
int add_exp_op(as_operations *ops, uint32_t opcode, v8::Local<v8::Object> op,
LogInfo *log);
int add_cdt_op(as_operations *ops, uint32_t opcode, v8::Local<v8::Object> op,
LogInfo *log);
int get_optional_cdt_context(as_cdt_ctx *context, bool *has_context,
v8::Local<v8::Object> obj, const char *prop,
const LogInfo *log);
as_cdt_ctx* get_optional_cdt_context_heap(int * rc,
as_cdt_ctx* get_cdt_context_heap(int * rc,
v8::Local<v8::Object> obj, const char *prop,
const LogInfo *log);
int get_v8_cdt_context(as_cdt_ctx *context, v8::Local<v8::Array> items);
Expand All @@ -60,3 +63,4 @@ const uint32_t MAP_OPS_OFFSET = 0x0200;
const uint32_t BIT_OPS_OFFSET = 0x0300;
const uint32_t HLL_OPS_OFFSET = 0x0400;
const uint32_t EXPOP_OPS_OFFSET = 0x0500;
const uint32_t CDT_OPS_OFFSET = 0x0600;
Loading