Class: Aerospike::Exp
- Inherits:
-
Object
- Object
- Aerospike::Exp
- Defined in:
- lib/aerospike/exp/exp.rb
Direct Known Subclasses
Bin, Blob, Bool, Cmd, CmdExp, CmdInt, CmdStr, Def, ExpBytes, Float, Geo, Infinity, Int, Let, ListVal, MapVal, Module, Nil, Regex, Str, Wildcard
Defined Under Namespace
Modules: ReadFlags, RegexFlags, Type, WriteFlags Classes: Bin, Bit, Blob, Bool, Cmd, CmdExp, CmdInt, CmdStr, Def, ExpBytes, Float, Geo, HLL, Infinity, Int, Let, List, ListVal, Map, MapVal, Module, Nil, Operation, Regex, Str, Wildcard
Constant Summary collapse
- MODIFY =
Internal
0x40
Class Method Summary collapse
-
.abs(value) ⇒ Object
Create operator that returns absolute value of a number.
-
.add(*exps) ⇒ Object
Create “add” (+) operator that applies to a variable number of expressions.
-
.and(*exps) ⇒ Object
Create “and” (&&) operator that applies to a variable number of expressions.
-
.arshift(value, shift) ⇒ Object
Create integer “arithmetic right shift” (>>) operator.
-
.bin(name, type) ⇒ Object
Create bin expression of specified type.
-
.bin_exists(name) ⇒ Object
Create expression that returns if bin of specified name exists.
-
.bin_type(name) ⇒ Object
- Create expression that returns bin’s integer particle type
-
See ParticleType.
-
.blob_bin(name) ⇒ Object
Create bin expression.
-
.blob_val(val) ⇒ Object
Create blob byte value.
-
.bool_bin(name) ⇒ Object
Create boolean bin expression.
-
.bool_val(val) ⇒ Object
Create boolean value.
-
.ceil(num) ⇒ Object
Create expression that rounds a floating point number up to the closest integer value.
-
.cond(*exps) ⇒ Object
Conditionally select an expression from a variable number of expression pairs followed by default expression action.
-
.count(exp) ⇒ Object
Create expression that returns count of integer bits that are set to 1.
-
.def(name, value) ⇒ Object
Assign variable to a Exp#let(Exp…) expression that can be accessed later.
-
.device_size ⇒ Object
Create expression that returns record size on disk.
-
.digest_modulo(mod) ⇒ Object
Create expression that returns record digest modulo as integer.
-
.div(*exps) ⇒ Object
Create “divide” (/) operator that applies to a variable number of expressions.
-
.eq(left, right) ⇒ Object
Create equal (==) expression.
-
.exclusive(*exps) ⇒ Object
Create expression that returns true if only one of the expressions are true.
-
.float_bin(name) ⇒ Object
Create 64 bit float bin expression.
-
.float_val(val) ⇒ Object
Create 64 bit floating point value.
-
.floor(num) ⇒ Object
Create expression that rounds a floating point number down to the closest integer value.
-
.ge(left, right) ⇒ Object
Create greater than or equal (>=) operation.
-
.geo(val) ⇒ Object
Create geospatial json string value.
-
.geo_bin(name) ⇒ Object
Create geospatial bin expression.
-
.geo_compare(left, right) ⇒ Object
Create compare geospatial operation.
-
.gt(left, right) ⇒ Object
Create greater than (>) operation.
-
.hll_bin(name) ⇒ Object
Create hll bin expression.
-
.infinity_val ⇒ Object
Create Infinity value.
-
.int_and(*exps) ⇒ Object
Create integer “and” (&) operator that is applied to two or more integers.
-
.int_bin(name) ⇒ Object
Create 64 bit integer bin expression.
-
.int_not(exp) ⇒ Object
Create integer “not” (~) operator.
-
.int_or(*exps) ⇒ Object
Create integer “or” (|) operator that is applied to two or more integers.
-
.int_val(val) ⇒ Object
Create 64 bit integer value.
-
.int_xor(*exps) ⇒ Object
Create integer “xor” (^) operator that is applied to two or more integers.
-
.is_tombstone ⇒ Object
Create expression that returns if record has been deleted and is still in tombstone state.
-
.key(type) ⇒ Object
Create record key expression of specified type.
-
.key_exists ⇒ Object
Create expression that returns if the primary key is stored in the record meta data as a boolean expression.
-
.last_update ⇒ Object
Create expression that returns record last update time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch.
-
.le(left, right) ⇒ Object
Create less than or equals (<=) operation.
-
.let(*exps) ⇒ Object
Define variables and expressions in scope.
-
.list_bin(name) ⇒ Object
Create list bin expression.
-
.list_val(*list) ⇒ Object
Create list value.
-
.log(num, base) ⇒ Object
Create “log” operator for logarithm of “num” with base “base”.
-
.lscan(value, search) ⇒ Object
Create expression that scans integer bits from left (most significant bit) to right (least significant bit), looking for a search bit value.
-
.lshift(value, shift) ⇒ Object
Create integer “left shift” (<<) operator.
-
.lt(left, right) ⇒ Object
Create less than (<) operation.
-
.map_bin(name) ⇒ Object
Create map bin expression.
-
.map_val(map) ⇒ Object
Create map value.
-
.max(*exps) ⇒ Object
Create expression that returns the maximum value in a variable number of expressions.
-
.memory_size ⇒ Object
Create expression that returns record size in memory.
-
.min(*exps) ⇒ Object
Create expression that returns the minimum value in a variable number of expressions.
-
.mod(numerator, denominator) ⇒ Object
Create “modulo” (%) operator that determines the remainder of “numerator” divided by “denominator”.
-
.mul(*exps) ⇒ Object
Create “multiply” (*) operator that applies to a variable number of expressions.
-
.ne(left, right) ⇒ Object
Create not equal (!=) expression.
-
.nil_val ⇒ Object
Create nil value.
-
.not(exp) ⇒ Object
Create “not” operator expression.
-
.or(*exps) ⇒ Object
Create “or” (||) operator that applies to a variable number of expressions.
-
.pow(base, exponent) ⇒ Object
Create “power” operator that raises a “base” to the “exponent” power.
-
.record_size ⇒ Object
Create expression that returns the record size.
-
.regex_compare(regex, flags, bin) ⇒ Object
Create expression that performs a regex match on a string bin or string value expression.
-
.rscan(value, search) ⇒ Object
Create expression that scans integer bits from right (least significant bit) to left (most significant bit), looking for a search bit value.
-
.rshift(value, shift) ⇒ Object
Create integer “logical right shift” (>>>) operator.
-
.set_name ⇒ Object
Create expression that returns record set name string.
-
.since_update ⇒ Object
Create expression that returns milliseconds since the record was last updated.
-
.str_bin(name) ⇒ Object
Create string bin expression.
-
.str_val(val) ⇒ Object
Create string value.
-
.sub(*exps) ⇒ Object
Create “subtract” (-) operator that applies to a variable number of expressions.
-
.to_float(num) ⇒ Object
Create expression that converts an integer to a float.
-
.to_int(num) ⇒ Object
Create expression that converts a float to an integer.
-
.ttl ⇒ Object
Create expression that returns record expiration time (time to live) in integer seconds.
-
.unknown ⇒ Object
Create unknown value.
-
.var(name) ⇒ Object
Retrieve expression value from a variable.
-
.void_time ⇒ Object
Create expression that returns record expiration time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch.
-
.wildcard_val ⇒ Object
Create Wildcard value.
Instance Method Summary collapse
- #bytes ⇒ Object
-
#size ⇒ Object
Estimate expression size in wire protocol.
-
#write(buf, offset) ⇒ Object
Write expression in wire protocol.
Class Method Details
.abs(value) ⇒ Object
652 653 654 |
# File 'lib/aerospike/exp/exp.rb', line 652 def self.abs(value) CmdExp.new(ABS, value) end |
.add(*exps) ⇒ Object
Create “add” (+) operator that applies to a variable number of expressions. Return sum of all arguments. All arguments must resolve to the same type (or float). Requires server version 5.6.0+.
Examples
# a + b + c == 10
Exp.eq(
Exp.add(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
Exp.int_val(10))
556 557 558 |
# File 'lib/aerospike/exp/exp.rb', line 556 def self.add(*exps) CmdExp.new(ADD, *exps) end |
.and(*exps) ⇒ Object
462 463 464 |
# File 'lib/aerospike/exp/exp.rb', line 462 def self.and(*exps) CmdExp.new(AND, *exps) end |
.arshift(value, shift) ⇒ Object
787 788 789 |
# File 'lib/aerospike/exp/exp.rb', line 787 def self.arshift(value, shift) CmdExp.new(INT_ARSHIFT, value, shift) end |
.bin(name, type) ⇒ Object
119 120 121 |
# File 'lib/aerospike/exp/exp.rb', line 119 def self.bin(name, type) Bin.new(name, type) end |
.bin_exists(name) ⇒ Object
Create expression that returns if bin of specified name exists.
Examples
# Bin "a" exists in record
Exp.bin_exists("a")
212 213 214 |
# File 'lib/aerospike/exp/exp.rb', line 212 def self.bin_exists(name) Exp.ne(Exp.bin_type(name), Exp.int_val(0)) end |
.bin_type(name) ⇒ Object
- Create expression that returns bin’s integer particle type
-
See ParticleType.
Examples
# Bin "a" particle type is a list Exp.eq(Exp.bin_type("a"), Exp.val(ParticleType::LIST))
222 223 224 |
# File 'lib/aerospike/exp/exp.rb', line 222 def self.bin_type(name) CmdStr.new(BIN_TYPE, name) end |
.blob_bin(name) ⇒ Object
Create bin expression.
Examples
# Blob bin "a" == [1,2,3]
Exp.eq(Exp.blob_bin("a"), Exp.val(new {1, 2, 3}))
164 165 166 |
# File 'lib/aerospike/exp/exp.rb', line 164 def self.blob_bin(name) Bin.new(name, Type::BLOB) end |
.blob_val(val) ⇒ Object
Create blob byte value.
408 409 410 |
# File 'lib/aerospike/exp/exp.rb', line 408 def self.blob_val(val) Blob.new(val) end |
.bool_bin(name) ⇒ Object
155 156 157 |
# File 'lib/aerospike/exp/exp.rb', line 155 def self.bool_bin(name) Bin.new(name, Type::BOOL) end |
.bool_val(val) ⇒ Object
Create boolean value.
388 389 390 |
# File 'lib/aerospike/exp/exp.rb', line 388 def self.bool_val(val) Bool.new(val) end |
.ceil(num) ⇒ Object
676 677 678 |
# File 'lib/aerospike/exp/exp.rb', line 676 def self.ceil(num) CmdExp.new(CEIL, num) end |
.cond(*exps) ⇒ Object
Conditionally select an expression from a variable number of expression pairs followed by default expression action. Requires server version 5.6.0+.
Examples
Args Format: bool exp1, action exp1, bool exp2, action exp2, …, action-default
- # Apply operator based on type
-
Exp.cond(
Exp.eq(Exp.int_bin("type"), Exp.val(0)), Exp.add(Exp.int_bin("val1"), Exp.int_bin("val2")), Exp.eq(Exp.int_bin("type"), Exp.int_val(1)), Exp.sub(Exp.int_bin("val1"), Exp.int_bin("val2")), Exp.eq(Exp.int_bin("type"), Exp.val(2)), Exp.mul(Exp.int_bin("val1"), Exp.int_bin("val2")), Exp.val(-1))
877 878 879 |
# File 'lib/aerospike/exp/exp.rb', line 877 def self.cond(*exps) CmdExp.new(COND, *exps) end |
.count(exp) ⇒ Object
799 800 801 |
# File 'lib/aerospike/exp/exp.rb', line 799 def self.count(exp) CmdExp.new(INT_COUNT, exp) end |
.def(name, value) ⇒ Object
Assign variable to a Exp#let(Exp…) expression that can be accessed later. Requires server version 5.6.0+.
Examples
# 5 < a < 10 Exp.let(
Exp.def("x", Exp.int_bin("a")),
Exp.and(
Exp.lt(Exp.val(5), Exp.var("x")),
Exp.lt(Exp.var("x"), Exp.int_val(10))))
910 911 912 |
# File 'lib/aerospike/exp/exp.rb', line 910
def(name, value)
Def.new(name, value)
end
|
.device_size ⇒ Object
261 262 263 |
# File 'lib/aerospike/exp/exp.rb', line 261 def self.device_size Cmd.new(DEVICE_SIZE) end |
.digest_modulo(mod) ⇒ Object
338 339 340 |
# File 'lib/aerospike/exp/exp.rb', line 338 def self.digest_modulo(mod) CmdInt.new(DIGEST_MODULO, mod) end |
.div(*exps) ⇒ Object
Create “divide” (/) operator that applies to a variable number of expressions. If there is only one argument, returns the reciprocal for that argument. Otherwise, return the first argument divided by the product of the rest. All arguments must resolve to the same type (or float). Requires server version 5.6.0+.
Examples
# a / b / c > 1
Exp.gt(
Exp.div(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
Exp.int_val(1))
600 601 602 |
# File 'lib/aerospike/exp/exp.rb', line 600 def self.div(*exps) CmdExp.new(DIV, *exps) end |
.eq(left, right) ⇒ Object
494 495 496 |
# File 'lib/aerospike/exp/exp.rb', line 494 def self.eq(left, right) CmdExp.new(EQ, left, right) end |
.exclusive(*exps) ⇒ Object
485 486 487 |
# File 'lib/aerospike/exp/exp.rb', line 485 def self.exclusive(*exps) CmdExp.new(EXCLUSIVE, *exps) end |
.float_bin(name) ⇒ Object
137 138 139 |
# File 'lib/aerospike/exp/exp.rb', line 137 def self.float_bin(name) Bin.new(name, Type::FLOAT) end |
.float_val(val) ⇒ Object
Create 64 bit floating point value.
398 399 400 |
# File 'lib/aerospike/exp/exp.rb', line 398 def self.float_val(val) Float.new(val) end |
.floor(num) ⇒ Object
664 665 666 |
# File 'lib/aerospike/exp/exp.rb', line 664 def self.floor(num) CmdExp.new(FLOOR, num) end |
.ge(left, right) ⇒ Object
521 522 523 |
# File 'lib/aerospike/exp/exp.rb', line 521 def self.ge(left, right) CmdExp.new(GE, left, right) end |
.geo(val) ⇒ Object
Create geospatial json string value.
379 380 381 |
# File 'lib/aerospike/exp/exp.rb', line 379 def self.geo(val) Geo.new(val) end |
.geo_bin(name) ⇒ Object
Create geospatial bin expression.
Examples
# Geo bin "a" == region
String region = "{ \"type\": \"AeroCircle\", \"coordinates\": [[-122.0, 37.5], 50000.0] }"
Exp.geo_compare(Exp.geo_bin("loc"), Exp.geo(region))
174 175 176 |
# File 'lib/aerospike/exp/exp.rb', line 174 def self.geo_bin(name) Bin.new(name, Type::GEO) end |
.geo_compare(left, right) ⇒ Object
Create compare geospatial operation.
Examples
# Query region within coordinates.
region =
"{ " +
" \"type\": \"Polygon\", " +
" \"coordinates\": [ " +
" [[-122.500000, 37.000000],[-121.000000, 37.000000], " +
" [-121.000000, 38.080000],[-122.500000, 38.080000], " +
" [-122.500000, 37.000000]] " +
" ] " +
"}"
Exp.geo_compare(Exp.geo_bin("a"), Exp.geo(region))
374 375 376 |
# File 'lib/aerospike/exp/exp.rb', line 374 def self.geo_compare(left, right) CmdExp.new(GEO, left, right) end |
.gt(left, right) ⇒ Object
512 513 514 |
# File 'lib/aerospike/exp/exp.rb', line 512 def self.gt(left, right) CmdExp.new(GT, left, right) end |
.hll_bin(name) ⇒ Object
Create hll bin expression.
Examples
# HLL bin “a” count > 7 Exp.gt(HLLExp.get_count(Exp.hll_bin(“a”)), Exp.val(7))
203 204 205 |
# File 'lib/aerospike/exp/exp.rb', line 203 def self.hll_bin(name) Bin.new(name, Type::HLL) end |
.infinity_val ⇒ Object
Create Infinity value.
428 429 430 |
# File 'lib/aerospike/exp/exp.rb', line 428 def self.infinity_val Infinity.new end |
.int_and(*exps) ⇒ Object
713 714 715 |
# File 'lib/aerospike/exp/exp.rb', line 713 def self.int_and(*exps) CmdExp.new(INT_AND, *exps) end |
.int_bin(name) ⇒ Object
128 129 130 |
# File 'lib/aerospike/exp/exp.rb', line 128 def self.int_bin(name) Bin.new(name, Type::INT) end |
.int_not(exp) ⇒ Object
751 752 753 |
# File 'lib/aerospike/exp/exp.rb', line 751 def self.int_not(exp) CmdExp.new(INT_NOT, exp) end |
.int_or(*exps) ⇒ Object
726 727 728 |
# File 'lib/aerospike/exp/exp.rb', line 726 def self.int_or(*exps) CmdExp.new(INT_OR, *exps) end |
.int_val(val) ⇒ Object
Create 64 bit integer value.
393 394 395 |
# File 'lib/aerospike/exp/exp.rb', line 393 def self.int_val(val) Int.new(val) end |
.int_xor(*exps) ⇒ Object
739 740 741 |
# File 'lib/aerospike/exp/exp.rb', line 739 def self.int_xor(*exps) CmdExp.new(INT_XOR, *exps) end |
.is_tombstone ⇒ Object
Create expression that returns if record has been deleted and is still in tombstone state. This expression usually evaluates quickly because record meta data is cached in memory.
Examples
# Deleted records that are in tombstone state.
Exp.is_tombstone
328 329 330 |
# File 'lib/aerospike/exp/exp.rb', line 328 def self.is_tombstone Cmd.new(IS_TOMBSTONE) end |
.key(type) ⇒ Object
Create record key expression of specified type.
Examples
# Integer record key >= 100000 Exp.ge(Exp.key(Type::INT), Exp.int_val(100000))
94 95 96 |
# File 'lib/aerospike/exp/exp.rb', line 94 def self.key(type) CmdInt.new(KEY, type) end |
.key_exists ⇒ Object
Create expression that returns if the primary key is stored in the record meta data as a boolean expression. This would occur when Policy#send_key is true on record write. This expression usually evaluates quickly because record meta data is cached in memory.
Examples
# Key exists in record meta data
Exp.key_exists
106 107 108 |
# File 'lib/aerospike/exp/exp.rb', line 106 def self.key_exists Cmd.new(KEY_EXISTS) end |
.last_update ⇒ Object
Create expression that returns record last update time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch. This expression usually evaluates quickly because record meta data is cached in memory.
Examples
# Record last update time >= 2020-01-15
Exp.ge(Exp.last_update, Exp.val(new GregorianCalendar(2020, 0, 15)))
285 286 287 |
# File 'lib/aerospike/exp/exp.rb', line 285 def self.last_update Cmd.new(LAST_UPDATE) end |
.le(left, right) ⇒ Object
539 540 541 |
# File 'lib/aerospike/exp/exp.rb', line 539 def self.le(left, right) CmdExp.new(LE, left, right) end |
.let(*exps) ⇒ Object
Define variables and expressions in scope. Requires server version 5.6.0+.
Examples
Args Format: <def1>, <def2>, …, <exp> def: Exp) exp: Scoped expression
Examples
# 5 < a < 10 Exp.let(
Exp.def("x", Exp.int_bin("a")),
Exp.and(
Exp.lt(Exp.val(5), Exp.var("x")),
Exp.lt(Exp.var("x"), Exp.int_val(10))))
896 897 898 |
# File 'lib/aerospike/exp/exp.rb', line 896 def self.let(*exps) Let.new(exps) end |
.list_bin(name) ⇒ Object
183 184 185 |
# File 'lib/aerospike/exp/exp.rb', line 183 def self.list_bin(name) Bin.new(name, Type::LIST) end |
.list_val(*list) ⇒ Object
Create list value.
413 414 415 |
# File 'lib/aerospike/exp/exp.rb', line 413 def self.list_val(*list) ListVal.new(list) end |
.log(num, base) ⇒ Object
626 627 628 |
# File 'lib/aerospike/exp/exp.rb', line 626 def self.log(num, base) CmdExp.new(LOG, num, base) end |
.lscan(value, search) ⇒ Object
Create expression that scans integer bits from left (most significant bit) to right (least significant bit), looking for a search bit value. When the search value is found, the index of that bit (where the most significant bit is index 0) is returned. If “search” is true, the scan will search for the bit value 1. If “search” is false it will search for bit value 0. Requires server version 5.6.0+.
Examples
# lscan(a, true) == 4
Exp.eq(
Exp.lscan(Exp.int_bin("a"), Exp.val(true)),
Exp.val(4))
815 816 817 |
# File 'lib/aerospike/exp/exp.rb', line 815 def self.lscan(value, search) CmdExp.new(INT_LSCAN, value, search) end |
.lshift(value, shift) ⇒ Object
763 764 765 |
# File 'lib/aerospike/exp/exp.rb', line 763 def self.lshift(value, shift) CmdExp.new(INT_LSHIFT, value, shift) end |
.lt(left, right) ⇒ Object
530 531 532 |
# File 'lib/aerospike/exp/exp.rb', line 530 def self.lt(left, right) CmdExp.new(LT, left, right) end |
.map_bin(name) ⇒ Object
194 195 196 |
# File 'lib/aerospike/exp/exp.rb', line 194 def self.map_bin(name) Bin.new(name, Type::MAP) end |
.map_val(map) ⇒ Object
Create map value.
418 419 420 |
# File 'lib/aerospike/exp/exp.rb', line 418 def self.map_val(map) MapVal.new(map) end |
.max(*exps) ⇒ Object
857 858 859 |
# File 'lib/aerospike/exp/exp.rb', line 857 def self.max(*exps) CmdExp.new(MAX, *exps) end |
.memory_size ⇒ Object
Create expression that returns record size in memory. If server storage-engine is not memory nor data-in-memory, then zero is returned. This expression usually evaluates quickly because record meta data is cached in memory.
Requires server version 5.3.0+
Examples
# Record memory size >= 100 KB
Exp.ge(Exp.memory_size, Exp.int_val(100 * 1024))
274 275 276 |
# File 'lib/aerospike/exp/exp.rb', line 274 def self.memory_size Cmd.new(MEMORY_SIZE) end |
.min(*exps) ⇒ Object
844 845 846 |
# File 'lib/aerospike/exp/exp.rb', line 844 def self.min(*exps) CmdExp.new(MIN, *exps) end |
.mod(numerator, denominator) ⇒ Object
639 640 641 |
# File 'lib/aerospike/exp/exp.rb', line 639 def self.mod(numerator, denominator) CmdExp.new(MOD, numerator, denominator) end |
.mul(*exps) ⇒ Object
Create “multiply” (*) operator that applies to a variable number of expressions. Return the product of all arguments. If only one argument is supplied, return that argument. All arguments must resolve to the same type (or float). Requires server version 5.6.0+.
Examples
# a * b * c < 100
Exp.lt(
Exp.mul(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
Exp.int_val(100))
585 586 587 |
# File 'lib/aerospike/exp/exp.rb', line 585 def self.mul(*exps) CmdExp.new(MUL, *exps) end |
.ne(left, right) ⇒ Object
503 504 505 |
# File 'lib/aerospike/exp/exp.rb', line 503 def self.ne(left, right) CmdExp.new(NE, left, right) end |
.nil_val ⇒ Object
Create nil value.
423 424 425 |
# File 'lib/aerospike/exp/exp.rb', line 423 def self.nil_val Nil.new end |
.not(exp) ⇒ Object
449 450 451 |
# File 'lib/aerospike/exp/exp.rb', line 449 def self.not(exp) CmdExp.new(NOT, exp) end |
.or(*exps) ⇒ Object
473 474 475 |
# File 'lib/aerospike/exp/exp.rb', line 473 def self.or(*exps) CmdExp.new(OR, *exps) end |
.pow(base, exponent) ⇒ Object
613 614 615 |
# File 'lib/aerospike/exp/exp.rb', line 613 def self.pow(base, exponent) CmdExp.new(POW, base, exponent) end |
.record_size ⇒ Object
Create expression that returns the record size. This expression usually evaluates quickly because record meta data is cached in memory. Requires server version 7.0+. This expression replaces #deviceSize() and #memorySize() since those older expressions are equivalent on server version 7.0+.
{@code // Record size >= 100 KB Exp.ge(Exp.record_size(), Exp.val(100 * 1024)) }
235 236 237 |
# File 'lib/aerospike/exp/exp.rb', line 235 def self.record_size Cmd.new(RECORD_SIZE) end |
.regex_compare(regex, flags, bin) ⇒ Object
Create expression that performs a regex match on a string bin or string value expression.
Examples
# Select string bin “a” that starts with “prefix” and ends with “suffix”. # Ignore case and do not match newline. Exp.regex_compare(“prefix.*suffix”, RegexFlags.ICASE | RegexFlags.NEWLINE, Exp.str_bin(“a”))
352 353 354 |
# File 'lib/aerospike/exp/exp.rb', line 352 def self.regex_compare(regex, flags, bin) Regex.new(bin, regex, flags) end |
.rscan(value, search) ⇒ Object
Create expression that scans integer bits from right (least significant bit) to left (most significant bit), looking for a search bit value. When the search value is found, the index of that bit (where the most significant bit is index 0) is returned. If “search” is true, the scan will search for the bit value 1. If “search” is false it will search for bit value 0. Requires server version 5.6.0+.
Examples
# rscan(a, true) == 4
Exp.eq(
Exp.rscan(Exp.int_bin("a"), Exp.val(true)),
Exp.val(4))
831 832 833 |
# File 'lib/aerospike/exp/exp.rb', line 831 def self.rscan(value, search) CmdExp.new(INT_RSCAN, value, search) end |
.rshift(value, shift) ⇒ Object
775 776 777 |
# File 'lib/aerospike/exp/exp.rb', line 775 def self.rshift(value, shift) CmdExp.new(INT_RSHIFT, value, shift) end |
.set_name ⇒ Object
250 251 252 |
# File 'lib/aerospike/exp/exp.rb', line 250 def self.set_name Cmd.new(SET_NAME) end |
.since_update ⇒ Object
295 296 297 |
# File 'lib/aerospike/exp/exp.rb', line 295 def self.since_update Cmd.new(SINCE_UPDATE) end |
.str_bin(name) ⇒ Object
146 147 148 |
# File 'lib/aerospike/exp/exp.rb', line 146 def self.str_bin(name) Bin.new(name, Type::STRING) end |
.str_val(val) ⇒ Object
Create string value.
403 404 405 |
# File 'lib/aerospike/exp/exp.rb', line 403 def self.str_val(val) Str.new(val) end |
.sub(*exps) ⇒ Object
Create “subtract” (-) operator that applies to a variable number of expressions. If only one argument is provided, return the negation of that argument. Otherwise, return the sum of the 2nd to Nth argument subtracted from the 1st argument. All arguments must resolve to the same type (or float). Requires server version 5.6.0+.
Examples
# a - b - c > 10
Exp.gt(
Exp.sub(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
Exp.int_val(10))
571 572 573 |
# File 'lib/aerospike/exp/exp.rb', line 571 def self.sub(*exps) CmdExp.new(SUB, *exps) end |
.to_float(num) ⇒ Object
Create expression that converts an integer to a float. Requires server version 5.6.0+.
Examples
# float(2) == 2.0
Exp.eq(
Exp.to_float(Exp.val(2))),
Exp.val(2.0))
700 701 702 |
# File 'lib/aerospike/exp/exp.rb', line 700 def self.to_float(num) CmdExp.new(TO_FLOAT, num) end |
.to_int(num) ⇒ Object
688 689 690 |
# File 'lib/aerospike/exp/exp.rb', line 688 def self.to_int(num) CmdExp.new(TO_INT, num) end |
.unknown ⇒ Object
Create unknown value. Used to intentionally fail an expression. The failure can be ignored with Exp::WriteFlags#EVAL_NO_FAIL or Exp::ReadFlags#EVAL_NO_FAIL. Requires server version 5.6.0+.
Examples
# double v = balance - 100.0 # return (v > 0.0)? v : unknown Exp.let(
Exp.def("v", Exp.sub(Exp.float_bin("balance"), Exp.int_val(100.0))),
Exp.cond(
Exp.ge(Exp.var("v"), Exp.val(0.0)), Exp.var("v"),
Exp.unknown))
945 946 947 |
# File 'lib/aerospike/exp/exp.rb', line 945 def self.unknown Cmd.new(UNKNOWN) end |
.var(name) ⇒ Object
Retrieve expression value from a variable. Requires server version 5.6.0+.
Examples
# 5 < a < 10 Exp.let(
Exp.def("x", Exp.int_bin("a")),
Exp.and(
Exp.lt(Exp.val(5), Exp.var("x")),
Exp.lt(Exp.var("x"), Exp.int_val(10))))
924 925 926 |
# File 'lib/aerospike/exp/exp.rb', line 924 def self.var(name) CmdStr.new(VAR, name) end |
.void_time ⇒ Object
Create expression that returns record expiration time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch. This expression usually evaluates quickly because record meta data is cached in memory.
Examples
# Record expires on 2021-01-01
Exp.and(
Exp.ge(Exp.void_time, Exp.val(new GregorianCalendar(2021, 0, 1))),
Exp.lt(Exp.void_time, Exp.val(new GregorianCalendar(2021, 0, 2))))
308 309 310 |
# File 'lib/aerospike/exp/exp.rb', line 308 def self.void_time Cmd.new(VOID_TIME) end |
.wildcard_val ⇒ Object
Create Wildcard value.
433 434 435 |
# File 'lib/aerospike/exp/exp.rb', line 433 def self.wildcard_val Wildcard.new end |
Instance Method Details
#bytes ⇒ Object
966 967 968 969 970 971 972 973 974 |
# File 'lib/aerospike/exp/exp.rb', line 966 def bytes if @bytes.nil? Packer.use do |packer| pack(packer) @bytes = packer.bytes end end @bytes end |
#size ⇒ Object
Estimate expression size in wire protocol. For internal use only.
978 979 980 |
# File 'lib/aerospike/exp/exp.rb', line 978 def size bytes.length end |
#write(buf, offset) ⇒ Object
Write expression in wire protocol. For internal use only.
984 985 986 |
# File 'lib/aerospike/exp/exp.rb', line 984 def write(buf, offset) buf.write_binary(bytes, offset) end |