diff --git a/src/main/client/cdt_list_operate.c b/src/main/client/cdt_list_operate.c index c649be0fd3..26c09bf3f8 100644 --- a/src/main/client/cdt_list_operate.c +++ b/src/main/client/cdt_list_operate.c @@ -30,11 +30,6 @@ #include "cdt_list_operations.h" #include "cdt_operation_utils.h" -typedef struct { - int operation_code; - const char *operation_name; -} op_code_to_name; - const char *op_code_to_names[] = { #define X(op_name) [OP_##op_name] = #op_name X(LIST_APPEND), LIST_OP_NAMES_EXCEPT_LIST_APPEND diff --git a/src/main/client/cdt_map_operate.c b/src/main/client/cdt_map_operate.c index b3f850adde..ed60d840a2 100644 --- a/src/main/client/cdt_map_operate.c +++ b/src/main/client/cdt_map_operate.c @@ -37,22 +37,6 @@ static as_status get_map_return_type(as_error *err, PyObject *op_dict, int *return_type); -static as_status add_op_map_remove_by_value_rel_rank_range( - AerospikeClient *self, as_error *err, char *bin, PyObject *op_dict, - as_operations *ops, as_static_pool *static_pool, int serializer_type); - -static as_status add_op_map_get_by_value_rel_rank_range( - AerospikeClient *self, as_error *err, char *bin, PyObject *op_dict, - as_operations *ops, as_static_pool *static_pool, int serializer_type); - -static as_status add_op_map_remove_by_key_rel_index_range( - AerospikeClient *self, as_error *err, char *bin, PyObject *op_dict, - as_operations *ops, as_static_pool *static_pool, int serializer_type); - -static as_status add_op_map_get_by_key_rel_index_range( - AerospikeClient *self, as_error *err, char *bin, PyObject *op_dict, - as_operations *ops, as_static_pool *static_pool, int serializer_type); - as_status add_new_map_op(AerospikeClient *self, as_error *err, PyObject *op_dict, as_vector *unicodeStrVector, as_static_pool *static_pool, as_operations *ops, @@ -66,283 +50,120 @@ as_status add_new_map_op(AerospikeClient *self, as_error *err, return err->code; } - switch (operation_code) { - - case OP_MAP_REMOVE_BY_VALUE_RANK_RANGE_REL: { - return add_op_map_remove_by_value_rel_rank_range( - self, err, bin, op_dict, ops, static_pool, serializer_type); - } - - case OP_MAP_GET_BY_VALUE_RANK_RANGE_REL: { - return add_op_map_get_by_value_rel_rank_range( - self, err, bin, op_dict, ops, static_pool, serializer_type); - } - - case OP_MAP_REMOVE_BY_KEY_INDEX_RANGE_REL: { - return add_op_map_remove_by_key_rel_index_range( - self, err, bin, op_dict, ops, static_pool, serializer_type); - } - - case OP_MAP_GET_BY_KEY_INDEX_RANGE_REL: { - return add_op_map_get_by_key_rel_index_range( - self, err, bin, op_dict, ops, static_pool, serializer_type); - } - default: - // This should never be possible since we only get here if we know that the operation is valid. - return as_error_update(err, AEROSPIKE_ERR_PARAM, "Unknown operation"); - } - - return err->code; -} - -static as_status add_op_map_remove_by_value_rel_rank_range( - AerospikeClient *self, as_error *err, char *bin, PyObject *op_dict, - as_operations *ops, as_static_pool *static_pool, int serializer_type) -{ - bool count_present = false; - int64_t count; int return_type = AS_MAP_RETURN_VALUE; - int64_t rank; - as_val *value = NULL; - bool ctx_in_use = false; - as_cdt_ctx ctx; - if (get_map_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { return err->code; } - if (get_int64_t(err, AS_PY_RANK_KEY, op_dict, &rank) != AEROSPIKE_OK) { - return err->code; - } - - if (get_optional_int64_t(err, AS_PY_COUNT_KEY, op_dict, &count, - &count_present) != AEROSPIKE_OK) { - return err->code; - } - - if (get_asval(self, err, AS_PY_VAL_KEY, op_dict, &value, static_pool, - serializer_type, true) != AEROSPIKE_OK) { - return err->code; - } - - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { - return err->code; - } - - if (count_present) { - if (!as_operations_map_remove_by_value_rel_rank_range( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - (uint64_t)count, return_type)) { - as_cdt_ctx_destroy(&ctx); - return as_error_update( - err, AEROSPIKE_ERR_CLIENT, - "Failed to add map remove by value rank relative operation"); - } - } - else { - if (!as_operations_map_remove_by_value_rel_rank_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - return_type)) { - as_cdt_ctx_destroy(&ctx); - return as_error_update( - err, AEROSPIKE_ERR_CLIENT, - "Failed to add map remove by value rank relative operation"); - } - } - - if (ctx_in_use) { - as_cdt_ctx_destroy(&ctx); - } - - return AEROSPIKE_OK; -} - -static as_status add_op_map_get_by_value_rel_rank_range( - AerospikeClient *self, as_error *err, char *bin, PyObject *op_dict, - as_operations *ops, as_static_pool *static_pool, int serializer_type) -{ bool count_present = false; int64_t count; - int return_type = AS_MAP_RETURN_VALUE; - int64_t rank; - as_val *value = NULL; - bool ctx_in_use = false; - as_cdt_ctx ctx; - - if (get_map_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { - return err->code; - } - - if (get_int64_t(err, AS_PY_RANK_KEY, op_dict, &rank) != AEROSPIKE_OK) { - return err->code; - } - if (get_optional_int64_t(err, AS_PY_COUNT_KEY, op_dict, &count, &count_present) != AEROSPIKE_OK) { return err->code; } - if (get_asval(self, err, AS_PY_VAL_KEY, op_dict, &value, static_pool, - serializer_type, true) != AEROSPIKE_OK) { - return err->code; - } - - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { - return err->code; - } - - if (count_present) { - if (!as_operations_map_get_by_value_rel_rank_range( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - (uint64_t)count, return_type)) { - as_cdt_ctx_destroy(&ctx); - return as_error_update( - err, AEROSPIKE_ERR_CLIENT, - "Failed to add map get by value rank relative operation"); - } - } - else { - if (!as_operations_map_get_by_value_rel_rank_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, - return_type)) { - as_cdt_ctx_destroy(&ctx); - return as_error_update( - err, AEROSPIKE_ERR_CLIENT, - "Failed to add map get by value rank relative operation"); + int64_t rank; + as_val *value = NULL; + switch (operation_code) { + case OP_MAP_REMOVE_BY_VALUE_RANK_RANGE_REL: + case OP_MAP_GET_BY_VALUE_RANK_RANGE_REL: + if (get_int64_t(err, AS_PY_RANK_KEY, op_dict, &rank) != AEROSPIKE_OK) { + return err->code; } - } - if (ctx_in_use) { - as_cdt_ctx_destroy(&ctx); + if (get_asval(self, err, AS_PY_VAL_KEY, op_dict, &value, static_pool, + serializer_type, true) != AEROSPIKE_OK) { + return err->code; + } } - return AEROSPIKE_OK; -} - -static as_status add_op_map_remove_by_key_rel_index_range( - AerospikeClient *self, as_error *err, char *bin, PyObject *op_dict, - as_operations *ops, as_static_pool *static_pool, int serializer_type) -{ - bool count_present = false; - int64_t count; - int return_type = AS_MAP_RETURN_VALUE; - int64_t rank; as_val *key = NULL; - bool ctx_in_use = false; - as_cdt_ctx ctx; - - if (get_map_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { - return err->code; - } - - if (get_int64_t(err, AS_PY_INDEX_KEY, op_dict, &rank) != AEROSPIKE_OK) { - return err->code; - } - - if (get_optional_int64_t(err, AS_PY_COUNT_KEY, op_dict, &count, - &count_present) != AEROSPIKE_OK) { - return err->code; - } + switch (operation_code) { + case OP_MAP_REMOVE_BY_KEY_INDEX_RANGE_REL: + case OP_MAP_GET_BY_KEY_INDEX_RANGE_REL: + if (get_int64_t(err, AS_PY_INDEX_KEY, op_dict, &rank) != AEROSPIKE_OK) { + return err->code; + } - if (get_asval(self, err, AS_PY_MAP_KEY_KEY, op_dict, &key, static_pool, - serializer_type, true) != AEROSPIKE_OK) { - return err->code; + if (get_asval(self, err, AS_PY_MAP_KEY_KEY, op_dict, &key, static_pool, + serializer_type, true) != AEROSPIKE_OK) { + return err->code; + } } + as_cdt_ctx ctx; + bool ctx_in_use = false; if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, serializer_type) != AEROSPIKE_OK) { return err->code; } - if (count_present) { - if (!as_operations_map_remove_by_key_rel_index_range( - ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, - (uint64_t)count, return_type)) { - as_cdt_ctx_destroy(&ctx); - return as_error_update( - err, AEROSPIKE_ERR_CLIENT, - "Failed to add map remove by key rank relative operation"); + switch (operation_code) { + case OP_MAP_REMOVE_BY_VALUE_RANK_RANGE_REL: { + if (count_present) { + if (!as_operations_map_remove_by_value_rel_rank_range( + ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, + (uint64_t)count, return_type)) { + } } - } - else { - if (!as_operations_map_remove_by_key_rel_index_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, return_type)) { - as_cdt_ctx_destroy(&ctx); - return as_error_update( - err, AEROSPIKE_ERR_CLIENT, - "Failed to add map remove by key rank relative operation"); + else { + if (!as_operations_map_remove_by_value_rel_rank_range_to_end( + ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, + return_type)) { + } } } - if (ctx_in_use) { - as_cdt_ctx_destroy(&ctx); - } - - return AEROSPIKE_OK; -} - -static as_status add_op_map_get_by_key_rel_index_range( - AerospikeClient *self, as_error *err, char *bin, PyObject *op_dict, - as_operations *ops, as_static_pool *static_pool, int serializer_type) -{ - bool count_present = false; - int64_t count; - int return_type = AS_MAP_RETURN_VALUE; - int64_t rank; - as_val *key = NULL; - bool ctx_in_use = false; - as_cdt_ctx ctx; - - if (get_map_return_type(err, op_dict, &return_type) != AEROSPIKE_OK) { - return err->code; - } - - if (get_int64_t(err, AS_PY_INDEX_KEY, op_dict, &rank) != AEROSPIKE_OK) { - return err->code; - } - - if (get_optional_int64_t(err, AS_PY_COUNT_KEY, op_dict, &count, - &count_present) != AEROSPIKE_OK) { - return err->code; - } - - if (get_asval(self, err, AS_PY_MAP_KEY_KEY, op_dict, &key, static_pool, - serializer_type, true) != AEROSPIKE_OK) { - return err->code; + case OP_MAP_GET_BY_VALUE_RANK_RANGE_REL: { + if (count_present) { + if (!as_operations_map_get_by_value_rel_rank_range( + ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, + (uint64_t)count, return_type)) { + } + } + else { + if (!as_operations_map_get_by_value_rel_rank_range_to_end( + ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, + return_type)) { + } + } } - if (get_cdt_ctx(self, err, &ctx, op_dict, &ctx_in_use, static_pool, - serializer_type) != AEROSPIKE_OK) { - return err->code; + case OP_MAP_REMOVE_BY_KEY_INDEX_RANGE_REL: { + if (count_present) { + if (!as_operations_map_remove_by_value_rel_rank_range( + ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, + (uint64_t)count, return_type)) { + } + else { + if (!as_operations_map_remove_by_value_rel_rank_range_to_end( + ops, bin, (ctx_in_use ? &ctx : NULL), value, rank, + return_type)) { + } + } + } } - if (count_present) { - if (!as_operations_map_get_by_key_rel_index_range( - ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, - (uint64_t)count, return_type)) { - as_cdt_ctx_destroy(&ctx); - return as_error_update( - err, AEROSPIKE_ERR_CLIENT, - "Failed to add map get by key rank relative operation"); + case OP_MAP_GET_BY_KEY_INDEX_RANGE_REL: { + if (count_present) { + if (!as_operations_map_get_by_key_rel_index_range( + ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, + (uint64_t)count, return_type)) { + } } - } - else { - if (!as_operations_map_get_by_key_rel_index_range_to_end( - ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, return_type)) { - as_cdt_ctx_destroy(&ctx); - return as_error_update( - err, AEROSPIKE_ERR_CLIENT, - "Failed to add map get by key rank relative operation"); + else { + if (!as_operations_map_get_by_key_rel_index_range_to_end( + ops, bin, (ctx_in_use ? &ctx : NULL), key, rank, + return_type)) { + } } } - - if (ctx_in_use) { //add these spaces - as_cdt_ctx_destroy(&ctx); + default: + // This should never be possible since we only get here if we know that the operation is valid. + return as_error_update(err, AEROSPIKE_ERR_PARAM, "Unknown operation"); } - return AEROSPIKE_OK; + return err->code; } static as_status get_map_return_type(as_error *err, PyObject *op_dict,