From 60759791939dc6db701107123bc3b3e867c408ff Mon Sep 17 00:00:00 2001 From: Khosrow Afroozeh Date: Wed, 24 Jul 2024 19:03:03 +0200 Subject: [PATCH] [CLIENT-3055] Remove Unsupported Server Features (Predexp and BatchDirect) --- Gemfile | 1 + README.md | 22 +- examples/pred_exp.rb | 206 ------- lib/aerospike.rb | 12 - lib/aerospike/client.rb | 77 +-- lib/aerospike/command/batch_direct_command.rb | 105 ---- .../command/batch_direct_exists_command.rb | 51 -- lib/aerospike/command/batch_direct_node.rb | 40 -- lib/aerospike/command/batch_index_command.rb | 16 +- lib/aerospike/command/command.rb | 92 +-- lib/aerospike/info.rb | 6 +- lib/aerospike/policy/batch_policy.rb | 7 +- lib/aerospike/policy/policy.rb | 41 +- lib/aerospike/query/pred_exp.rb | 192 ------- lib/aerospike/query/pred_exp/and_or.rb | 32 -- .../query/pred_exp/geo_json_value.rb | 41 -- lib/aerospike/query/pred_exp/integer_value.rb | 32 -- lib/aerospike/query/pred_exp/op.rb | 27 - lib/aerospike/query/pred_exp/regex.rb | 32 -- lib/aerospike/query/pred_exp/regex_flags.rb | 23 - lib/aerospike/query/pred_exp/string_value.rb | 29 - lib/aerospike/query/statement.rb | 26 +- spec/aerospike/batch_spec.rb | 70 +-- spec/aerospike/cdt/cdt_list_spec.rb | 96 ++-- spec/aerospike/exp/exp_bit_spec.rb | 2 +- spec/aerospike/exp/exp_hll_spec.rb | 2 +- spec/aerospike/exp/exp_list_spec.rb | 2 +- spec/aerospike/exp/exp_map_spec.rb | 2 +- spec/aerospike/exp/expression_spec.rb | 154 ++--- spec/aerospike/pred_exp_spec.rb | 536 ------------------ spec/aerospike/predexp_ops_spec.rb | 329 ----------- spec/aerospike/udf_spec.rb | 10 +- spec/support/utils.rb | 55 +- 33 files changed, 251 insertions(+), 2117 deletions(-) delete mode 100644 examples/pred_exp.rb delete mode 100644 lib/aerospike/command/batch_direct_command.rb delete mode 100644 lib/aerospike/command/batch_direct_exists_command.rb delete mode 100644 lib/aerospike/command/batch_direct_node.rb delete mode 100644 lib/aerospike/query/pred_exp.rb delete mode 100644 lib/aerospike/query/pred_exp/and_or.rb delete mode 100644 lib/aerospike/query/pred_exp/geo_json_value.rb delete mode 100644 lib/aerospike/query/pred_exp/integer_value.rb delete mode 100644 lib/aerospike/query/pred_exp/op.rb delete mode 100644 lib/aerospike/query/pred_exp/regex.rb delete mode 100644 lib/aerospike/query/pred_exp/regex_flags.rb delete mode 100644 lib/aerospike/query/pred_exp/string_value.rb delete mode 100644 spec/aerospike/pred_exp_spec.rb delete mode 100644 spec/aerospike/predexp_ops_spec.rb diff --git a/Gemfile b/Gemfile index 084d1765..ad605391 100644 --- a/Gemfile +++ b/Gemfile @@ -17,6 +17,7 @@ group :development do gem "rubocop-rspec", require: false end +gem "base64" gem "bcrypt" gem "msgpack", "~> 1.2" gem "rake" diff --git a/README.md b/README.md index 55ea697b..8f75d441 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,18 @@ An Aerospike library for Ruby. This library is compatible with Ruby 2.3+ and supports Linux, Mac OS X and various other BSDs. -- [Usage](#Usage) -- [Prerequisites](#Prerequisites) -- [Installation](#Installation) -- [Benchmarks](#Benchmarks) -- [API Documentaion](#API-Documentation) -- [Tests](#Tests) -- [Examples](#Examples) - - [Tools](#Tools) +- [Aerospike Ruby Client ](#aerospike-ruby-client---) + - [Usage:](#usage) + - [Prerequisites](#prerequisites) + - [Installation](#installation) + - [Installation from Ruby gems](#installation-from-ruby-gems) + - [Installation from source](#installation-from-source) + - [Tests](#tests) + - [Examples](#examples) + - [Tools](#tools) + - [Benchmarks](#benchmarks) + - [API Documentation](#api-documentation) + - [License](#license) ## Usage: @@ -97,7 +101,7 @@ This library is packaged with a number of tests. To run all the test cases: - $ AEROSPIKE_HOSTS="[,]" AEROSPIKE_USER="" AEROSPIKE_PASSWORD="" bundle exec rspec + $ AEROSPIKE_HOSTS="[,]" AEROSPIKE_USER="" AEROSPIKE_PASSWORD="" bundle exec rspec ## Examples diff --git a/examples/pred_exp.rb b/examples/pred_exp.rb deleted file mode 100644 index 647d9ad5..00000000 --- a/examples/pred_exp.rb +++ /dev/null @@ -1,206 +0,0 @@ -# frozen_string_literal: true - -require "rubygems" -require "aerospike" -require './shared/shared' - -include Aerospike -include Shared - -def main - Shared.init - setup(Shared.client) - teardown(Shared.client) - - run_integer_predexp_example(Shared.client) - run_string_predexp_example(Shared.client) - run_regex_predexp_example(Shared.client) - run_mapval_predexp_example(Shared.client) - run_list_predexp_example(Shared.client) - run_geojson_predexp_example(Shared.client) - run_void_time_predexp_example(Shared.client) - - Shared.logger.info("Example finished successfully.") -end - -def setup(client) - records = 100 - Shared.logger.info("Creating #{records} records with random properties.") - records.times do |idx| - key = Key.new(Shared.namespace, Shared.set_name, "user#{idx}") - record = { - 'name' => %w[Timmy Alice John Arthur Mike Diana Emily Laura Nicole].sample + "_#{idx}", - 'race' => %w[Squid Octopus].sample, - 'level' => rand(1..100), - 'rank' => ['C-', 'C', 'C+', 'B-', 'B', 'B+', 'A-', 'A', 'A+', 'S', 'S+', 'X'].sample, - 'gear' => { - 'clothes' => ['Green Hoodie', 'White Tee', 'Blue Jersey', 'Black Tee', 'Mountain Coat'].sample - }, - 'weapons' => ['Water Gun', 'Paint Roller', 'Paintbrush', 'Aerospray', 'Bucket'].sample(3), - 'loc' => GeoJSON.new(type: 'Point', coordinates: [(3 + (idx * 0.003)), (4 + (idx * 0.003))]) - } - client.put(key, record, ttl: (idx + 1) * 5) - end - - task = client.create_index(Shared.namespace, Shared.set_name, "name_index", "name", :string) - task.wait_till_completed or fail "Could not create secondary 'name' index" - - task = client.create_index(Shared.namespace, Shared.set_name, "level_index", "level", :numeric) - task.wait_till_completed or fail "Could not create secondary 'level' index" - - task = client.create_index(Shared.namespace, Shared.set_name, "loc_index", "loc", :geo2dsphere) - task.wait_till_completed or fail "Could not create secondary 'loc' index" -end - -def teardown(client) - client.drop_index(Shared.namespace, Shared.set_name, "name_index") - client.drop_index(Shared.namespace, Shared.set_name, "level_index") - client.drop_index(Shared.namespace, Shared.set_name, "loc_index") -end - -def run_integer_predexp_example(client) - Shared.logger.info("Querying set using predicate expressions to return users with level > 30") - - statement = Statement.new(Shared.namespace, Shared.set_name) - statement.predexp = [ - PredExp.integer_bin('level'), - PredExp.integer_value(30), - PredExp.integer_greater - ] - - records = client.query(statement) - results = [] - records.each do |r| - results << r.bins['name'] - end - - Shared.logger.info("Found #{results.length} records with level > 30.") -end - -def run_string_predexp_example(client) - Shared.logger.info("Querying set using predicate expressions to return Squids") - - statement = Statement.new(Shared.namespace, Shared.set_name) - statement.predexp = [ - PredExp.string_bin('race'), - PredExp.string_value('Squid'), - PredExp.string_equal - ] - - records = client.query(statement) - results = [] - records.each do |r| - results << r.bins['name'] - end - - Shared.logger.info("Found #{results.length} Squids.") -end - -def run_regex_predexp_example(client) - Shared.logger.info("Querying set using predicate expressions to return B rank users") - - statement = Statement.new(Shared.namespace, Shared.set_name) - statement.predexp = [ - PredExp.string_bin('rank'), - PredExp.string_value('B'), - PredExp.string_regex(PredExp::RegexFlags::NONE) - ] - - records = client.query(statement) - results = [] - records.each do |r| - results << r.bins['name'] - end - - Shared.logger.info("Found #{results.length} users with B rank.") -end - -def run_mapval_predexp_example(client) - Shared.logger.info("Querying set using predicate expressions to return all users wearing White Tees") - - statement = Statement.new(Shared.namespace, Shared.set_name) - statement.predexp = [ - PredExp.string_value('White Tee'), - PredExp.string_var('x'), - PredExp.string_equal, - PredExp.map_bin('gear'), - PredExp.mapval_iterate_or('x') - ] - - records = client.query(statement) - results = [] - records.each do |r| - results << r.bins['name'] - end - - Shared.logger.info("Found #{results.length} users wearing White Tees.") -end - -def run_list_predexp_example(client) - Shared.logger.info("Querying set using predicate expressions to return users using buckets") - - statement = Statement.new(Shared.namespace, Shared.set_name) - statement.predexp = [ - PredExp.string_value('Bucket'), - PredExp.string_var('x'), - PredExp.string_equal, - PredExp.list_bin('weapons'), - PredExp.list_iterate_or('x') - ] - - records = client.query(statement) - results = [] - records.each do |r| - results << r.bins['name'] - end - - Shared.logger.info("Found #{results.length} users using buckets.") -end - -def run_geojson_predexp_example(client) - Shared.logger.info("Querying set using predicate expressions to return users in range of circle") - - circle_range = 1_000 - # circle with range of 1000 meters - circle = GeoJSON.new(type: 'AeroCircle', coordinates: [[3,4], circle_range]) - - statement = Statement.new(Shared.namespace, Shared.set_name) - statement.predexp = [ - PredExp.geojson_bin('loc'), - PredExp.geojson_value(circle), - PredExp.geojson_contains - ] - - records = client.query(statement) - results = [] - records.each do |r| - results << r.bins['name'] - end - - Shared.logger.info("Found #{results.length} users in a circle.") -end - -def run_void_time_predexp_example(client) - Shared.logger.info("Querying set using predicate expressions to return records expiring in less than a minute") - - minute_from_now = Time.now + 60 - # Provided time must be an Epoch in nanoseconds - minute_from_now = ("%10.9f" % minute_from_now.to_f).gsub('.', '').to_i - - statement = Statement.new(Shared.namespace, Shared.set_name) - statement.predexp = [ - Aerospike::PredExp.integer_value(minute_from_now), - Aerospike::PredExp.void_time, - Aerospike::PredExp.integer_greater - ] - - records = client.query(statement) - results = [] - records.each do |r| - results << r.bins['name'] - end - - Shared.logger.info("Found #{results.length} records expiring in less than a minute.") -end - -main diff --git a/lib/aerospike.rb b/lib/aerospike.rb index 17c1939f..b1323ce4 100644 --- a/lib/aerospike.rb +++ b/lib/aerospike.rb @@ -43,7 +43,6 @@ require "aerospike/value/particle_type" require "aerospike/value/value" require "aerospike/command/single_command" -require "aerospike/command/batch_direct_node" require "aerospike/command/batch_index_node" require "aerospike/command/field_type" require "aerospike/command/command" @@ -53,8 +52,6 @@ require "aerospike/command/operate_command" require "aerospike/command/exists_command" require "aerospike/command/multi_command" -require "aerospike/command/batch_direct_command" -require "aerospike/command/batch_direct_exists_command" require "aerospike/command/batch_index_command" require "aerospike/command/batch_index_exists_command" require "aerospike/command/read_header_command" @@ -160,7 +157,6 @@ require "aerospike/query/query_command" require "aerospike/query/scan_command" require "aerospike/query/statement" -require "aerospike/query/pred_exp" require "aerospike/query/partition_tracker" require "aerospike/query/partition_status" require "aerospike/query/partition_filter" @@ -178,14 +174,6 @@ require "aerospike/exp/exp_hll" require "aerospike/exp/operation" -require "aerospike/query/pred_exp/and_or" -require "aerospike/query/pred_exp/geo_json_value" -require "aerospike/query/pred_exp/integer_value" -require "aerospike/query/pred_exp/op" -require "aerospike/query/pred_exp/regex" -require "aerospike/query/pred_exp/regex_flags" -require "aerospike/query/pred_exp/string_value" - module Aerospike extend Loggable end diff --git a/lib/aerospike/client.rb b/lib/aerospike/client.rb index 1b56c9c3..d3a8fa1c 100644 --- a/lib/aerospike/client.rb +++ b/lib/aerospike/client.rb @@ -36,15 +36,7 @@ module Aerospike # +:fail_if_not_connected+ set to true class Client - attr_accessor :default_admin_policy - attr_accessor :default_batch_policy - attr_accessor :default_info_policy - attr_accessor :default_query_policy - attr_accessor :default_read_policy - attr_accessor :default_scan_policy - attr_accessor :default_write_policy - attr_accessor :default_operate_policy - attr_accessor :cluster + attr_accessor :default_admin_policy, :default_batch_policy, :default_info_policy, :default_query_policy, :default_read_policy, :default_scan_policy, :default_write_policy, :default_operate_policy, :cluster def initialize(hosts = nil, policy: ClientPolicy.new, connect: true) hosts = ::Aerospike::Host::Parse.(hosts || ENV["AEROSPIKE_HOSTS"] || "localhost") @@ -230,11 +222,11 @@ def truncate(namespace, set_name = nil, before_last_update = nil, options = {}) str_cmd = "truncate:namespace=#{namespace}" str_cmd << ";set=#{set_name}" unless set_name.to_s.strip.empty? else - if node.supports_feature?(Aerospike::Features::TRUNCATE_NAMESPACE) - str_cmd = "truncate-namespace:namespace=#{namespace}" - else - str_cmd = "truncate:namespace=#{namespace}" - end + str_cmd = if node.supports_feature?(Aerospike::Features::TRUNCATE_NAMESPACE) + "truncate-namespace:namespace=#{namespace}" + else + "truncate:namespace=#{namespace}" + end end if before_last_update @@ -329,15 +321,8 @@ def batch_get(keys, bin_names = nil, options = nil) bin_names = nil end - if policy.use_batch_direct - key_map = BatchItem.generate_map(keys) - execute_batch_direct_commands(policy, keys) do |node, batch| - BatchDirectCommand.new(node, batch, policy, key_map, bin_names, results, info_flags) - end - else - execute_batch_index_commands(policy, keys) do |node, batch| - BatchIndexCommand.new(node, batch, policy, bin_names, results, info_flags) - end + execute_batch_index_commands(policy, keys) do |node, batch| + BatchIndexCommand.new(node, batch, policy, bin_names, results, info_flags) end results @@ -358,15 +343,8 @@ def batch_exists(keys, options = nil) policy = create_policy(options, BatchPolicy, default_batch_policy) results = Array.new(keys.length) - if policy.use_batch_direct - key_map = BatchItem.generate_map(keys) - execute_batch_direct_commands(policy, keys) do |node, batch| - BatchDirectExistsCommand.new(node, batch, policy, key_map, results) - end - else - execute_batch_index_commands(policy, keys) do |node, batch| - BatchIndexExistsCommand.new(node, batch, policy, results) - end + execute_batch_index_commands(policy, keys) do |node, batch| + BatchIndexExistsCommand.new(node, batch, policy, results) end results @@ -430,7 +408,7 @@ def register_udf(udf_body, server_path, language, options = nil) end if res["error"] - raise Aerospike::Exceptions::CommandRejected.new("Registration failed: #{res["error"]}\nFile: #{res["file"]}\nLine: #{res["line"]}\nMessage: #{res["message"]}") + raise Aerospike::Exceptions::CommandRejected.new("Registration failed: #{res['error']}\nFile: #{res['file']}\nLine: #{res['line']}\nMessage: #{res['message']}") end UdfRegisterTask.new(@cluster, server_path) @@ -566,7 +544,8 @@ def execute_udf_on_query(statement, package_name, function_name, function_args = # ctx is an optional list of context. Supported on server v6.1+. def create_index(namespace, set_name, index_name, bin_name, index_type, collection_type = nil, options = nil, ctx: nil) if options.nil? && collection_type.is_a?(Hash) - options, collection_type = collection_type, nil + options = collection_type + collection_type = nil end policy = create_policy(options, Policy, default_info_policy) @@ -943,13 +922,11 @@ def create_policy(policy, policy_klass, default_policy = nil) when Hash policy_klass.new(policy) else - fail TypeError, "policy should be a #{policy_klass.name} instance or a Hash" + raise TypeError, "policy should be a #{policy_klass.name} instance or a Hash" end end - def cluster=(cluster) - @cluster = cluster - end + attr_writer :cluster def cluster_config_changed(cluster) Aerospike.logger.debug { "Cluster config change detected; active nodes: #{cluster.nodes.map(&:name)}" } @@ -998,29 +975,5 @@ def execute_batch_index_commands(policy, keys) threads.each(&:join) end - - def execute_batch_direct_commands(policy, keys) - if @cluster.nodes.empty? - raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_NOT_AVAILABLE, "Executing Batch Direct command failed because cluster is empty.") - end - - batch_nodes = BatchDirectNode.generate_list(@cluster, policy.replica, keys) - threads = [] - - # Use a thread per namespace per node - batch_nodes.each do |batch_node| - # copy to avoid race condition - bn = batch_node - bn.batch_namespaces.each do |batch| - threads << Thread.new do - Thread.current.abort_on_exception = true - command = yield batch_node.node, batch - execute_command(command) - end - end - end - - threads.each(&:join) - end end # class end # module diff --git a/lib/aerospike/command/batch_direct_command.rb b/lib/aerospike/command/batch_direct_command.rb deleted file mode 100644 index 3c96d82e..00000000 --- a/lib/aerospike/command/batch_direct_command.rb +++ /dev/null @@ -1,105 +0,0 @@ -# Copyright 2014-2020 Aerospike, Inc. -# -# Portions may be licensed to Aerospike, Inc. under one or more contributor -# license agreements. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -require 'aerospike/command/multi_command' - -module Aerospike - - class BatchDirectCommand < MultiCommand #:nodoc: - - attr_accessor :batch - attr_accessor :policy - attr_accessor :key_map - attr_accessor :bin_names - attr_accessor :results - attr_accessor :read_attr - - def initialize(node, batch, policy, key_map, bin_names, results, read_attr) - super(node) - - @batch = batch - @policy = policy - @key_map = key_map - @bin_names = bin_names - @results = results - @read_attr = read_attr - end - - def write_buffer - # Estimate buffer size - begin_cmd - byte_size = batch.keys.length * DIGEST_SIZE - - @data_offset += batch.namespace.bytesize + - FIELD_HEADER_SIZE + byte_size + FIELD_HEADER_SIZE - - if bin_names - bin_names.each do |bin_name| - estimate_operation_size_for_bin_name(bin_name) - end - end - - size_buffer - - operation_count = 0 - if bin_names - operation_count = bin_names.length - end - - write_header_read(policy, read_attr, 0, 2, operation_count) - write_field_string(batch.namespace, Aerospike::FieldType::NAMESPACE) - write_field_header(byte_size, Aerospike::FieldType::DIGEST_RIPE_ARRAY) - - batch.keys.each do |key| - @data_offset += @data_buffer.write_binary(key.digest, @data_offset) - end - - if bin_names - bin_names.each do |bin_name| - write_operation_for_bin_name(bin_name, Aerospike::Operation::READ) - end - end - - end_cmd - mark_compressed(@policy) - end - - # Parse all results in the batch. Add records to shared list. - # If the record was not found, the bins will be nil. - def parse_row(result_code) - generation = @data_buffer.read_int32(6) - expiration = @data_buffer.read_int32(10) - field_count = @data_buffer.read_int16(18) - op_count = @data_buffer.read_int16(20) - - key = parse_key(field_count) - - item = key_map[key.digest] - if item - if result_code == 0 - index = item.index - key = item.key - results[index] = parse_record(key, op_count, generation, expiration) - end - else - Aerospike.logger.warn("Unexpected batch key returned: #{key}") - end - end - - end # class - -end # module diff --git a/lib/aerospike/command/batch_direct_exists_command.rb b/lib/aerospike/command/batch_direct_exists_command.rb deleted file mode 100644 index 803af8c9..00000000 --- a/lib/aerospike/command/batch_direct_exists_command.rb +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2014-2020 Aerospike, Inc. -# -# Portions may be licensed to Aerospike, Inc. under one or more contributor -# license agreements. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -require 'aerospike/command/batch_direct_command' - -module Aerospike - - class BatchDirectExistsCommand < BatchDirectCommand #:nodoc: - - def initialize(node, batch, policy, key_map, results) - super(node, batch, policy, key_map, nil, results, INFO1_READ | INFO1_NOBINDATA) - end - - # Parse all results in the batch. Add records to shared list. - # If the record was not found, the bins will be nil. - def parse_row(result_code) - field_count = @data_buffer.read_int16(18) - op_count = @data_buffer.read_int16(20) - - if op_count > 0 - raise Aerospike::Exceptions::Parse.new('Received bins that were not requested!') - end - - key = parse_key(field_count) - item = key_map[key.digest] - - if item - index = item.index - results[index] = (result_code == 0) - else - Aerospike::logger.debug("Unexpected batch key returned: #{key.namespace}, #{key.digest}") - end - end - - end # class - -end # module diff --git a/lib/aerospike/command/batch_direct_node.rb b/lib/aerospike/command/batch_direct_node.rb deleted file mode 100644 index dc1aab56..00000000 --- a/lib/aerospike/command/batch_direct_node.rb +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2014-2020 Aerospike, Inc. -# -# Portions may be licensed to Aerospike, Inc. under one or more contributor -# license agreements. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -module Aerospike - - BatchNamespace = Struct.new :namespace, :keys - - class BatchDirectNode #:nodoc: - - attr_accessor :node - attr_accessor :batch_namespaces - - def self.generate_list(cluster, replica_policy, keys) - keys.group_by { |key| cluster.get_node_for_key(replica_policy, key) } - .map { |node, keys_for_node| BatchDirectNode.new(node, keys_for_node) } - end - - def initialize(node, keys) - @node = node - @batch_namespaces = keys.group_by(&:namespace) - .map { |ns, keys_for_ns| BatchNamespace.new(ns, keys_for_ns) } - end - - end - -end diff --git a/lib/aerospike/command/batch_index_command.rb b/lib/aerospike/command/batch_index_command.rb index 65835279..495e52f5 100644 --- a/lib/aerospike/command/batch_index_command.rb +++ b/lib/aerospike/command/batch_index_command.rb @@ -21,11 +21,7 @@ module Aerospike class BatchIndexCommand < MultiCommand #:nodoc: - attr_accessor :batch - attr_accessor :policy - attr_accessor :bin_names - attr_accessor :results - attr_accessor :read_attr + attr_accessor :batch, :policy, :bin_names, :results, :read_attr def initialize(node, batch, policy, bin_names, results, read_attr) super(node) @@ -42,8 +38,8 @@ def write_buffer field_count_row = 1 field_count = 1 - predexp_size = estimate_predexp(@policy.predexp) - field_count += 1 if predexp_size > 0 + exp_size = estimate_expression_size(@policy.filter_exp) + field_count += 1 if exp_size > 0 if bin_names bin_names.each do |bin_name| @@ -58,7 +54,7 @@ def write_buffer batch.keys.each do |key| @data_offset += key.digest.length + 4 # 4 byte batch offset - if prev != nil && prev.namespace == key.namespace + if !prev.nil? && prev.namespace == key.namespace @data_offset += 1 else @data_offset += key.namespace.bytesize + FIELD_HEADER_SIZE + 1 + 1 + 2 + 2 # repeat/no-repeat flag + read_attr flags + field_count + operation_count @@ -68,7 +64,7 @@ def write_buffer size_buffer write_header_read(policy, read_attr | INFO1_BATCH, 0, field_count, 0) - write_predexp(@policy.predexp, predexp_size) + write_filter_exp(@policy.filter_exp, exp_size) write_field_header(0, Aerospike::FieldType::BATCH_INDEX) @data_offset += @data_buffer.write_int32(batch.keys.length, @data_offset) @@ -80,7 +76,7 @@ def write_buffer @data_offset += @data_buffer.write_int32(index, @data_offset) @data_offset += @data_buffer.write_binary(key.digest, @data_offset) - if (prev != nil && prev.namespace == key.namespace) + if !prev.nil? && prev.namespace == key.namespace @data_offset += @data_buffer.write_byte(1, @data_offset) else @data_offset += @data_buffer.write_byte(0, @data_offset) diff --git a/lib/aerospike/command/command.rb b/lib/aerospike/command/command.rb index 4bedc891..05807a3d 100644 --- a/lib/aerospike/command/command.rb +++ b/lib/aerospike/command/command.rb @@ -112,9 +112,6 @@ def set_write(policy, operation, key, bins) begin_cmd field_count = estimate_key_size(key, policy) - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(@policy.filter_exp) field_count += 1 if exp_size > 0 @@ -126,7 +123,6 @@ def set_write(policy, operation, key, bins) write_header_write(policy, INFO2_WRITE, field_count, bins.length) write_key(key, policy) - write_predexp(policy.predexp, predexp_size) write_filter_exp(@policy.filter_exp, exp_size) bins.each do |bin| @@ -142,16 +138,12 @@ def set_delete(policy, key) begin_cmd field_count = estimate_key_size(key) - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(@policy.filter_exp) field_count += 1 if exp_size > 0 size_buffer - write_header_write(policy, INFO2_WRITE | INFO2_DELETE, field_count, 0) + write_header_write(policy, INFO2_WRITE | INFO2_DELETE, field_count, 0) write_key(key) - write_predexp(policy.predexp, predexp_size) write_filter_exp(@policy.filter_exp, exp_size) end_cmd end @@ -161,17 +153,13 @@ def set_touch(policy, key) begin_cmd field_count = estimate_key_size(key) - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(@policy.filter_exp) field_count += 1 if exp_size > 0 estimate_operation_size size_buffer - write_header_write(policy, INFO2_WRITE, field_count, 1) + write_header_write(policy, INFO2_WRITE, field_count, 1) write_key(key) - write_predexp(policy.predexp, predexp_size) write_filter_exp(@policy.filter_exp, exp_size) write_operation_for_operation_type(Aerospike::Operation::TOUCH) end_cmd @@ -182,16 +170,12 @@ def set_exists(policy, key) begin_cmd field_count = estimate_key_size(key) - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(@policy.filter_exp) field_count += 1 if exp_size > 0 size_buffer write_header_read_header(policy, INFO1_READ | INFO1_NOBINDATA, field_count, 0) write_key(key) - write_predexp(policy.predexp, predexp_size) write_filter_exp(@policy.filter_exp, exp_size) end_cmd end @@ -201,16 +185,12 @@ def set_read_for_key_only(policy, key) begin_cmd field_count = estimate_key_size(key) - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(@policy.filter_exp) field_count += 1 if exp_size > 0 size_buffer write_header_read(policy, INFO1_READ | INFO1_GET_ALL, 0, field_count, 0) write_key(key) - write_predexp(policy.predexp, predexp_size) write_filter_exp(@policy.filter_exp, exp_size) end_cmd end @@ -221,9 +201,6 @@ def set_read(policy, key, bin_names) begin_cmd field_count = estimate_key_size(key) - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(@policy.filter_exp) field_count += 1 if exp_size > 0 @@ -239,7 +216,6 @@ def set_read(policy, key, bin_names) write_header_read(policy, attr, 0, field_count, bin_names.length) write_key(key) - write_predexp(policy.predexp, predexp_size) write_filter_exp(@policy.filter_exp, exp_size) bin_names.each do |bin_name| @@ -258,9 +234,6 @@ def set_read_header(policy, key) begin_cmd field_count = estimate_key_size(key) - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(@policy.filter_exp) field_count += 1 if exp_size > 0 @@ -273,7 +246,6 @@ def set_read_header(policy, key) write_header_read_header(policy, INFO1_READ|INFO1_NOBINDATA, field_count, 0) write_key(key) - write_predexp(policy.predexp, predexp_size) write_filter_exp(@policy.filter_exp, exp_size) end_cmd mark_compressed(policy) @@ -284,9 +256,6 @@ def set_operate(policy, key, args) begin_cmd field_count = estimate_key_size(key, policy) - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(policy.filter_exp) field_count += 1 if exp_size > 0 @@ -296,7 +265,6 @@ def set_operate(policy, key, args) write_header_read_write(policy, args.read_attr, args.write_attr, field_count, args.operations.length) write_key(key, policy) - write_predexp(policy.predexp, predexp_size) write_filter_exp(policy.filter_exp, exp_size) args.operations.each do |operation| @@ -311,9 +279,6 @@ def set_udf(policy, key, package_name, function_name, args) begin_cmd field_count = estimate_key_size(key, policy) - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(@policy.filter_exp) field_count += 1 if exp_size > 0 @@ -324,7 +289,6 @@ def set_udf(policy, key, package_name, function_name, args) write_header_write(policy, INFO2_WRITE, field_count, 0) write_key(key, policy) - write_predexp(policy.predexp, predexp_size) write_filter_exp(@policy.filter_exp, exp_size) write_field_string(package_name, Aerospike::FieldType::UDF_PACKAGE_NAME) write_field_string(function_name, Aerospike::FieldType::UDF_FUNCTION) @@ -373,9 +337,6 @@ def set_scan(cluster, policy, namespace, set_name, bin_names, node_partitions) field_count += 1 end - predexp_size = estimate_predexp(policy.predexp) - field_count += 1 if predexp_size > 0 - exp_size = estimate_expression_size(@policy.filter_exp) field_count += 1 if exp_size > 0 @@ -446,7 +407,6 @@ def set_scan(cluster, policy, namespace, set_name, bin_names, node_partitions) write_field_int(policy.records_per_second, Aerospike::FieldType::RECORDS_PER_SECOND) end - write_predexp(policy.predexp, predexp_size) write_filter_exp(@policy.filter_exp, exp_size) # write_field_header(2, Aerospike::FieldType::SCAN_OPTIONS) @@ -475,7 +435,6 @@ def set_scan(cluster, policy, namespace, set_name, bin_names, node_partitions) end_cmd end - def set_query(cluster, policy, statement, background, node_partitions) function_arg_buffer = nil field_count = 0 @@ -525,7 +484,7 @@ def set_query(cluster, policy, statement, background, node_partitions) # Estimate INDEX_RANGE field. @data_offset += FIELD_HEADER_SIZE - filter_size += 1 # num filters + filter_size += 1 # num filters filter_size += filter.estimate_size @data_offset += filter_size @@ -539,14 +498,6 @@ def set_query(cluster, policy, statement, background, node_partitions) end statement.set_task_id - predexp = policy.predexp || statement.predexp - - if predexp - @data_offset += FIELD_HEADER_SIZE - pred_size = Aerospike::PredExp.estimate_size(predexp) - @data_offset += pred_size - field_count += 1 - end unless policy.filter_exp.nil? exp_size = estimate_expression_size(policy.filter_exp) @@ -656,13 +607,6 @@ def set_query(cluster, policy, statement, background, node_partitions) # Write task_id field write_field_int64(statement.task_id, FieldType::TRAN_ID) - unless predexp.nil? - write_field_header(pred_size, Aerospike::FieldType::PREDEXP) - @data_offset = Aerospike::PredExp.write( - predexp, @data_buffer, @data_offset - ) - end - if filter type = filter.collection_type @@ -725,7 +669,6 @@ def set_query(cluster, policy, statement, background, node_partitions) end_cmd end - def execute iterations = 0 @@ -752,7 +695,7 @@ def execute # Socket connection error has occurred. Decrease health and retry. @node.decrease_health - Aerospike.logger.error("Node #{@node.to_s}: #{e}") + Aerospike.logger.error("Node #{@node}: #{e}") else Aerospike.logger.error("No node available for transaction: #{e}") end @@ -785,7 +728,7 @@ def execute # Close socket to flush out possible garbage. Do not put back in pool. @conn.close if @conn - Aerospike.logger.error("Node #{@node.to_s}: #{e}") + Aerospike.logger.error("Node #{@node}: #{e}") # IO error means connection to server @node is unhealthy. # Reflect cmd status. @node.decrease_health @@ -853,14 +796,14 @@ def estimate_key_size(key, policy = nil) field_count += 1 end - return field_count + field_count end def estimate_udf_size(package_name, function_name, bytes) @data_offset += package_name.bytesize + FIELD_HEADER_SIZE @data_offset += function_name.bytesize + FIELD_HEADER_SIZE @data_offset += bytes.bytesize + FIELD_HEADER_SIZE - return 3 + 3 end def estimate_operation_size_for_bin(bin) @@ -890,16 +833,6 @@ def estimate_operation_size @data_offset += OPERATION_HEADER_SIZE end - def estimate_predexp(predexp) - if predexp && !predexp.empty? - @data_offset += FIELD_HEADER_SIZE - sz = Aerospike::PredExp.estimate_size(predexp) - @data_offset += sz - return sz - end - return 0 - end - def estimate_expression_size(exp) unless exp.nil? @data_offset += FIELD_HEADER_SIZE @@ -1199,15 +1132,6 @@ def write_field_header(size, ftype) @data_offset += 1 end - def write_predexp(predexp, predexp_size) - if predexp && !predexp.empty? - write_field_header(predexp_size, Aerospike::FieldType::FILTER_EXP) - @data_offset = Aerospike::PredExp.write( - predexp, @data_buffer, @data_offset - ) - end - end - def write_filter_exp(exp, exp_size) unless exp.nil? write_field_header(exp_size, Aerospike::FieldType::FILTER_EXP) @@ -1238,7 +1162,7 @@ def use_compression? def compress_buffer if @data_offset > COMPRESS_THRESHOLD - compressed = Zlib::deflate(@data_buffer.buf, Zlib::DEFAULT_COMPRESSION) + compressed = Zlib.deflate(@data_buffer.buf, Zlib::DEFAULT_COMPRESSION) # write original size as header proto_s = format("%08d", 0) diff --git a/lib/aerospike/info.rb b/lib/aerospike/info.rb index 30217e3b..b8e231e4 100644 --- a/lib/aerospike/info.rb +++ b/lib/aerospike/info.rb @@ -66,7 +66,6 @@ def self.parse_multiple_response(buf_length, buffer) private def self.send_command(conn, offset, buffer) - begin # Write size field. size = (offset - 8) | (2 << 56) | (1 << 48) @@ -82,12 +81,11 @@ def self.send_command(conn, offset, buffer) buffer.resize(length) conn.read(buffer, length) - return length - rescue => e + length + rescue => e Aerospike.logger.error(e) conn.close if conn raise e - end end end diff --git a/lib/aerospike/policy/batch_policy.rb b/lib/aerospike/policy/batch_policy.rb index a5800b83..c54247ab 100644 --- a/lib/aerospike/policy/batch_policy.rb +++ b/lib/aerospike/policy/batch_policy.rb @@ -22,11 +22,12 @@ module Aerospike # Container object for batch policy command. class BatchPolicy < Policy - attr_accessor :use_batch_direct - def initialize(opt={}) super(opt) + # [:nodoc:] + # DEPRECATED + # This setting does not have any effect anymore. # Use old batch direct protocol where batch reads are handled by direct # low-level batch server database routines. The batch direct protocol can # be faster when there is a single namespace. But there is one important @@ -39,7 +40,7 @@ def initialize(opt={}) # # Default: false (use new batch index protocol if server supports it) @use_batch_direct = opt.fetch(:use_batch_direct) { false } - + self end diff --git a/lib/aerospike/policy/policy.rb b/lib/aerospike/policy/policy.rb index 054f51f1..69edc810 100644 --- a/lib/aerospike/policy/policy.rb +++ b/lib/aerospike/policy/policy.rb @@ -22,7 +22,7 @@ module Aerospike # Container object for client policy command. class Policy attr_accessor :filter_exp, :priority, :timeout, :max_retries, :sleep_between_retries, :consistency_level, - :predexp, :fail_on_filtered_out, :replica, :use_compression, :socket_timeout + :fail_on_filtered_out, :replica, :use_compression, :socket_timeout alias total_timeout timeout alias total_timeout= timeout= @@ -57,44 +57,7 @@ def initialize(opt = {}) # TODO: Remove for next major release @priority = opt[:priority] || Priority::DEFAULT - # Set optional predicate expression filters in postfix notation. - # Predicate expression filters are applied on the query results on the server. - # Predicate expression filters may occur on any bin in the record. - # Requires Aerospike Server versions >= 3.12 - # - # Postfix notation is described here: http://wiki.c2.com/?PostfixNotation - # - # Example: - # - # (c >= 11 and c <= 20) or (d > 3 and (d < 5) - # policy.predexp = [ - # PredExp.integer_bin("c"), - # PredExp.integer_value(11), - # PredExp.integer_greater_eq(), - # PredExp.integer_bin("c"), - # PredExp.integer_value(20), - # PredExp.integer_less_eq(), - # PredExp.and(2), - # PredExp.integer_bin("d"), - # PredExp.integer_value(3), - # PredExp.integer_greater(), - # PredExp.integer_bin("d"), - # PredExp.integer_value(5), - # PredExp.integer_less(), - # PredExp.and(2), - # PredExp.or(2) - # ] - # - # # Record last update time > 2017-01-15 - # policy.predexp = [ - # PredExp.rec_last_update(), - # PredExp.integer_value(Time.new(2017, 1, 15).to_i), - # PredExp.integer_greater(), - # PredExp.integer_greater() - # ] - @predexp = opt[:predexp] || nil - - # Throw exception if @predexp is defined and that filter evaluates + # Throw exception if @filter_exp is defined and that filter evaluates # to false (transaction ignored). The Aerospike::Exceptions::Aerospike # will contain result code Aerospike::ResultCode::FILTERED_OUT. # This field is not applicable to batch, scan or query commands. diff --git a/lib/aerospike/query/pred_exp.rb b/lib/aerospike/query/pred_exp.rb deleted file mode 100644 index 761615cc..00000000 --- a/lib/aerospike/query/pred_exp.rb +++ /dev/null @@ -1,192 +0,0 @@ -# frozen_string_literal: true - -module Aerospike - class PredExp - AND = 1 - OR = 2 - NOT = 3 - INTEGER_VALUE = 10 - STRING_VALUE = 11 - GEOJSON_VALUE = 12 - INTEGER_BIN = 100 - STRING_BIN = 101 - GEOJSON_BIN = 102 - LIST_BIN = 103 - MAP_BIN = 104 - INTEGER_VAR = 120 - STRING_VAR = 121 - GEOJSON_VAR = 122 - RECSIZE = 150 - LAST_UPDATE = 151 - VOID_TIME = 152 - INTEGER_EQUAL = 200 - INTEGER_UNEQUAL = 201 - INTEGER_GREATER = 202 - INTEGER_GREATEREQ = 203 - INTEGER_LESS = 204 - INTEGER_LESSEQ = 205 - STRING_EQUAL = 210 - STRING_UNEQUAL = 211 - STRING_REGEX = 212 - GEOJSON_WITHIN = 220 - GEOJSON_CONTAINS = 221 - LIST_ITERATE_OR = 250 - MAPKEY_ITERATE_OR = 251 - MAPVAL_ITERATE_OR = 252 - LIST_ITERATE_AND = 253 - MAPKEY_ITERATE_AND = 254 - MAPVAL_ITERATE_AND = 255 - - def self.and(nexp) - AndOr.new(AND, nexp) - end - - def self.or(nexp) - AndOr.new(OR, nexp) - end - - def self.not - Op.new(NOT) - end - - def self.integer_value(value) - IntegerValue.new(value, INTEGER_VALUE) - end - - def self.string_value(value) - StringValue.new(value, STRING_VALUE) - end - - def self.geojson_value(value) - raise(ArgumentError, "value must be a GeoJSON object!") unless value.is_a?(Aerospike::GeoJSON) - GeoJsonValue.new(value.to_s, GEOJSON_VALUE) - end - - def self.integer_bin(name) - StringValue.new(name, INTEGER_BIN) - end - - def self.string_bin(name) - StringValue.new(name, STRING_BIN) - end - - def self.geojson_bin(name) - StringValue.new(name, GEOJSON_BIN) - end - - def self.list_bin(name) - StringValue.new(name, LIST_BIN) - end - - def self.map_bin(name) - StringValue.new(name, MAP_BIN) - end - - def self.integer_var(name) - StringValue.new(name, INTEGER_VAR) - end - - def self.string_var(name) - StringValue.new(name, STRING_VAR) - end - - def self.geojson_var(name) - StringValue.new(name, GEOJSON_VAR) - end - - def self.record_size - Op.new(RECSIZE) - end - - def self.last_update - Op.new(LAST_UPDATE) - end - - def self.void_time - Op.new(VOID_TIME) - end - - def self.integer_equal - Op.new(INTEGER_EQUAL) - end - - def self.integer_unequal - Op.new(INTEGER_UNEQUAL) - end - - def self.integer_greater - Op.new(INTEGER_GREATER) - end - - def self.integer_greater_eq - Op.new(INTEGER_GREATEREQ) - end - - def self.integer_less - Op.new(INTEGER_LESS) - end - - def self.integer_less_eq - Op.new(INTEGER_LESSEQ) - end - - def self.string_equal - Op.new(STRING_EQUAL) - end - - def self.string_unequal - Op.new(STRING_UNEQUAL) - end - - def self.string_regex(flags) - Regex.new(STRING_REGEX, flags) - end - - def self.geojson_within - Op.new(GEOJSON_WITHIN) - end - - def self.geojson_contains - Op.new(GEOJSON_CONTAINS) - end - - def self.list_iterate_or(var_name) - StringValue.new(var_name, LIST_ITERATE_OR) - end - - def self.list_iterate_and(var_name) - StringValue.new(var_name, LIST_ITERATE_AND) - end - - def self.mapkey_iterate_or(var_name) - StringValue.new(var_name, MAPKEY_ITERATE_OR) - end - - def self.mapkey_iterate_and(var_name) - StringValue.new(var_name, MAPKEY_ITERATE_AND) - end - - def self.mapval_iterate_or(var_name) - StringValue.new(var_name, MAPVAL_ITERATE_OR) - end - - def self.mapval_iterate_and(var_name) - StringValue.new(var_name, MAPVAL_ITERATE_AND) - end - - - - def self.estimate_size(predexp) - return 0 unless predexp - predexp.map(&:estimate_size).inject { |sum, size| sum + size } - end - - def self.write(predexp, buffer, offset) - predexp.each do |p| - offset = p.write(buffer, offset) - end - - offset - end - end -end diff --git a/lib/aerospike/query/pred_exp/and_or.rb b/lib/aerospike/query/pred_exp/and_or.rb deleted file mode 100644 index 4da893fd..00000000 --- a/lib/aerospike/query/pred_exp/and_or.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -module Aerospike - class PredExp - class AndOr < PredExp - def initialize(op, nexp) - @op = op - @nexp = nexp - end - - def estimate_size - 8 - end - - def write(buffer, offset) - # write type - buffer.write_int16(@op, offset) - offset += 2 - - # write length - buffer.write_int32(2, offset) - offset += 4 - - # write predicate count - buffer.write_int16(@nexp, offset) - offset += 2 - - offset - end - end - end -end diff --git a/lib/aerospike/query/pred_exp/geo_json_value.rb b/lib/aerospike/query/pred_exp/geo_json_value.rb deleted file mode 100644 index da4a8dd8..00000000 --- a/lib/aerospike/query/pred_exp/geo_json_value.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -module Aerospike - class PredExp - class GeoJsonValue < PredExp - def initialize(value, type) - @value = value - @type = type - end - - def estimate_size - @value.bytesize + 9 - end - - def write(buffer, offset) - # tag - buffer.write_uint16(@type, offset) - offset += 2 - - # len - buffer.write_uint32(@value.bytesize + 3, offset) - offset += 4 - - # flags - - buffer.write_byte(0, offset) - offset += 1 - - # ncells - buffer.write_uint16(0, offset) - offset += 2 - - # value - len = buffer.write_binary(@value, offset) - offset += len - - offset - end - end - end -end diff --git a/lib/aerospike/query/pred_exp/integer_value.rb b/lib/aerospike/query/pred_exp/integer_value.rb deleted file mode 100644 index 42d71b24..00000000 --- a/lib/aerospike/query/pred_exp/integer_value.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -module Aerospike - class PredExp - class IntegerValue < PredExp - def initialize(value, type) - @value = value - @type = type - end - - def estimate_size - 14 - end - - def write(buffer, offset) - # Write type - buffer.write_int16(@type, offset) - offset += 2 - - # Write length - buffer.write_int32(8, offset) - offset += 4 - - # Write value. - buffer.write_int64(@value, offset) - offset += 8 - - offset - end - end - end -end diff --git a/lib/aerospike/query/pred_exp/op.rb b/lib/aerospike/query/pred_exp/op.rb deleted file mode 100644 index 53ca25f9..00000000 --- a/lib/aerospike/query/pred_exp/op.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module Aerospike - class PredExp - class Op < PredExp - def initialize(op) - @op = op - end - - def estimate_size - 6 - end - - def write(buffer, offset) - # write type - buffer.write_int16(@op, offset) - offset += 2 - - # write zero length - buffer.write_int32(0, offset) - offset += 4 - - offset - end - end - end -end diff --git a/lib/aerospike/query/pred_exp/regex.rb b/lib/aerospike/query/pred_exp/regex.rb deleted file mode 100644 index f74cd744..00000000 --- a/lib/aerospike/query/pred_exp/regex.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -module Aerospike - class PredExp - class Regex < PredExp - def initialize(op, flag = Flags::NONE) - @op = op - @flag = flag - end - - def estimate_size - 10 - end - - def write(buffer, offset) - # write op type - buffer.write_int16(@op, offset) - offset += 2 - - # write length - buffer.write_int32(4, offset) - offset += 4 - - # write predicate count - buffer.write_int32(@flag, offset) - offset += 4 - - offset - end - end - end -end diff --git a/lib/aerospike/query/pred_exp/regex_flags.rb b/lib/aerospike/query/pred_exp/regex_flags.rb deleted file mode 100644 index 354d4131..00000000 --- a/lib/aerospike/query/pred_exp/regex_flags.rb +++ /dev/null @@ -1,23 +0,0 @@ -# fr# frozen_string_literal: true - -module Aerospike - class PredExp - # Regex bit flags - module RegexFlags - # Regex defaults - NONE = 0 - - # Use POSIX Extended Regular Expression syntax when interpreting regex. - EXTENDED = 1 - - # Do not differentiate case. - ICASE = 2 - - # Do not report position of matches. - NOSUB = 4 - - # Match-any-character operators don't match a newline. - NEWLINE = 8 - end - end -end diff --git a/lib/aerospike/query/pred_exp/string_value.rb b/lib/aerospike/query/pred_exp/string_value.rb deleted file mode 100644 index 723a6e3c..00000000 --- a/lib/aerospike/query/pred_exp/string_value.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module Aerospike - class PredExp - class StringValue < PredExp - def initialize(value, type) - @value = value - @type = type - end - - def estimate_size - @value.bytesize + 6 - end - - def write(buffer, offset) - buffer.write_int16(@type, offset) - offset += 2 - - buffer.write_int32(@value.bytesize, offset) - offset += 4 - - len = buffer.write_binary(@value, offset) - offset += len - - offset - end - end - end -end diff --git a/lib/aerospike/query/statement.rb b/lib/aerospike/query/statement.rb index 56d4a560..c5f49895 100644 --- a/lib/aerospike/query/statement.rb +++ b/lib/aerospike/query/statement.rb @@ -21,9 +21,7 @@ module Aerospike # index name, filters, and operations. class Statement - attr_accessor :namespace, :set_name, :index_name, :bin_names, :task_id - attr_accessor :filters, :package_name, :function_name, :function_args, :operations - attr_accessor :predexp, :return_data, :records_per_second + attr_accessor :namespace, :set_name, :index_name, :bin_names, :task_id, :filters, :package_name, :function_name, :function_args, :operations, :return_data, :records_per_second def initialize(namespace, set_name, bin_names=[]) # Namespace determines query Namespace @@ -46,16 +44,6 @@ def initialize(namespace, set_name, bin_names=[]) # aggregation function. @filters = [] - # Predicate expressions in postfix notation. If the expression is evaluated to false, - # the record will be ommited in the results. - # - # This method is redundant because PredExp can now be set in the base Policy for - # any transaction (including queries). - # - # NOTE : Policy.predexp takes precedence to this value. This value will be - # deprecated in the future. - @predexp = nil - @package_name = nil @function_name = nil @function_args = nil @@ -83,27 +71,23 @@ def set_aggregate_function(package_name, function_name, function_args=[], return end def is_scan? - return (filters.nil? || (filters.empty?)) + filters.nil? || filters.empty? end def set_task_id - while @task_id == 0 - @task_id = rand(RAND_MAX) - end + @task_id = rand(RAND_MAX) while @task_id == 0 end def reset_task_id @task_id = rand(RAND_MAX) - while @task_id == 0 - @task_id = rand(RAND_MAX) - end + @task_id = rand(RAND_MAX) while @task_id == 0 end private - RAND_MAX = 2**63 - 1 + RAND_MAX = (2**63) - 1 end # class end diff --git a/spec/aerospike/batch_spec.rb b/spec/aerospike/batch_spec.rb index 964d2d73..bffd3283 100644 --- a/spec/aerospike/batch_spec.rb +++ b/spec/aerospike/batch_spec.rb @@ -23,9 +23,9 @@ describe "#batch_exists" do shared_examples_for 'a batch_exists request' do - let(:batch_policy) { - Aerospike::BatchPolicy.new(use_batch_direct: use_batch_direct) - } + let(:batch_policy) do + Aerospike::BatchPolicy.new + end let(:existing_keys) { Array.new(3) { Support.gen_random_key } } let(:no_such_key) { Support.gen_random_key } let(:keys) { existing_keys } @@ -34,10 +34,10 @@ before do existing_keys.each_with_index do |key, idx| client.put(key, { - 'idx' => idx, - 'key' => key.user_key, - 'rnd' => rand - }) + 'idx' => idx, + 'key' => key.user_key, + 'rnd' => rand + }) end end @@ -65,23 +65,15 @@ end context 'using batch index protocol' do - let(:use_batch_direct) { false } - - it_behaves_like 'a batch_exists request' - end - - context 'using batch direct protocol', skip: Support.min_version?('4.4.0') do - let(:use_batch_direct) { true } - it_behaves_like 'a batch_exists request' end end describe "#batch_get" do shared_examples_for 'a batch_get request' do - let(:batch_policy) { - Aerospike::BatchPolicy.new(use_batch_direct: use_batch_direct) - } + let(:batch_policy) do + Aerospike::BatchPolicy.new + end let(:existing_keys) { Array.new(3) { Support.gen_random_key } } let(:no_such_key) { Support.gen_random_key } let(:keys) { existing_keys } @@ -91,10 +83,10 @@ before do existing_keys.each_with_index do |key, idx| client.put(key, { - 'idx' => idx, - 'key' => key.user_key, - 'rnd' => rand - }) + 'idx' => idx, + 'key' => key.user_key, + 'rnd' => rand + }) end end @@ -133,7 +125,7 @@ end context 'when given a list of bin names' do - let(:bins) { %w[ idx rnd ] } + let(:bins) { %w[idx rnd] } it 'returns only the specified bins' do expect(result.first.bins.keys).to eql %w[idx rnd] @@ -158,23 +150,16 @@ end context 'using batch index protocol' do - let(:use_batch_direct) { false } - it_behaves_like 'a batch_get request' end - context 'using batch direct protocol', skip: Support.min_version?('4.4.0') do - let(:use_batch_direct) { true } - - it_behaves_like 'a batch_get request' - end end describe "#batch_get_header" do shared_examples_for 'a batch_get_header request' do - let(:batch_policy) { - Aerospike::BatchPolicy.new(use_batch_direct: use_batch_direct) - } + let(:batch_policy) do + Aerospike::BatchPolicy.new + end let(:existing_keys) { Array.new(3) { Support.gen_random_key } } let(:no_such_key) { Support.gen_random_key } let(:keys) { existing_keys } @@ -183,12 +168,10 @@ before do existing_keys.each_with_index do |key, idx| client.put(key, { - 'idx' => idx, - 'key' => key.user_key, - 'rnd' => rand - }, { - ttl: 1000 - }) + 'idx' => idx, + 'key' => key.user_key, + 'rnd' => rand + }, {}) end end @@ -201,7 +184,7 @@ expect(result.map(&:key)).to eql keys end - it 'returns the meta-data for each record' do + it 'returns the meta-data for each record', skip: !Support.ttl_supported? do expect(result.first.generation).to eq 1 expect(result.first.ttl).to be_within(100).of(1000) end @@ -225,15 +208,8 @@ end context 'using batch index protocol' do - let(:use_batch_direct) { false } - it_behaves_like 'a batch_get_header request' end - context 'using batch direct protocol', skip: Support.min_version?('4.4.0') do - let(:use_batch_direct) { true } - - it_behaves_like 'a batch_get_header request' - end end end diff --git a/spec/aerospike/cdt/cdt_list_spec.rb b/spec/aerospike/cdt/cdt_list_spec.rb index ac491edb..618b2368 100644 --- a/spec/aerospike/cdt/cdt_list_spec.rb +++ b/spec/aerospike/cdt/cdt_list_spec.rb @@ -275,7 +275,7 @@ def list_post_op it "returns the value at the specified index" do operation = ListOperation.get_by_index(list_bin, 2) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to be 3 @@ -293,7 +293,7 @@ def list_post_op it "returns the value at the specified index range" do operation = ListOperation.get_by_index_range(list_bin, 1, 3) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([2, 3, 4]) @@ -301,7 +301,7 @@ def list_post_op it "returns all values starting at the specified index if count is not specified" do operation = ListOperation.get_by_index_range(list_bin, 1) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([2, 3, 4, 5]) @@ -313,7 +313,7 @@ def list_post_op it "returns the value at the specified rank" do operation = ListOperation.get_by_rank(list_bin, 0) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to be 1 @@ -325,7 +325,7 @@ def list_post_op it "returns the value at the specified rank range" do operation = ListOperation.get_by_rank_range(list_bin, 1, 3) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(2, 3, 4) @@ -333,7 +333,7 @@ def list_post_op it "returns all values starting at the specified index if count is not specified" do operation = ListOperation.get_by_rank_range(list_bin, 3) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(4, 5) @@ -346,7 +346,7 @@ def list_post_op it "returns the index of the specified value" do operation = ListOperation.get_by_value(list_bin, 2) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(2, 6) @@ -359,7 +359,7 @@ def list_post_op it "returns the indeces of the items in the specified value range" do operation = ListOperation.get_by_value_range(list_bin, 2, 4) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(2, 3, 6) @@ -367,7 +367,7 @@ def list_post_op it "returns the indeces of the items starting with the specified value" do operation = ListOperation.get_by_value_range(list_bin, 2) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(1, 2, 3, 4, 6) @@ -380,7 +380,7 @@ def list_post_op it "returns the indeces of the items in the specified list" do operation = ListOperation.get_by_value_list(list_bin, [2, 4]) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(1, 2, 6) @@ -392,7 +392,7 @@ def list_post_op it "returns the values of the items nearest to and greater than the specified value, by relative rank range" do operation = ListOperation.get_by_value_rel_rank_range(list_bin, 5, 0, 2) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(5, 9) @@ -400,7 +400,7 @@ def list_post_op it "returns the values of the items nearest to and greater than the specified value, starting with the specified relative rank" do operation = ListOperation.get_by_value_rel_rank_range(list_bin, 5, 0) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(5, 9, 11, 15) @@ -412,7 +412,7 @@ def list_post_op it "removes the value at the specified index" do operation = ListOperation.remove_by_index(list_bin, 2) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to be 3 @@ -431,7 +431,7 @@ def list_post_op it "removes the values at the specified index range" do operation = ListOperation.remove_by_index_range(list_bin, 1, 3) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([2, 3, 4]) @@ -440,7 +440,7 @@ def list_post_op it "returns all values starting at the specified index if count is not specified" do operation = ListOperation.remove_by_index_range(list_bin, 1) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([2, 3, 4, 5]) @@ -453,7 +453,7 @@ def list_post_op it "removes the value at the specified rank" do operation = ListOperation.remove_by_rank(list_bin, 0) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to be 1 @@ -466,7 +466,7 @@ def list_post_op it "removes the value at the specified rank range" do operation = ListOperation.remove_by_rank_range(list_bin, 1, 3) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(2, 3, 4) @@ -475,7 +475,7 @@ def list_post_op it "returns all values starting at the specified index if count is not specified" do operation = ListOperation.remove_by_rank_range(list_bin, 3) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(4, 5) @@ -489,7 +489,7 @@ def list_post_op it "removes the index of the specified value" do operation = ListOperation.remove_by_value(list_bin, 2) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(2, 6) @@ -503,7 +503,7 @@ def list_post_op it "removes the indeces of the items in the specified value range" do operation = ListOperation.remove_by_value_range(list_bin, 2, 4) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(2, 3, 6) @@ -512,7 +512,7 @@ def list_post_op it "removes the indeces of the items starting with the specified value" do operation = ListOperation.remove_by_value_range(list_bin, 2) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(1, 2, 3, 4, 6) @@ -526,7 +526,7 @@ def list_post_op it "removes the indeces of the items in the specified list" do operation = ListOperation.remove_by_value_list(list_bin, [2, 4]) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(1, 2, 6) @@ -539,7 +539,7 @@ def list_post_op it "removes the values of the items nearest to and greater than the specified value, by relative rank range" do operation = ListOperation.remove_by_value_rel_rank_range(list_bin, 5, 0, 2) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(5, 9) @@ -548,7 +548,7 @@ def list_post_op it "removes the values of the items nearest to and greater than the specified value, starting with the specified relative rank" do operation = ListOperation.remove_by_value_rel_rank_range(list_bin, 5, 0) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to contain_exactly(5, 9, 11, 15) @@ -561,7 +561,7 @@ def list_post_op it "returns nothing by default" do operation = ListOperation.remove_by_index_range(list_bin, 2, 4) - .and_return(ListReturnType::DEFAULT) + .and_return(ListReturnType::DEFAULT) result = client.operate(key, [operation]) expected = { list_bin => nil } @@ -570,7 +570,7 @@ def list_post_op it "returns the list index" do operation = ListOperation.remove_by_index_range(list_bin, 2, 4) - .and_return(ListReturnType::INDEX) + .and_return(ListReturnType::INDEX) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([2, 3, 4, 5]) @@ -578,7 +578,7 @@ def list_post_op it "returns the reverse list index" do operation = ListOperation.remove_by_index_range(list_bin, 2, 4) - .and_return(ListReturnType::REVERSE_INDEX) + .and_return(ListReturnType::REVERSE_INDEX) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([1, 2, 3, 4]) @@ -586,7 +586,7 @@ def list_post_op it "returns the list rank" do operation = ListOperation.remove_by_index_range(list_bin, 2, 4) - .and_return(ListReturnType::RANK) + .and_return(ListReturnType::RANK) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([2, 4, 6, 0]) @@ -594,7 +594,7 @@ def list_post_op it "returns the reverse list rank" do operation = ListOperation.remove_by_index_range(list_bin, 2, 4) - .and_return(ListReturnType::REVERSE_RANK) + .and_return(ListReturnType::REVERSE_RANK) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([4, 2, 0, 6]) @@ -602,7 +602,7 @@ def list_post_op it "returns the number of items" do operation = ListOperation.remove_by_index_range(list_bin, 2, 4) - .and_return(ListReturnType::COUNT) + .and_return(ListReturnType::COUNT) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to be 4 @@ -610,7 +610,7 @@ def list_post_op it "returns the value of the items" do operation = ListOperation.remove_by_index_range(list_bin, 2, 4) - .and_return(ListReturnType::VALUE) + .and_return(ListReturnType::VALUE) result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([2, 3, 5, 1]) @@ -622,8 +622,8 @@ def list_post_op it "inverts the selection of items affected by the operation" do operation = ListOperation.remove_by_index_range(list_bin, 2, 4) - .and_return(return_type) - .invert_selection + .and_return(return_type) + .invert_selection result = client.operate(key, [operation]) expect(result.bins[list_bin]).to eql([1, 4, 2]) @@ -638,7 +638,7 @@ def list_post_op list = [ [7, 9, 5], [1, 2, 3], - [6, 5, 4, 1], + [6, 5, 4, 1] ] client.put(key, Aerospike::Bin.new(list_bin, list)) @@ -646,7 +646,7 @@ def list_post_op # Append value to new list created after the original 3 lists. operation = [ ListOperation.append(list_bin, 2, ctx: [Context.list_index_create(3, ListOrder::ORDERED, false)], policy: ListPolicy.new(order: ListOrder::ORDERED)), - Aerospike::Operation.get(list_bin), + Aerospike::Operation.get(list_bin) ] record = client.operate(key, operation) @@ -660,7 +660,7 @@ def list_post_op list = [ [7, 9, 5], [1, 2, 3], - [6, 5, 4, 1], + [6, 5, 4, 1] ] client.put(key, Aerospike::Bin.new(list_bin, list)) @@ -670,10 +670,10 @@ def list_post_op record = client.operate(key, [ListOperation.append(list_bin, 11, ctx: [Context.list_index(-1)]), Aerospike::Operation.get(list_bin)]) expect(record.bins[list_bin]).to eq([ - [7, 9, 5], - [1, 2, 3], - [6, 5, 4, 1, 11], - ]) + [7, 9, 5], + [1, 2, 3], + [6, 5, 4, 1, 11] + ]) end it "is used to change a map in nested list" do @@ -682,13 +682,13 @@ def list_post_op m = { "key1" => [ [7, 9, 5], - [13], + [13] ], "key2" => [ [9], [2, 4], - [6, 1, 9], - ], + [6, 1, 9] + ] } client.put(key, Aerospike::Bin.new(list_bin, m)) @@ -701,13 +701,13 @@ def list_post_op { "key1" => [ [7, 9, 5], - [13], + [13] ], "key2" => [ [9], [2, 4, 11], - [6, 1, 9], - ], + [6, 1, 9] + ] } ) end @@ -789,7 +789,7 @@ def list_post_op it "returns all list elements from 10 to Infinity" do operation = ListOperation.get_by_value_range(list_bin, 10, Aerospike::Value::INFINITY) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) @@ -802,7 +802,7 @@ def list_post_op it "returns all list elements that match a wildcard" do operation = ListOperation.get_by_value(list_bin, ["Jim", Aerospike::Value::WILDCARD]) - .and_return(return_type) + .and_return(return_type) result = client.operate(key, [operation]) diff --git a/spec/aerospike/exp/exp_bit_spec.rb b/spec/aerospike/exp/exp_bit_spec.rb index 7dc72374..18ecc926 100644 --- a/spec/aerospike/exp/exp_bit_spec.rb +++ b/spec/aerospike/exp/exp_bit_spec.rb @@ -27,7 +27,7 @@ @set = "query1000" Support.client.truncate(@namespace, @set) - opts = { expiration: 24 * 60 * 60 } + opts = { } @key_count.times do |ii| key = Aerospike::Key.new(@namespace, @set, ii) bytes = bytes_to_str([0b00000001, 0b01000010]) diff --git a/spec/aerospike/exp/exp_hll_spec.rb b/spec/aerospike/exp/exp_hll_spec.rb index 2f14cc63..ebde871e 100644 --- a/spec/aerospike/exp/exp_hll_spec.rb +++ b/spec/aerospike/exp/exp_hll_spec.rb @@ -28,7 +28,7 @@ Support.client.truncate(@namespace, @set) - opts = { expiration: 24 * 60 * 60 } + opts = { } @key_count.times do |ii| key = Aerospike::Key.new(@namespace, @set, ii) bin = { "bin" => ii, "lbin" => [ii, "a"] } diff --git a/spec/aerospike/exp/exp_list_spec.rb b/spec/aerospike/exp/exp_list_spec.rb index cf8eadd6..00d7c702 100644 --- a/spec/aerospike/exp/exp_list_spec.rb +++ b/spec/aerospike/exp/exp_list_spec.rb @@ -26,7 +26,7 @@ @namespace = "test" @set = "query1000" - opts = { expiration: 24 * 60 * 60 } + opts = { } @key_count.times do |ii| key = Aerospike::Key.new(@namespace, @set, ii) ibin = { "bin" => [1, 2, 3, ii] } diff --git a/spec/aerospike/exp/exp_map_spec.rb b/spec/aerospike/exp/exp_map_spec.rb index 3e0a4eee..4ee12468 100644 --- a/spec/aerospike/exp/exp_map_spec.rb +++ b/spec/aerospike/exp/exp_map_spec.rb @@ -26,7 +26,7 @@ @namespace = "test" @set = "query1000" - opts = { expiration: 24 * 60 * 60 } + opts = { } @key_count.times do |ii| key = Aerospike::Key.new(@namespace, @set, ii) ibin = { "bin" => { "test" => ii, "test2" => "a" } } diff --git a/spec/aerospike/exp/expression_spec.rb b/spec/aerospike/exp/expression_spec.rb index f57f5143..f044b4e6 100644 --- a/spec/aerospike/exp/expression_spec.rb +++ b/spec/aerospike/exp/expression_spec.rb @@ -31,7 +31,7 @@ "bin1" => "value#{i}", "bin2" => i, "bin3" => [i, i + 1_000, i + 1_000_000], - "bin4" => { "key#{i}" => i }, + "bin4" => { "key#{i}" => i } } Support.client.put(key, bin_map) end @@ -39,7 +39,7 @@ Support.client.drop_index(@namespace, @set, "index_intval") Support.client.drop_index(@namespace, @set, "index_strval") - wpolicy = { generation: 0, expiration: 24 * 60 * 60 } + wpolicy = { generation: 0 } starbucks = [ [-122.1708441, 37.4241193], @@ -56,7 +56,7 @@ [-122.0303178, 37.3882739], [-122.0464861, 37.3786236], [-122.0582128, 37.3726980], - [-122.0365083, 37.3676930], + [-122.0365083, 37.3676930] ] @record_count.times do |ii| @@ -74,12 +74,12 @@ lat = 37.5 + (0.01 * ii) point = Aerospike::GeoJSON.point(lat, lng) - if ii < starbucks.length - region = Aerospike::GeoJSON.circle(starbucks[ii][0], starbucks[ii][1], 3000.0) - else + region = if ii < starbucks.length + Aerospike::GeoJSON.circle(starbucks[ii][0], starbucks[ii][1], 3000.0) + else # Somewhere off Africa ... - region = Aerospike::GeoJSON.circle(0.0, 0.0, 3000.0) - end + Aerospike::GeoJSON.circle(0.0, 0.0, 3000.0) + end # Accumulate prime factors of the index into a list and map. listval = [] @@ -87,7 +87,7 @@ [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31].each do |ff| if ii >= ff && ii % ff == 0 listval << ff - mapval[ff] = sprintf("0x%04x", ff) + mapval[ff] = format("0x%04x", ff) end end @@ -95,13 +95,13 @@ bins = { "intval" => ii, - "strval" => sprintf("0x%04x", ii), + "strval" => format("0x%04x", ii), "modval" => ii % 10, # "locval" => point, # "rgnval" => region, "lstval" => listval, "mapval" => mapval, - "ballast" => ballast, + "ballast" => ballast } Support.client.put(key, bins, wpolicy) @@ -119,10 +119,12 @@ stmt = Aerospike::Statement.new(@namespace, @set) stmt.filters << Aerospike::Filter.Range("intval", 0, 400) opts = { filter_exp: Aerospike::Exp.int_val(100) } - expect { + expect do rs = client.query(stmt, opts) - rs.each do end - }.to raise_error (Aerospike::Exceptions::Aerospike) { |error| + rs.each do + + end + end.to raise_error(Aerospike::Exceptions::Aerospike) { |error| error.result_code == Aerospike::ResultCode::PARAMETER_ERROR } end @@ -134,7 +136,7 @@ stmt.filters << Aerospike::Filter.Range("intval", 0, 400) opts = { filter_exp: Aerospike::Exp.ge(Aerospike::Exp.int_bin("modval"), Aerospike::Exp.int_val(8)) } - # The query clause selects [0, 1, ... 400, 401] The predexp + # The query clause selects [0, 1, ... 400, 401] The filter_exp # only takes mod 8 and 9, should be 2 pre decade or 80 total. rs = client.query(stmt, opts) @@ -162,11 +164,11 @@ opts = { filter_exp: Aerospike::Exp.or( Aerospike::Exp.and( Aerospike::Exp.not(Aerospike::Exp.eq(Aerospike::Exp.str_bin("strval"), Aerospike::Exp.str_val("0x0001"))), - Aerospike::Exp.ge(Aerospike::Exp.int_bin("modval"), Aerospike::Exp.int_val(8)), + Aerospike::Exp.ge(Aerospike::Exp.int_bin("modval"), Aerospike::Exp.int_val(8)) ), Aerospike::Exp.eq(Aerospike::Exp.str_bin("strval"), Aerospike::Exp.str_val("0x0104")), Aerospike::Exp.eq(Aerospike::Exp.str_bin("strval"), Aerospike::Exp.str_val("0x0105")), - Aerospike::Exp.eq(Aerospike::Exp.str_bin("strval"), Aerospike::Exp.str_val("0x0106")), + Aerospike::Exp.eq(Aerospike::Exp.str_bin("strval"), Aerospike::Exp.str_val("0x0106")) ) } rs = client.query(stmt, opts) @@ -219,7 +221,7 @@ def query_method(exp, ops = {}) "bin3" => ii.to_f / 3, "bin4" => BytesValue.new("blob#{ii}"), "bin5" => ["a", "b", ii], - "bin6" => { "a": "test", "b": ii }, + "bin6" => { a: "test", b: ii } } Support.client.put(key, bins) end @@ -255,7 +257,7 @@ def query_method(exp, ops = {}) ["key must work", 0, Exp.eq(Exp.key(Exp::Type::INT), Exp.int_val(50))], ["key_exists must work", 0, Exp.key_exists], ["nil must work", 100, Exp.eq(Exp.nil_val, Exp.nil_val)], - ["regex_compare must work", 75, Exp.regex_compare("[1-5]", Exp::RegexFlags::ICASE, Exp.str_bin("bin2"))], + ["regex_compare must work", 75, Exp.regex_compare("[1-5]", Exp::RegexFlags::ICASE, Exp.str_bin("bin2"))] ] matrix.each do |title, result, exp| @@ -281,19 +283,19 @@ def query_method(exp, ops = {}) fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(16), - ), + Exp.int_val(16) + ) } - expect { + expect do client.delete(key, opts) - }.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) + end.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) opts = { fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(15), - ), + Exp.int_val(15) + ) } client.delete(key, opts) end @@ -304,19 +306,19 @@ def query_method(exp, ops = {}) fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(15), - ), + Exp.int_val(15) + ) } - expect { + expect do client.put(key, { "bin" => 26 }, opts) - }.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) + end.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) opts = { fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(25), - ), + Exp.int_val(25) + ) } client.put(key, { "bin" => 26 }, opts) end @@ -327,20 +329,20 @@ def query_method(exp, ops = {}) fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(15), - ), + Exp.int_val(15) + ) } - expect { + expect do client.get(key, nil, opts) - }.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) + end.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) opts = { fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(35), - ), + Exp.int_val(35) + ) } client.get(key, ["bin"], opts) end @@ -351,19 +353,19 @@ def query_method(exp, ops = {}) fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(15), - ), + Exp.int_val(15) + ) } - expect { + expect do client.exists(key, opts) - }.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) + end.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) opts = { fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(45), - ), + Exp.int_val(45) + ) } client.exists(key, opts) end @@ -374,19 +376,19 @@ def query_method(exp, ops = {}) fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(15), - ), + Exp.int_val(15) + ) } - expect { + expect do client.add(key, { "test55" => "test" }, opts) - }.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) + end.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) opts = { fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(55), - ), + Exp.int_val(55) + ) } client.add(key, { "test55" => "test" }, opts) end @@ -397,19 +399,19 @@ def query_method(exp, ops = {}) fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(15), - ), + Exp.int_val(15) + ) } - expect { + expect do client.prepend(key, { "test55" => "test" }, opts) - }.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) + end.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) opts = { fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(55), - ), + Exp.int_val(55) + ) } client.prepend(key, { "test55" => "test" }, opts) end @@ -420,19 +422,19 @@ def query_method(exp, ops = {}) fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(15), - ), + Exp.int_val(15) + ) } - expect { + expect do client.touch(key, opts) - }.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) + end.to raise_aerospike_error(Aerospike::ResultCode::FILTERED_OUT) opts = { fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(65), - ), + Exp.int_val(65) + ) } client.touch(key, opts) end @@ -442,8 +444,8 @@ def query_method(exp, ops = {}) fail_on_filtered_out: true, filter_exp: Exp.eq( Exp.int_bin("bin"), - Exp.int_val(75), - ), + Exp.int_val(75) + ) } rs = client.scan_all(@namespace, @set, nil, opts) @@ -498,7 +500,7 @@ def query_method(exp, ops = {}) ), Exp.eq( Exp.int_and(Exp.int_bin(bin_a), Exp.int_val(0xFFFF)), - Exp.int_val(1), + Exp.int_val(1) ) ) ), key_a, key_a, bin_a, 1, true], @@ -510,7 +512,7 @@ def query_method(exp, ops = {}) ), Exp.eq( Exp.int_or(Exp.int_bin(bin_a), Exp.int_val(0xFF)), - Exp.int_val(0xFF), + Exp.int_val(0xFF) ) ) ), key_a, key_a, bin_a, 1, true], @@ -522,7 +524,7 @@ def query_method(exp, ops = {}) ), Exp.eq( Exp.int_xor(Exp.int_bin(bin_a), Exp.int_val(0xFF)), - Exp.int_val(0xFE), + Exp.int_val(0xFE) ) ) ), key_a, key_a, bin_a, 1, true], @@ -596,7 +598,7 @@ def query_method(exp, ops = {}) Exp.def("val", Exp.add(Exp.float_bin(bin_b), Exp.float_val(1.1))), Exp.and( Exp.ge(Exp.var("val"), Exp.float_val(3.2999)), - Exp.le(Exp.var("val"), Exp.float_val(3.3001)), + Exp.le(Exp.var("val"), Exp.float_val(3.3001)) ) ), key_a, key_b, bin_a, 2, false], @@ -613,26 +615,28 @@ def query_method(exp, ops = {}) Exp.ge(Exp.var("val"), Exp.float_val(4.8399)), Exp.le(Exp.var("val"), Exp.float_val(4.8401)) ) - ), key_a, key_b, bin_a, 2, false], + ), key_a, key_b, bin_a, 2, false] ] matrix.each do |title, exp, key, exp_key, bin, expected, reverse_exp| it "#{title} should work" do opts = { fail_on_filtered_out: true, - filter_exp: exp, + filter_exp: exp } - expect { + expect do client.get(key, nil, opts) - }.to raise_error (Aerospike::Exceptions::Aerospike) { |error| + end.to raise_error(Aerospike::Exceptions::Aerospike) { |error| error.result_code == Aerospike::ResultCode::FILTERED_OUT } - opts = { - fail_on_filtered_out: true, - filter_exp: Exp.not(exp), - } if reverse_exp + if reverse_exp + opts = { + fail_on_filtered_out: true, + filter_exp: Exp.not(exp) + } + end r = client.get(exp_key, nil, opts) client.get(key) expect(r.bins[bin]).to eq expected diff --git a/spec/aerospike/pred_exp_spec.rb b/spec/aerospike/pred_exp_spec.rb deleted file mode 100644 index 0849e245..00000000 --- a/spec/aerospike/pred_exp_spec.rb +++ /dev/null @@ -1,536 +0,0 @@ -# frozen_string_literal: true - -describe Aerospike::PredExp, skip: Support.min_version?("6") do - let(:client) { Support.client } - - before :all do - @namespace = "test" - @set = "predexp" - @record_count = 5 - @record_count.times do |i| - key = Aerospike::Key.new(@namespace, @set, i) - bin_map = { - 'bin1' => "value#{i}", - 'bin2' => i, - 'bin3' => [ i, i + 1_000, i + 1_000_000 ], - 'bin4' => { "key#{i}" => i } - } - Support.client.put(key, bin_map, ttl: i * 10) - end - - tasks = [] - tasks << Support.client.create_index(@namespace, @set, "predexp_index_str_bin1", "bin1", :string) - tasks << Support.client.create_index(@namespace, @set, "predexp_index_int_bin2", "bin2", :numeric) - tasks << Support.client.create_index(@namespace, @set, "predexp_index_lst_bin3", "bin3", :numeric, :list) - tasks << Support.client.create_index(@namespace, @set, "predexp_index_mapkey_bin4", "bin4", :string, :mapkeys) - tasks << Support.client.create_index(@namespace, @set, "predexp_index_mapval_bin4", "bin4", :numeric, :mapvalues) - tasks.each(&:wait_till_completed) - expect(tasks.all?(&:completed?)).to be true - end - - let(:statement) { Aerospike::Statement.new(@namespace, @set) } - let(:string_bin) { 'bin1' } - let(:integer_bin) { 'bin2' } - let(:list_bin) { 'bin3' } - let(:map_bin) { 'bin4' } - - context 'void time' do - let(:seconds_from_now) { 30 } - let(:time) { Time.now + seconds_from_now } - let(:value) { Support.time_in_nanoseconds(time) } - let(:predexp) do - [ - Aerospike::PredExp.integer_value(value), - Aerospike::PredExp.void_time, - Aerospike::PredExp.integer_less - ] - end - - it 'returns records expiring later than set time' do - statement.predexp = predexp - rs = client.query(statement) - - count = 0 - rs.each do |r| - expect(r.ttl).to be > seconds_from_now - count += 1 - end - - expect(count).to be > 0 - end - end - - describe 'expressions for integer bins' do - let(:value) { 3 } - let(:predexp) do - [ - Aerospike::PredExp.integer_bin(integer_bin), - Aerospike::PredExp.integer_value(value) - ] - end - - it 'returns records with bin equal to value' do - predexp << Aerospike::PredExp.integer_equal - statement.predexp = predexp - rs = client.query(statement) - rs.each do |r| - expect(r.bins[integer_bin]).to eq(value) - end - end - - it 'returns records not equal to value' do - predexp << Aerospike::PredExp.integer_unequal - statement.predexp = predexp - rs = client.query(statement) - rs.each do |r| - expect(r.bins[integer_bin]).not_to eq(value) - end - end - - it 'returns records with bin less than value' do - predexp << Aerospike::PredExp.integer_less - statement.predexp = predexp - rs = client.query(statement) - rs.each do |r| - expect(r.bins[integer_bin]).to be < value - end - end - - it 'returns records with bin less or equal than value' do - predexp << Aerospike::PredExp.integer_less_eq - statement.predexp = predexp - rs = client.query(statement) - rs.each do |r| - expect(r.bins[integer_bin]).to be <= value - end - end - - it 'returns records with bin greater than value' do - predexp << Aerospike::PredExp.integer_greater - statement.predexp = predexp - rs = client.query(statement) - rs.each do |r| - expect(r.bins[integer_bin]).to be > value - end - end - - it 'returns records with bin greater or equal to value' do - predexp << Aerospike::PredExp.integer_greater_eq - statement.predexp = predexp - rs = client.query(statement) - rs.each do |r| - expect(r.bins[integer_bin]).to be >= value - end - end - end - - describe 'expressions for string bins' do - let(:value) { 'value3' } - let(:predexp) do - [ - Aerospike::PredExp.string_bin(string_bin), - Aerospike::PredExp.string_value(value) - ] - end - - it 'returns records equal to value' do - predexp << Aerospike::PredExp.string_equal - statement.predexp = predexp - rs = client.query(statement) - rs.each do |r| - expect(r.bins[string_bin]).to eq(value) - end - end - - it 'returns records not equal to value' do - predexp << Aerospike::PredExp.string_unequal - statement.predexp = predexp - rs = client.query(statement) - rs.each do |r| - expect(r.bins[string_bin]).not_to eq(value) - end - end - - context 'regex' do - let(:value) { 'lue3' } - context 'default flag' do - it 'returns records matching regex' do - predexp << Aerospike::PredExp.string_regex(Aerospike::PredExp::RegexFlags::NONE) - statement.predexp = predexp - rs = client.query(statement) - count = 0 - rs.each do |r| - count += 1 - end - - expect(count).to eq(1) - end - end - end - end - - context 'expressions for GeoJSON bins' do - before :all do - @lat = 1.3083 - @lng = 103.9114 - - @point = Aerospike::GeoJSON.new(type: "Point", coordinates: [@lng, @lat]) - @record_count.times do |i| - key = Aerospike::Key.new(@namespace, @set, i) - sub_point = Support::Geo.destination_point(@lng, @lat, i * 200, rand(0..359)) - - sub_point_cords = sub_point.coordinates - - polygon_points = [315, 45, 135, 225].map { |x| - Support::Geo.destination_point(sub_point_cords.first, sub_point_cords.last, 100, x).coordinates - } - polygon_points << polygon_points.first - polygon = Aerospike::GeoJSON.new(type: 'Polygon', coordinates: [polygon_points]) - bin_map = { - 'geo_point' => sub_point, - 'geo_polygon' => polygon - } - Support.client.put(key, bin_map, ttl: 10) - end - - - tasks = [] - tasks << Support.client.create_index(@namespace, @set, "index_geo_bin5", "geo_point", :geo2dsphere) - tasks << Support.client.create_index(@namespace, @set, "index_geo_bin5", "geo_polygon", :geo2dsphere) - tasks.each(&:wait_till_completed) - expect(tasks.all?(&:completed?)).to be true - end - - let(:point_bin) { 'geo_point' } - let(:polygon_bin) { 'geo_polygon' } - - context 'contains' do - let(:geo_json_area_circle) { Aerospike::GeoJSON.new(type: 'AeroCircle', coordinates: [[@lng, @lat], 500]) } - - let(:predexp) do - [ - Aerospike::PredExp.geojson_bin(point_bin), - Aerospike::PredExp.geojson_value(geo_json_area_circle), - Aerospike::PredExp.geojson_contains - ] - end - - it 'returns records with points within a circle' do - statement.predexp = predexp - rs = client.query(statement) - count = 0 - rs.each do |r| - count += 1 - end - expect(count).to eq(3) - end - end - - context 'within' do - let(:predexp) do - [ - Aerospike::PredExp.geojson_bin(polygon_bin), - Aerospike::PredExp.geojson_value(@point), - Aerospike::PredExp.geojson_within - ] - end - - it 'returns records with polygons which contain point' do - statement.predexp = predexp - rs = client.query(statement) - count = 0 - rs.each do |r| - count += 1 - end - expect(count).to eq(1) - end - end - end - - context 'expressions for bins with lists' do - let(:value) { 3 } - - context 'list_or' do - let(:predexp) do - [ - Aerospike::PredExp.integer_value(value), - Aerospike::PredExp.integer_var('x'), - Aerospike::PredExp.integer_equal, - Aerospike::PredExp.list_bin(list_bin), - Aerospike::PredExp.list_iterate_or('x') - ] - end - - it 'returns items which has any item equal to value' do - statement.predexp = predexp - rs = client.query(statement) - count = 0 - rs.each do |r| - expect(r.bins[list_bin]).to include(value) - count += 1 - end - - expect(count).to eq(1) - end - end - - context 'list_and' do - let(:predexp) do - [ - Aerospike::PredExp.integer_value(value), - Aerospike::PredExp.integer_var('x'), - Aerospike::PredExp.integer_unequal, - Aerospike::PredExp.list_bin(list_bin), - Aerospike::PredExp.list_iterate_and('x') - ] - end - - it 'returns items which do NOT contain an item equal to value' do - statement.predexp = predexp - rs = client.query(statement) - count = 0 - rs.each do |r| - expect(r.bins[list_bin]).not_to include(value) - count += 1 - end - - expect(count).to eq(4) - end - end - end - - context 'expressions for bins with mapkeys' do - let(:bin) { 'bin4' } - let(:value) { 3 } - let(:key) { 'key3' } - - context 'keys' do - context 'iterate_or' do - let(:predexp) do - [ - Aerospike::PredExp.string_value(key), - Aerospike::PredExp.string_var('k'), - Aerospike::PredExp.string_equal, - Aerospike::PredExp.map_bin(map_bin), - Aerospike::PredExp.mapkey_iterate_or('k') - ] - end - - it 'returns records with map bins containing chosen key' do - statement.predexp = predexp - rs = client.query(statement) - - count = 0 - rs.each do |r| - expect(r.bins[map_bin].keys).to include(key) - count += 1 - end - - expect(count).to eq(1) - end - end - - context 'iterate_and' do - let(:predexp) do - [ - Aerospike::PredExp.string_value(key), - Aerospike::PredExp.string_var('k'), - Aerospike::PredExp.string_unequal, - Aerospike::PredExp.map_bin(map_bin), - Aerospike::PredExp.mapkey_iterate_and('k') - ] - end - - it 'returns records with map bins NOT containing chosen key' do - statement.predexp = predexp - rs = client.query(statement) - - count = 0 - rs.each do |r| - expect(r.bins[map_bin].keys).not_to include(key) - count += 1 - end - - expect(count).to eq(4) - end - end - end - - context 'values' do - context 'iterate_or' do - let(:predexp) do - [ - Aerospike::PredExp.integer_value(value), - Aerospike::PredExp.integer_var('v'), - Aerospike::PredExp.integer_equal, - Aerospike::PredExp.map_bin(map_bin), - Aerospike::PredExp.mapval_iterate_or('v') - ] - end - - it 'returns records with map bins containing chosen value' do - statement.predexp = predexp - rs = client.query(statement) - - count = 0 - rs.each do |r| - expect(r.bins[map_bin].values).to include(value) - count += 1 - end - - expect(count).to eq(1) - end - end - - context 'iterate_and' do - let(:predexp) do - [ - Aerospike::PredExp.integer_value(value), - Aerospike::PredExp.integer_var('v'), - Aerospike::PredExp.integer_unequal, - Aerospike::PredExp.map_bin(map_bin), - Aerospike::PredExp.mapval_iterate_and('v') - ] - end - - it 'returns records with map bins NOT containing chosen value' do - statement.predexp = predexp - rs = client.query(statement) - - count = 0 - rs.each do |r| - expect(r.bins[map_bin].values).not_to include(value) - count += 1 - end - - expect(count).to eq(4) - end - end - end - end - - context '.and' do - let(:min_value) { 2 } - - # return records with bin2 > 2 AND bin1 equal to 'value4' - let(:predexp) do - [ - Aerospike::PredExp.integer_bin(integer_bin), - Aerospike::PredExp.integer_value(min_value), - Aerospike::PredExp.integer_greater, - Aerospike::PredExp.string_bin(string_bin), - Aerospike::PredExp.string_value('value4'), - Aerospike::PredExp.string_equal, - Aerospike::PredExp.and(2) - ] - end - - it 'returns records fulfilling multiple predicates' do - statement.predexp = predexp - rs = client.query(statement) - - count = 0 - rs.each do |r| - bins = r.bins - expect(bins[integer_bin]).to be > min_value - expect(bins[string_bin]).to eq('value4') - count += 1 - end - - expect(count).to eq(1) - end - end - - context '.or' do - let(:max_value) { 2 } - - # return all records with bin2 <=2 OR bin1 equal to 'value4' - let(:predexp) do - [ - Aerospike::PredExp.integer_bin(integer_bin), - Aerospike::PredExp.integer_value(max_value), - Aerospike::PredExp.integer_less_eq, - Aerospike::PredExp.string_bin(string_bin), - Aerospike::PredExp.string_value('value4'), - Aerospike::PredExp.string_equal, - Aerospike::PredExp.or(2) - ] - end - - it 'returns records fulfilling one of the predicates' do - statement.predexp = predexp - rs = client.query(statement) - - count = 0 - rs.each do |r| - bins = r.bins - if bins[integer_bin] > max_value - expect(bins[string_bin]).to eq('value4') - else - expect(bins[integer_bin]).to be <= max_value - end - - count += 1 - end - - expect(count).to eq(4) - end - end - - context '.not' do - let(:value) { 3 } - # return all records with bin2 not equal 3 - let(:predexp) do - [ - Aerospike::PredExp.integer_bin(integer_bin), - Aerospike::PredExp.integer_value(value), - Aerospike::PredExp.integer_equal, - Aerospike::PredExp.not - ] - end - - it 'returns records NOT fulfilling the predicate' do - statement.predexp = predexp - rs = client.query(statement) - - count = 0 - rs.each do |r| - expect(r.bins[integer_bin]).not_to eq(value) - count += 1 - end - - expect(count).to eq(4) - end - end - - context 'last update' do - before :all do - @current_time = Support.time_in_nanoseconds(Time.now) - sleep 0.1 - key = Aerospike::Key.new(@namespace, @set, "new_rec") - bin_map = { - 'bin1' => 'val' - } - Support.client.put(key, bin_map, ttl: 10) - end - - let(:predexp) do - [ - Aerospike::PredExp.integer_value(@current_time), - Aerospike::PredExp.last_update, - Aerospike::PredExp.integer_less - ] - end - - it 'returns records updated at chosen time' do - statement.predexp = predexp - rs = client.query(statement) - - count = 0 - rs.each do |r| - count += 1 - end - expect(count).to eq(1) - end - end -end diff --git a/spec/aerospike/predexp_ops_spec.rb b/spec/aerospike/predexp_ops_spec.rb deleted file mode 100644 index 2c40d05c..00000000 --- a/spec/aerospike/predexp_ops_spec.rb +++ /dev/null @@ -1,329 +0,0 @@ -# Copyright 2014-2020 Aerospike, Inc. -# -# Portions may be licensed to Aerospike, Inc. under one or more contributor -# license agreements. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -require 'aerospike' -require 'benchmark' - -describe Aerospike::Client do - - describe "Predicates", skip: Support.min_version?("6") do - - let(:key) { Aerospike::Key.new(Support.namespace, 'predexp_ops_spec', 0) } - let(:client) { Support.client } - let(:valid_predicate) { - [ - Aerospike::PredExp.integer_bin('bin2'), - Aerospike::PredExp.integer_value(9), - Aerospike::PredExp.integer_less_eq - ] - } - - let(:invalid_predicate) { - [ - Aerospike::PredExp.string_bin('bin1'), - Aerospike::PredExp.string_value('value'), - Aerospike::PredExp.string_unequal - ] - } - - before :each do - client.delete(key) - client.put(key, {'bin1' => 'value', 'bin2' => 9}) - end - - describe "#put" do - - it "should put the key if the predicate is valid" do - client.put(key, {'bin3' => 1.1}, predexp: valid_predicate) - rec = client.get(key) - expect(rec.bins['bin1']).to eq 'value' - expect(rec.bins['bin2']).to eq 9 - expect(rec.bins['bin3']).to eq 1.1 - end - - it "should NOT put the key if the predicate is invalid" do - client.put(key, {'bin3' => 1.1}, predexp: invalid_predicate) - rec = client.get(key) - expect(rec.bins['bin1']).to eq 'value' - expect(rec.bins['bin2']).to eq 9 - expect(rec.bins['bin3']).to be_nil - end - - it "should raise exception if the predicate is invalid" do - expect { - client.put(key, {'bin3' => 1.1}, predexp: invalid_predicate, fail_on_filtered_out: true) - }.to raise_error (Aerospike::Exceptions::Aerospike){ |error| - error.result_code == Aerospike::ResultCode::FILTERED_OUT - } - end - - end - - describe "#get" do - - it "should get the key if the predicate is valid" do - rec = client.get(key, [], predexp: valid_predicate) - expect(rec.bins['bin1']).to eq 'value' - expect(rec.bins['bin2']).to eq 9 - end - - it "should NOT get the key if the predicate is invalid" do - rec = client.get(key, [], predexp: invalid_predicate) - expect(rec).to be_nil - end - - it "should raise exception if the predicate is invalid" do - expect { - client.get(key, [], predexp: invalid_predicate, fail_on_filtered_out: true) - }.to raise_error (Aerospike::Exceptions::Aerospike){ |error| - error.result_code == Aerospike::ResultCode::FILTERED_OUT - } - end - - end - - describe "#get_header" do - - it "should get the key if the predicate is valid" do - rec = client.get_header(key, predexp: valid_predicate) - expect(rec).not_to be_nil - end - - it "should NOT get the key if the predicate is invalid" do - rec = client.get_header(key, predexp: invalid_predicate) - expect(rec).to be_nil - end - - it "should raise exception if the predicate is invalid" do - expect { - client.get_header(key, predexp: invalid_predicate, fail_on_filtered_out: true) - }.to raise_error (Aerospike::Exceptions::Aerospike){ |error| - error.result_code == Aerospike::ResultCode::FILTERED_OUT - } - end - - end - - describe "#delete" do - - it "should delete a key if the predicate is valid" do - existed = client.delete(key, predexp: valid_predicate) - expect(existed).to eq true - end - - it "should NOT delete a key if the predicate is invalid" do - existed = client.delete(key, predexp: invalid_predicate) - expect(existed).to eq true - rec = client.get(key, []) - expect(rec.bins['bin1']).to eq 'value' - expect(rec.bins['bin2']).to eq 9 - end - - it "should raise exception if the predicate is invalid" do - expect { - client.delete(key, predexp: invalid_predicate, fail_on_filtered_out: true) - }.to raise_error (Aerospike::Exceptions::Aerospike){ |error| - error.result_code == Aerospike::ResultCode::FILTERED_OUT - } - end - - end - - describe "#touch" do - - it "should touch the record to bump its generation if the predicate is valid" do - client.touch(key, predexp: valid_predicate) - record = client.get_header(key) - expect(record.generation).to eq 2 - end - - it "should NOT touch the record to bump its generation if the predicate is invalid" do - client.touch(key, predexp: invalid_predicate) - record = client.get_header(key) - expect(record.generation).to eq 1 - end - - it "should raise exception if the predicate is invalid" do - expect { - client.touch(key, predexp: invalid_predicate, fail_on_filtered_out: true) - }.to raise_error (Aerospike::Exceptions::Aerospike){ |error| - error.result_code == Aerospike::ResultCode::FILTERED_OUT - } - end - - end - - describe "#exists" do - - it "should check existence of the record if the predicate is valid" do - existed = client.exists(key, predexp: valid_predicate) - expect(existed).to eq true - end - - it "should NOT check existence of the record if the predicate is invalid" do - existed = client.exists(key, predexp: invalid_predicate) - expect(existed).to eq true - end - - it "should raise exception if the predicate is invalid" do - expect { - client.exists(key, predexp: invalid_predicate, fail_on_filtered_out: true) - }.to raise_error (Aerospike::Exceptions::Aerospike){ |error| - error.result_code == Aerospike::ResultCode::FILTERED_OUT - } - end - - end - - describe "#operate" do - - let(:bin_int) do - Aerospike::Bin.new('bin2', 5) - end - - it "should #add, #get if the predicate is valid" do - client.operate(key, [ - Aerospike::Operation.add(bin_int), - ], predexp: valid_predicate) - rec = client.get(key) - expect(rec.bins[bin_int.name]).to eq bin_int.value + 9 - expect(rec.generation).to eq 2 - end - - it "should NOT #add, #get if the predicate is invalid" do - client.operate(key, [ - Aerospike::Operation.add(bin_int), - ], predexp: invalid_predicate) - rec = client.get(key) - expect(rec.bins[bin_int.name]).to eq 9 - expect(rec.generation).to eq 1 - end - - it "should raise exception if the predicate is invalid" do - expect { - client.operate(key, [ - Aerospike::Operation.add(bin_int), - ], predexp: invalid_predicate, fail_on_filtered_out: true) - }.to raise_error (Aerospike::Exceptions::Aerospike){ |error| - error.result_code == Aerospike::ResultCode::FILTERED_OUT - } - end - - end - - describe "#batch" do - - it "should batch_get if the predicate is valid" do - result = client.batch_get([key], [], predexp: valid_predicate) - expect(result[0].bins['bin1']).to eq 'value' - end - - it "should NOT batch_get if the predicate is invalid" do - result = client.batch_get([key], [], predexp: invalid_predicate) - expect(result[0]).to be_nil - end - - end - - describe "#scan" do - - it "should scan and return records if the predicate is valid" do - rs = client.scan_all(key.namespace, key.set_name, nil, predexp: valid_predicate) - count = 0 - rs.each do |rs| - count += 1 - end - - expect(count).to eq 1 - end - - it "should NOT scan and return records if the predicate is invalid" do - rs = client.scan_all(key.namespace, key.set_name, nil, predexp: invalid_predicate) - count = 0 - rs.each do |rs| - count += 1 - end - - expect(count).to eq 0 - end - - end - - describe "#query" do - - let(:stmt) { stmt = Aerospike::Statement.new(key.namespace, key.set_name) } - - it "should query and return records if the predicate is valid" do - stmt.predexp = valid_predicate - rs = client.query(stmt) - count = 0 - rs.each do |rs| - count += 1 - end - - expect(count).to eq 1 - end - - it "should query and return records if the predicate is invalid - predexp on policy" do - rs = client.query(stmt, predexp: valid_predicate) - count = 0 - rs.each do |rs| - count += 1 - end - - expect(count).to eq 1 - end - - it "should query and return records if the predicate is valid - predexp on policy" do - # policy value takes precedence - stmt.predexp = invalid_predicate - rs = client.query(stmt, predexp: valid_predicate) - count = 0 - rs.each do |rs| - count += 1 - end - - expect(count).to eq 1 - end - - it "should NOT query and return records if the predicate is valid - predexp on policy" do - # policy value takes precedence - stmt.predexp = invalid_predicate - rs = client.query(stmt) - count = 0 - rs.each do |rs| - count += 1 - end - - expect(count).to eq 0 - end - - it "should NOT query and return records if the predicate is valid - predexp on policy" do - rs = client.query(stmt, predexp: invalid_predicate) - count = 0 - rs.each do |rs| - count += 1 - end - - expect(count).to eq 0 - end - - end - - end - -end diff --git a/spec/aerospike/udf_spec.rb b/spec/aerospike/udf_spec.rb index 41e3c16c..ca6dfff4 100644 --- a/spec/aerospike/udf_spec.rb +++ b/spec/aerospike/udf_spec.rb @@ -151,8 +151,8 @@ number_of_records = 100 number_of_records.times do |i| - key = Support.gen_random_key(50, {:set => set}) - bin1 = Aerospike::Bin.new('bin1', i * div) + key = Support.gen_random_key(50, { :set => set }) + bin1 = Aerospike::Bin.new('bin1', (i + 1) * div) bin2 = Aerospike::Bin.new('bin2', -1) client.put(key, [bin1, bin2]) end @@ -170,7 +170,7 @@ recordset = client.scan_all(ns, set) cnt = 0 recordset.each do |rec| - expect(rec.bins['bin2']).to eq (rec.bins['bin1'] / div) + expect(rec.bins['bin2']).to eq(rec.bins['bin1'] / div) cnt += 1 end expect(cnt).to eq number_of_records @@ -184,7 +184,7 @@ number_of_records = 100 number_of_records.times do |i| - key = Support.gen_random_key(50, {:set => set}) + key = Support.gen_random_key(50, { :set => set }) bin1 = Aerospike::Bin.new('bin1', i * div) bin2 = Aerospike::Bin.new('bin2', -1) client.put(key, [bin1, bin2]) @@ -212,7 +212,7 @@ cnt = 0 recordset.each do |rec| if rec.bins['bin1'] <= number_of_records / 2 - expect(rec.bins['bin2']).to eq (rec.bins['bin1'] / div) + expect(rec.bins['bin2']).to eq(rec.bins['bin1'] / div) else expect(rec.bins['bin2']).to eq(-1) end diff --git a/spec/support/utils.rb b/spec/support/utils.rb index 9a975f15..7366e2a0 100644 --- a/spec/support/utils.rb +++ b/spec/support/utils.rb @@ -20,10 +20,10 @@ module Support RAND_CHARS = ('a'..'z').to_a.concat(('A'..'Z').to_a).concat(('0'..'9').to_a) - VERSION_REGEX = /\d+(?:.\d+)+(:?-\d+)?(?:-[a-z0-9]{8})?/.freeze + VERSION_REGEX = /\d+(?:.\d+)+(:?-\d+)?(?:-[a-z0-9]{8})?/ def self.rand_string(len) - RAND_CHARS.shuffle[0,len].join + RAND_CHARS.shuffle[0, len].join end def self.namespace @@ -37,7 +37,7 @@ def self.set_name def self.gen_random_key(len=50, opts = {}) key_val = opts[:key_val] || rand_string(len) set_name = opts[:set] || self.set_name - ns_name = opts[:ns] || self.namespace + ns_name = opts[:ns] || namespace Aerospike::Key.new(ns_name, set_name, key_val) end @@ -47,52 +47,69 @@ def self.delete_set(client, namespace, set_name) end package = "test_utils_delete_record.lua" - function = <