Class: Aerospike::Exp::List

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/exp/exp_list.rb

Overview

List expression generator. See Exp.

The bin expression argument in these methods can be a reference to a bin or the result of another expression. Expressions that modify bin values are only used for temporary expression evaluation and are not permanently applied to the bin.

List modify expressions the bin’s value. This value will be a list except when the list is nested within a map. In that case, a map is returned for the list modify expression.

List expressions support negative indexing. If the index is negative, the resolved index starts backwards from end of list. If an index is out of bounds, a parameter error will be returned. If a range is partially out of bounds, the valid part of the range will be returned. Index/Range examples:

Index 0: First item in list. Index 4: Fifth item in list. Index -1: Last item in list. Index -3: Third to last item in list. Index 1 Count 2: Second and third items in list. Index -3 Count 3: Last three items in list. Index -5 Count 4: Range between fifth to last item to second to last item inclusive.

Nested expressions are supported by optional CTX context arguments. Example:

bin = [[7,9,5],,[6,5,4,1]] Get size of last list. ListExp.size(Exp.listBin(“bin”), CTX.listIndex(-1)) result = 4

Class Method Summary collapse

Class Method Details

.append(value, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT) ⇒ Object

Create expression that appends value to end of list.



51
52
53
54
# File 'lib/aerospike/exp/exp_list.rb', line 51

def self.append(value, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT)
  bytes = Exp.pack(ctx, APPEND, value, policy.order, policy.flags)
  self.add_write(bin, bytes, ctx)
end

.append_items(list, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT) ⇒ Object

Create expression that appends list items to end of list.



57
58
59
60
# File 'lib/aerospike/exp/exp_list.rb', line 57

def self.append_items(list, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT)
  bytes = Exp.pack(ctx, APPEND_ITEMS, list, policy.order, policy.flags)
  self.add_write(bin, bytes, ctx)
end

.clear(bin, ctx: nil) ⇒ Object

Create expression that removes all items in list.



88
89
90
91
# File 'lib/aerospike/exp/exp_list.rb', line 88

def self.clear(bin, ctx: nil)
  bytes = Exp.pack(ctx, CLEAR)
  self.add_write(bin, bytes, ctx)
end

.get_by_index(return_type, value_type, index, bin, ctx: nil) ⇒ Object

Create expression that selects list item identified by index and returns selected data specified by return_type.

Examples

# a == 5 Exp.eq(

ListExp.getByIndex(CDT::ListReturnType::VALUE, Exp::Type::INT, Exp.val(3), Exp.listBin("a")),
Exp.val(5))

end</pre>

Parameters:

  • return_type

    metadata attributes to return. See {@link CDT::ListReturnTypeend

  • value_type

    expected type of value

  • index

    list index expression

  • bin

    list bin or list value expression

  • ctx (defaults to: nil)

    optional context path for nested CDT



266
267
268
269
# File 'lib/aerospike/exp/exp_list.rb', line 266

def self.get_by_index(return_type, value_type, index, bin, ctx: nil)
  bytes = Exp.pack(ctx, GET_BY_INDEX, return_type, index)
  self.add_read(bin, bytes, value_type)
end

.get_by_index_range(return_type, index, bin, ctx: nil, count: nil) ⇒ Object

Create expression that selects “count” list items starting at specified index and returns selected data specified by return_type (See {@link CDT::ListReturnTypeend).



273
274
275
276
# File 'lib/aerospike/exp/exp_list.rb', line 273

def self.get_by_index_range(return_type, index, bin, ctx: nil)
  bytes = Exp.pack(ctx, GET_BY_INDEX_RANGE, return_type, index)
  self.add_read(bin, bytes, get_value_type(return_type))
end

.get_by_rank(return_type, value_type, rank, bin, ctx: nil) ⇒ Object

Create expression that selects list item identified by rank and returns selected data specified by return_type.

Examples

# Player with lowest score. ListExp.getByRank(CDT::ListReturnType::VALUE, Type.STRING, Exp.val(0), Exp.listBin(“a”)) end</pre>

Parameters:

  • return_type

    metadata attributes to return. See {@link CDT::ListReturnTypeend

  • value_type

    expected type of value

  • rank

    rank expression

  • bin

    list bin or list value expression

  • ctx (defaults to: nil)

    optional context path for nested CDT



302
303
304
305
# File 'lib/aerospike/exp/exp_list.rb', line 302

def self.get_by_rank(return_type, value_type, rank, bin, ctx: nil)
  bytes = Exp.pack(ctx, GET_BY_RANK, return_type, rank)
  self.add_read(bin, bytes, value_type)
end

.get_by_rank_range(return_type, rank, bin, ctx: nil, count: nil) ⇒ Object

Create expression that selects “count” list items starting at specified rank and returns selected data specified by return_type (See {@link CDT::ListReturnTypeend).



309
310
311
312
# File 'lib/aerospike/exp/exp_list.rb', line 309

def self.get_by_rank_range(return_type, rank, bin, ctx: nil)
  bytes = Exp.pack(ctx, GET_BY_RANK_RANGE, return_type, rank)
  self.add_read(bin, bytes, get_value_type(return_type))
end

.get_by_value(return_type, value, bin, ctx: nil) ⇒ Object

Create expression that selects list items identified by value and returns selected data specified by return_type.

Examples

# List bin “a” contains at least one item == “abc” Exp.gt(

ListExp.getByValue(CDT::ListReturnType::COUNT, Exp.val("abc"), Exp.listBin("a")),
Exp.val(0))

end</pre>

Parameters:

  • return_type

    metadata attributes to return. See {@link CDT::ListReturnType

  • value

    search expression

  • bin

    list bin or list value expression

  • ctx (defaults to: nil)

    optional context path for nested CDT



200
201
202
203
# File 'lib/aerospike/exp/exp_list.rb', line 200

def self.get_by_value(return_type, value, bin, ctx: nil)
  bytes = Exp.pack(ctx, GET_BY_VALUE, return_type, value)
  self.add_read(bin, bytes, get_value_type(return_type))
end

.get_by_value_list(return_type, values, bin, ctx: nil) ⇒ Object

Create expression that selects list items identified by values and returns selected data specified by return_type.



225
226
227
228
# File 'lib/aerospike/exp/exp_list.rb', line 225

def self.get_by_value_list(return_type, values, bin, ctx: nil)
  bytes = Exp.pack(ctx, GET_BY_VALUE_LIST, return_type, values)
  self.add_read(bin, bytes, get_value_type(return_type))
end

.get_by_value_range(return_type, value_begin, value_end, bin, ctx: nil) ⇒ Object

Create expression that selects list items identified by value range and returns selected data specified by return_type.

Examples

# List bin “a” items >= 10 && items < 20 ListExp.getByValueRange(CDT::ListReturnType::VALUE, Exp.val(10), Exp.val(20), Exp.listBin(“a”)) end</pre>

Parameters:

  • return_type

    metadata attributes to return. See CDT::ListReturnType

  • value_begin

    begin expression inclusive. If nil, range is less than value_end.

  • value_end

    end expression exclusive. If nil, range is greater than equal to value_begin.

  • bin

    bin or list value expression

  • ctx (defaults to: nil)

    optional context path for nested CDT



218
219
220
221
# File 'lib/aerospike/exp/exp_list.rb', line 218

def self.get_by_value_range(return_type, value_begin, value_end, bin, ctx: nil)
  bytes = self.pack_range_operation(GET_BY_VALUE_INTERVAL, return_type, value_begin, value_end, ctx)
  self.add_read(bin, bytes, get_value_type(return_type))
end

.get_by_value_relative_rank_range(return_type, value, rank, bin, ctx: nil, count: nil) ⇒ Object

Create expression that selects list items nearest to value and greater by relative rank with a count limit and returns selected data specified by return_type (See {@link CDT::ListReturnType).

Examples for ordered list [0,4,5,9,11,15]:

(value,rank,count) = [selected items] (5,0,2) = [5,9] (5,1,1) = [9] (5,-1,2) = [4,5] (3,0,1) = [4] (3,3,7) = [11,15] (3,-3,2) = []



242
243
244
245
246
247
248
249
# File 'lib/aerospike/exp/exp_list.rb', line 242

def self.get_by_value_relative_rank_range(return_type, value, rank, bin, ctx: nil, count: nil)
  unless count.nil?
    bytes = Exp.pack(ctx, GET_BY_VALUE_REL_RANK_RANGE, return_type, value, rank, count)
  else
    bytes = Exp.pack(ctx, GET_BY_VALUE_REL_RANK_RANGE, return_type, value, rank)
  end
  self.add_read(bin, bytes, get_value_type(return_type))
end

.increment(index, value, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT) ⇒ Object

Create expression that increments list by value. Value expression should resolve to a number.



76
77
78
79
# File 'lib/aerospike/exp/exp_list.rb', line 76

def self.increment(index, value, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT)
  bytes = Exp.pack(ctx, INCREMENT, index, value, policy.order, policy.flags)
  self.add_write(bin, bytes, ctx)
end

.insert(index, value, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT) ⇒ Object

Create expression that inserts value to specified index of list.



63
64
65
66
# File 'lib/aerospike/exp/exp_list.rb', line 63

def self.insert(index, value, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT)
  bytes = Exp.pack(ctx, INSERT, index, value, policy.flags)
  self.add_write(bin, bytes, ctx)
end

.insert_items(index, list, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT) ⇒ Object

Create expression that inserts each input list item starting at specified index of list.



69
70
71
72
# File 'lib/aerospike/exp/exp_list.rb', line 69

def self.insert_items(index, list, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT)
  bytes = Exp.pack(ctx, INSERT_ITEMS, index, list, policy.flags)
  self.add_write(bin, bytes, ctx)
end

.remove_by_index(index, bin, ctx: nil) ⇒ Object

Create expression that removes list item identified by index.



144
145
146
147
# File 'lib/aerospike/exp/exp_list.rb', line 144

def self.remove_by_index(index, bin, ctx: nil)
  bytes = Exp.pack(ctx, REMOVE_BY_INDEX, CDT::ListReturnType::NONE, index)
  self.add_write(bin, bytes, ctx)
end

.remove_by_index_range(index, bin, ctx: nil, count: nil) ⇒ Object

Create expression that removes “count” list items starting at specified index.



150
151
152
153
154
155
156
157
# File 'lib/aerospike/exp/exp_list.rb', line 150

def self.remove_by_index_range(index, bin, ctx: nil, count: nil)
  unless count.nil?
    bytes = Exp.pack(ctx, REMOVE_BY_INDEX_RANGE, CDT::ListReturnType::NONE, index, count)
  else
    bytes = Exp.pack(ctx, REMOVE_BY_INDEX_RANGE, CDT::ListReturnType::NONE, index)
  end
  self.add_write(bin, bytes, ctx)
end

.remove_by_rank(rank, bin, ctx: nil) ⇒ Object

Create expression that removes list item identified by rank.



160
161
162
163
# File 'lib/aerospike/exp/exp_list.rb', line 160

def self.remove_by_rank(rank, bin, ctx: nil)
  bytes = Exp.pack(ctx, REMOVE_BY_RANK, CDT::ListReturnType::NONE, rank)
  self.add_write(bin, bytes, ctx)
end

.remove_by_rank_range(rank, bin, ctx: nil, count: nil) ⇒ Object

Create expression that removes “count” list items starting at specified rank.



166
167
168
169
170
171
172
173
# File 'lib/aerospike/exp/exp_list.rb', line 166

def self.remove_by_rank_range(rank, bin, ctx: nil, count: nil)
  unless count.nil?
    bytes = Exp.pack(ctx, REMOVE_BY_RANK_RANGE, CDT::ListReturnType::NONE, rank, count)
  else
    bytes = Exp.pack(ctx, REMOVE_BY_RANK_RANGE, CDT::ListReturnType::NONE, rank)
  end
  self.add_write(bin, bytes, ctx)
end

.remove_by_value(value, bin, ctx: nil) ⇒ Object

Create expression that removes list items identified by value.



104
105
106
107
# File 'lib/aerospike/exp/exp_list.rb', line 104

def self.remove_by_value(value, bin, ctx: nil)
  bytes = Exp.pack(ctx, REMOVE_BY_VALUE, CDT::ListReturnType::NONE, value)
  self.add_write(bin, bytes, ctx)
end

.remove_by_value_list(values, bin, ctx: nil) ⇒ Object

Create expression that removes list items identified by values.



110
111
112
113
# File 'lib/aerospike/exp/exp_list.rb', line 110

def self.remove_by_value_list(values, bin, ctx: nil)
  bytes = Exp.pack(ctx, REMOVE_BY_VALUE_LIST, CDT::ListReturnType::NONE, values)
  self.add_write(bin, bytes, ctx)
end

.remove_by_value_range(value_begin, value_end, bin, ctx: nil) ⇒ Object

Create expression that removes list items identified by value range (value_begin inclusive, value_end exclusive). If value_begin is nil, the range is less than value_end. If value_end is nil, the range is greater than equal to value_begin.



118
119
120
121
# File 'lib/aerospike/exp/exp_list.rb', line 118

def self.remove_by_value_range(value_begin, value_end, bin, ctx: nil)
  bytes = self.pack_range_operation(REMOVE_BY_VALUE_INTERVAL, CDT::ListReturnType::NONE, value_begin, value_end, ctx)
  self.add_write(bin, bytes, ctx)
end

.remove_by_value_relative_rank_range(value, rank, bin, ctx: nil, count: nil) ⇒ Object

Create expression that removes list items nearest to value and greater by relative rank with a count limit if provided.

Examples for ordered list [0,4,5,9,11,15]:

(value,rank,count) = [removed items] (5,0,2) = [5,9] (5,1,1) = [9] (5,-1,2) = [4,5] (3,0,1) = [4] (3,3,7) = [11,15] (3,-3,2) = []



134
135
136
137
138
139
140
141
# File 'lib/aerospike/exp/exp_list.rb', line 134

def self.remove_by_value_relative_rank_range(value, rank, bin, ctx: nil, count: nil)
  unless count.nil?
    bytes = Exp.pack(ctx, REMOVE_BY_VALUE_REL_RANK_RANGE, CDT::ListReturnType::NONE, value, rank, count)
  else
    bytes = Exp.pack(ctx, REMOVE_BY_VALUE_REL_RANK_RANGE, CDT::ListReturnType::NONE, value, rank)
  end
  self.add_write(bin, bytes, ctx)
end

.set(index, value, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT) ⇒ Object

Create expression that sets item value at specified index in list.



82
83
84
85
# File 'lib/aerospike/exp/exp_list.rb', line 82

def self.set(index, value, bin, ctx: nil, policy: CDT::ListPolicy::DEFAULT)
  bytes = Exp.pack(ctx, SET, index, value, policy.flags)
  self.add_write(bin, bytes, ctx)
end

.size(bin, ctx: nil) ⇒ Object

Create expression that returns list size.

Examples

# List bin “a” size > 7 Exp.gt(ListExp.size(Exp.listBin(“a”)), Exp.val(7)) end</pre>



181
182
183
184
# File 'lib/aerospike/exp/exp_list.rb', line 181

def self.size(bin, ctx: nil)
  bytes = Exp.pack(ctx, SIZE)
  self.add_read(bin, bytes, Exp::Type::INT)
end

.sort(sort_flags, bin, ctx: nil) ⇒ Object

Create expression that sorts list according to sort_flags.

Parameters:

  • sort_flags

    sort flags. See {@link ListSortFlagsend.

  • bin

    bin or list value expression

  • ctx (defaults to: nil)

    optional context path for nested CDT



98
99
100
101
# File 'lib/aerospike/exp/exp_list.rb', line 98

def self.sort(sort_flags, bin, ctx: nil)
  bytes = Exp.pack(ctx, SORT, sort_flags)
  self.add_write(bin, bytes, ctx)
end