diff --git a/src/box/lua/call.cc b/src/box/lua/call.cc index f0f6b38e9593d0b8814a30d740dbd516ce3e816f..0ed7344ca48cfbd31dfc91edd7d3d1650c79fc7e 100644 --- a/src/box/lua/call.cc +++ b/src/box/lua/call.cc @@ -361,6 +361,7 @@ lbox_update(lua_State *L) struct request *request = lbox_request_create(L, IPROTO_UPDATE, 3, 4); /* Ignore index_id for now */ + request->field_base = 1; /* field ids are one-indexed */ box_process(port_lua_create(L), request); return lua_gettop(L) - 4; } diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index e59d4f00e11a68b84b5a8effb5abc34a2d5393a3..f7c10d78e9daf0ccb1f0f578444007d092195830 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -128,7 +128,7 @@ box.schema.space.drop = function(space_id) end box.schema.space.rename = function(space_id, space_name) local _space = box.space[box.schema.SPACE_ID] - _space:update(space_id, {{"=", 2, space_name}}) + _space:update(space_id, {{"=", 3, space_name}}) end box.schema.index = {} @@ -179,7 +179,7 @@ box.schema.index.drop = function(space_id, index_id) end box.schema.index.rename = function(space_id, index_id, name) local _index = box.space[box.schema.INDEX_ID] - _index:update({space_id, index_id}, {{"=", 2, name}}) + _index:update({space_id, index_id}, {{"=", 3, name}}) end box.schema.index.alter = function(space_id, index_id, options) if box.space[space_id] == nil then @@ -214,10 +214,10 @@ box.schema.index.alter = function(space_id, index_id, options) table.insert(ops, {'=', field_no, value}) end end - add_op(options.id, 1) - add_op(options.name, 2) - add_op(options.type, 3) - add_op(options.unique, 4) + add_op(options.id, 2) + add_op(options.name, 3) + add_op(options.type, 4) + add_op(options.unique, 5) _index:update({space_id, index_id}, ops) return end @@ -537,7 +537,7 @@ function box.schema.space.bless(space) -- space_mt.inc = function(space, key) local key = keify(key) - local cnt_index = #key + local cnt_index = #key + 1 local tuple while true do tuple = space:update(key, {{'+', cnt_index, 1}}) @@ -547,7 +547,7 @@ function box.schema.space.bless(space) tuple = space:insert(data) if tuple ~= nil then break end end - return tuple[cnt_index + 1] + return tuple[cnt_index] end -- @@ -557,15 +557,15 @@ function box.schema.space.bless(space) -- space_mt.dec = function(space, key) local key = keify(key) - local cnt_index = #key + local cnt_index = #key + 1 local tuple = space:get(key) if tuple == nil then return 0 end - if tuple[cnt_index + 1] == 1 then + if tuple[cnt_index] == 1 then space:delete(key) return 0 else tuple = space:update(key, {{'-', cnt_index, 1}}) - return tuple[cnt_index + 1] + return tuple[cnt_index] end end @@ -729,7 +729,7 @@ box.schema.user.passwd = function(new_password) auth_mech_list = {} auth_mech_list["chap-sha1"] = box.schema.user.password(new_password) require('session').su('admin') - _user:update({uid}, {{"=", 4, auth_mech_list}}) + _user:update({uid}, {{"=", 5, auth_mech_list}}) require('session').su(uid) end @@ -807,7 +807,7 @@ box.schema.user.revoke = function(user_name, privilege, object_type, object_name local old_privilege = tuple[5] if old_privilege ~= privilege then privilege = bit.band(old_privilege, bit.bnot(privilege)) - _priv:update({uid, object_type, oid}, { "=", 4, privilege}) + _priv:update({uid, object_type, oid}, { "=", 5, privilege}) else _priv:delete{uid, object_type, oid} end diff --git a/src/box/lua/tuple.cc b/src/box/lua/tuple.cc index e09cbf54c3d6136b034564815fbe8f2d1923544a..e6e1918b321026f8551ead191fe89599ef06305b 100644 --- a/src/box/lua/tuple.cc +++ b/src/box/lua/tuple.cc @@ -231,12 +231,17 @@ lbox_tuple_transform(struct lua_State *L) uint32_t field_count = tuple_field_count(tuple); /* validate offset and len */ - if (offset < 0) { + if (offset == 0) { + luaL_error(L, "tuple.transform(): offset is out of bound"); + } else if (offset < 0) { if (-offset > field_count) luaL_error(L, "tuple.transform(): offset is out of bound"); offset += field_count; - } else if (offset > field_count) { - offset = field_count; + } else { + --offset; /* offset is one-indexed */ + if (offset > field_count) { + offset = field_count; + } } if (len < 0) luaL_error(L, "tuple.transform(): len is negative"); @@ -285,7 +290,8 @@ lbox_tuple_transform(struct lua_State *L) struct tuple *new_tuple = tuple_update(tuple_format_ber, tuple_update_region_alloc, &fiber()->gc, - tuple, tbuf_str(b), tbuf_end(b)); + tuple, tbuf_str(b), tbuf_end(b), + 0); lbox_pushtuple(L, new_tuple); return 1; } diff --git a/src/box/request.cc b/src/box/request.cc index 01e76b5e3b4af6e8d260ab9f597ddea6d66c9310..759f3bbb754102825374f882da6f42aa5b1fd0b2 100644 --- a/src/box/request.cc +++ b/src/box/request.cc @@ -123,7 +123,8 @@ execute_update(struct request *request, struct txn *txn, region_alloc_cb, &fiber()->gc, old_tuple, request->tuple, - request->tuple_end); + request->tuple_end, + request->field_base); TupleGuard guard(new_tuple); space_validate_tuple(space, new_tuple); txn_replace(txn, space, old_tuple, new_tuple, DUP_INSERT); diff --git a/src/box/request.h b/src/box/request.h index 46acbcd1177c8a16c6c767af27193b76a86a39ab..f5ff0ecca0caa19183914734bd9eba15c79b2b56 100644 --- a/src/box/request.h +++ b/src/box/request.h @@ -60,6 +60,7 @@ struct request /* Insert/replace tuple or proc argument or update operations. */ const char *tuple; const char *tuple_end; + int field_base; /* base field id offset, e.g. 0 for C and 1 for Lua */ request_execute_f execute; }; diff --git a/src/box/tuple.cc b/src/box/tuple.cc index f6dca523f782d48d4b8ba73455fbcde0faee642f..383304acec6c9566ef2e31e66ebb717eb5a4a030 100644 --- a/src/box/tuple.cc +++ b/src/box/tuple.cc @@ -380,13 +380,13 @@ struct tuple * tuple_update(struct tuple_format *format, void *(*region_alloc)(void *, size_t), void *alloc_ctx, const struct tuple *old_tuple, const char *expr, - const char *expr_end) + const char *expr_end, int field_base) { uint32_t new_size = 0; const char *new_data = tuple_update_execute(region_alloc, alloc_ctx, expr, expr_end, old_tuple->data, old_tuple->data + old_tuple->bsize, - &new_size); + &new_size, field_base); /* Allocate a new tuple. */ assert(mp_typeof(*new_data) == MP_ARRAY); diff --git a/src/box/tuple.h b/src/box/tuple.h index 571a7ea33c47594ab137f144f62d0227511c54b4..b07a3e4db7f11f3515e790424d45f67e800ecd3a 100644 --- a/src/box/tuple.h +++ b/src/box/tuple.h @@ -388,7 +388,7 @@ struct tuple * tuple_update(struct tuple_format *new_format, void *(*region_alloc)(void *, size_t), void *alloc_ctx, const struct tuple *old_tuple, - const char *expr, const char *expr_end); + const char *expr, const char *expr_end, int field_base); /** * @brief Compare two tuple fields using using field type definition diff --git a/src/box/tuple_update.cc b/src/box/tuple_update.cc index bb25f2897a71a9f4a66a4939b25fcae63e262811..5ce86d636581b876feafb8e420c475ca775e9dd7 100644 --- a/src/box/tuple_update.cc +++ b/src/box/tuple_update.cc @@ -547,7 +547,7 @@ update_write_tuple(struct tuple_update *update, char *buffer, char *buffer_end) static void update_read_ops(struct tuple_update *update, const char *expr, - const char *expr_end) + const char *expr_end, int field_base) { /* number of operations */ update->op_count = mp_decode_array(&expr); @@ -599,6 +599,14 @@ update_read_ops(struct tuple_update *update, const char *expr, if (args != op->meta->args) tnt_raise(ClientError, ER_UNKNOWN_UPDATE_OP); op->field_no = mp_read_int(&expr, "expected a field no (integer)"); + if (op->field_no != UINT32_MAX) { + /* Check that field_no is not zero for Lua (base = 1) */ + if (op->field_no < field_base) { + tnt_raise(ClientError, ER_NO_SUCH_FIELD, + op->field_no); + } + op->field_no -= field_base; + } op->meta->do_op(update, op, &expr); } @@ -611,7 +619,7 @@ const char * tuple_update_execute(region_alloc_func alloc, void *alloc_ctx, const char *expr,const char *expr_end, const char *old_data, const char *old_data_end, - uint32_t *p_tuple_len) + uint32_t *p_tuple_len, int field_base) { struct tuple_update *update = (struct tuple_update *) alloc(alloc_ctx, sizeof(*update)); @@ -621,7 +629,7 @@ tuple_update_execute(region_alloc_func alloc, void *alloc_ctx, update->alloc_ctx = alloc_ctx; update_create_rope(update, old_data, old_data_end); - update_read_ops(update, expr, expr_end); + update_read_ops(update, expr, expr_end, field_base); uint32_t tuple_len = update_calc_tuple_length(update); char *buffer = (char *) alloc(alloc_ctx, tuple_len); diff --git a/src/box/tuple_update.h b/src/box/tuple_update.h index acfd304f5212e22a58b4969acc8ca3220673cb6a..17348c70cda4b831461e2cfd3061b9a961c966e9 100644 --- a/src/box/tuple_update.h +++ b/src/box/tuple_update.h @@ -43,6 +43,6 @@ const char * tuple_update_execute(region_alloc_func alloc, void *alloc_ctx, const char *expr,const char *expr_end, const char *old_data, const char *old_data_end, - uint32_t *p_new_size); + uint32_t *p_new_size, int field_base); #endif /* TARANTOOL_BOX_TUPLE_UPDATE_H_INCLUDED */ diff --git a/test/big/lua.result b/test/big/lua.result index 9cf67d473ad8427495fcef49fdb503dfd8e0ba49..9476a6d404ef1dfbe36db1bd2a5fbd6fee436353 100644 --- a/test/big/lua.result +++ b/test/big/lua.result @@ -591,15 +591,15 @@ space:create_index('primary', { type = 'hash', parts = {1, 'str'}, unique = true t = space:insert{'1', '2', '3', '4', '5', '6', '7'} --- ... -t:transform(7, 0, '8', '9', '100') +t:transform(8, 0, '8', '9', '100') --- - ['1', '2', '3', '4', '5', '6', '7', '8', '9', '100'] ... -t:transform(0, 1) +t:transform(1, 1) --- - ['2', '3', '4', '5', '6', '7'] ... -t:transform(1, 4) +t:transform(2, 4) --- - ['1', '6', '7'] ... @@ -611,7 +611,7 @@ t:transform(-3, 2) --- - ['1', '2', '3', '4', '7'] ... -t:transform(0, 0, 'A') +t:transform(1, 0, 'A') --- - ['A', '1', '2', '3', '4', '5', '6', '7'] ... @@ -619,7 +619,7 @@ t:transform(-1, 0, 'A') --- - ['1', '2', '3', '4', '5', '6', 'A', '7'] ... -t:transform(0, 1, 'A') +t:transform(1, 1, 'A') --- - ['A', '2', '3', '4', '5', '6', '7'] ... @@ -627,19 +627,19 @@ t:transform(-1, 1, 'B') --- - ['1', '2', '3', '4', '5', '6', 'B'] ... -t:transform(0, 2, 'C') +t:transform(1, 2, 'C') --- - ['C', '3', '4', '5', '6', '7'] ... -t:transform(2, 0, 'hello') +t:transform(3, 0, 'hello') --- - ['1', '2', 'hello', '3', '4', '5', '6', '7'] ... -t:transform(0, -1, 'C') +t:transform(1, -1, 'C') --- - error: 'tuple.transform(): len is negative' ... -t:transform(0, 100) +t:transform(1, 100) --- - [] ... @@ -647,15 +647,15 @@ t:transform(-100, 1) --- - error: 'tuple.transform(): offset is out of bound' ... -t:transform(0, 3, 1, 2, 3) +t:transform(1, 3, 1, 2, 3) --- - [1, 2, 3, '4', '5', '6', '7'] ... -t:transform(3, 1, tonumber64(4)) +t:transform(4, 1, tonumber64(4)) --- - ['1', '2', '3', 4, '5', '6', '7'] ... -t:transform(0, 1, {}) +t:transform(1, 1, {}) --- - [[], '2', '3', '4', '5', '6', '7'] ... @@ -675,7 +675,7 @@ tab = {}; for i=1,n,1 do table.insert(tab, i) end t = box.tuple.new(tab) --- ... -t:transform(0, n - 1) +t:transform(1, n - 1) --- - [2000] ... diff --git a/test/big/lua.test.lua b/test/big/lua.test.lua index 8ec7bbd81fbbd7fc4272a35320e8e744d62691e1..1a2531d4d123f8446f3b8253f56b5195fe8c7e1e 100644 --- a/test/big/lua.test.lua +++ b/test/big/lua.test.lua @@ -212,23 +212,23 @@ space:drop() space = box.schema.create_space('tweedledum') space:create_index('primary', { type = 'hash', parts = {1, 'str'}, unique = true }) t = space:insert{'1', '2', '3', '4', '5', '6', '7'} -t:transform(7, 0, '8', '9', '100') -t:transform(0, 1) -t:transform(1, 4) +t:transform(8, 0, '8', '9', '100') +t:transform(1, 1) +t:transform(2, 4) t:transform(-1, 1) t:transform(-3, 2) -t:transform(0, 0, 'A') +t:transform(1, 0, 'A') t:transform(-1, 0, 'A') -t:transform(0, 1, 'A') +t:transform(1, 1, 'A') t:transform(-1, 1, 'B') -t:transform(0, 2, 'C') -t:transform(2, 0, 'hello') -t:transform(0, -1, 'C') -t:transform(0, 100) +t:transform(1, 2, 'C') +t:transform(3, 0, 'hello') +t:transform(1, -1, 'C') +t:transform(1, 100) t:transform(-100, 1) -t:transform(0, 3, 1, 2, 3) -t:transform(3, 1, tonumber64(4)) -t:transform(0, 1, {}) +t:transform(1, 3, 1, 2, 3) +t:transform(4, 1, tonumber64(4)) +t:transform(1, 1, {}) space:truncate() -- @@ -239,7 +239,7 @@ space:truncate() n = 2000 tab = {}; for i=1,n,1 do table.insert(tab, i) end t = box.tuple.new(tab) -t:transform(0, n - 1) +t:transform(1, n - 1) t = nil -- diff --git a/test/big/lua/push.lua b/test/big/lua/push.lua index 423946433eb56c6e8600193f91ff254f9298233f..154126f8e1b1cf9a998495cd7363f2ce5243ac52 100644 --- a/test/big/lua/push.lua +++ b/test/big/lua/push.lua @@ -8,9 +8,9 @@ function push_collection(space, size, cid, ...) if #append == 0 then return tuple end - tuple = tuple:transform( #tuple, 0, unpack( append ) ) + tuple = tuple:transform( #tuple + 1, 0, unpack( append ) ) if #tuple - 1 > tonumber(size) then - tuple = tuple:transform( 1, #tuple - 1 - tonumber(size) ) + tuple = tuple:transform( 2, #tuple - 1 - tonumber(size) ) end return space:replace{tuple:unpack()} end diff --git a/test/big/tree_pk_multipart.result b/test/big/tree_pk_multipart.result index 42fdc0a697043e948bd72f7174401b2f295d06a1..e5653c703b8d6cc6178eae9d5bb522e9d29f41fa 100644 --- a/test/big/tree_pk_multipart.result +++ b/test/big/tree_pk_multipart.result @@ -267,11 +267,11 @@ space:delete{'Vincent', 'The Wolf!', 0} --- - ['Vincent', 'The Wolf!', 0, 'A please would be nice.'] ... -space:update({'Vincent', 'The Wolf!', 1}, {{ '=', 0, 'Updated' }, {'=', 4, 'New'}}) +space:update({'Vincent', 'The Wolf!', 1}, {{ '=', 1, 'Updated' }, {'=', 5, 'New'}}) --- - ['Updated', 'The Wolf!', 1, 'I said a please would be nice.', 'New'] ... -space:update({'Updated', 'The Wolf!', 1}, {{ '=', 0, 'Vincent'}, { '#', 4, 1 }}) +space:update({'Updated', 'The Wolf!', 1}, {{ '=', 1, 'Vincent'}, { '#', 5, 1 }}) --- - ['Vincent', 'The Wolf!', 1, 'I said a please would be nice.'] ... @@ -309,11 +309,11 @@ space:delete{'The Wolf!', 'Vincent', 1, 'Come again?'} -- -- Update test -- -space:update({'The Wolf!', 'Vincent', 1}, {{'=', 3, '<ooops>'}}) +space:update({'The Wolf!', 'Vincent', 1}, {{'=', 4, '<ooops>'}}) --- - ['The Wolf!', 'Vincent', 1, '<ooops>'] ... -space:update({'Vincent', 'The Wolf!', 1}, {{'=', 3, '<ooops>'}}) +space:update({'Vincent', 'The Wolf!', 1}, {{'=', 4, '<ooops>'}}) --- - ['Vincent', 'The Wolf!', 1, '<ooops>'] ... @@ -335,16 +335,16 @@ space.index['primary']:select({'The Wolf!', 'Vincent'}) help`s not appreciated then lotsa luck, gentlemen.'] ... -- try to update a nonexistent message -space:update({'Vincent', 'The Wolf!', 3}, {{'=', 3, '<ooops>'}}) +space:update({'Vincent', 'The Wolf!', 4}, {{'=', 4, '<ooops>'}}) --- ... -- try to update patrial defined key -space:update({'Vincent', 'The Wolf!'}, {{'=', 3, '<ooops>'}}) +space:update({'Vincent', 'The Wolf!'}, {{'=', 4, '<ooops>'}}) --- - error: Invalid key part count in an exact match (expected 3, got 2) ... -- try to update by invalid key -space:update({'The Wolf!', 'Vincent', 1, 'Come again?'}, {{'=', 3, '<ooops>'}}) +space:update({'The Wolf!', 'Vincent', 1, 'Come again?'}, {{'=', 4, '<ooops>'}}) --- - error: Invalid key part count in an exact match (expected 3, got 4) ... diff --git a/test/big/tree_pk_multipart.test.lua b/test/big/tree_pk_multipart.test.lua index ec12c7a9f5bbf620137c70ca6603410580de4796..d80454726878658c5438228ad9f634fbcec4b39d 100644 --- a/test/big/tree_pk_multipart.test.lua +++ b/test/big/tree_pk_multipart.test.lua @@ -78,8 +78,8 @@ space:delete{'The Wolf!', 'Vincent', 0} space:delete{'The Wolf!', 'Vincent', 3} space:delete{'Vincent', 'The Wolf!', 0} -space:update({'Vincent', 'The Wolf!', 1}, {{ '=', 0, 'Updated' }, {'=', 4, 'New'}}) -space:update({'Updated', 'The Wolf!', 1}, {{ '=', 0, 'Vincent'}, { '#', 4, 1 }}) +space:update({'Vincent', 'The Wolf!', 1}, {{ '=', 1, 'Updated' }, {'=', 5, 'New'}}) +space:update({'Updated', 'The Wolf!', 1}, {{ '=', 1, 'Vincent'}, { '#', 5, 1 }}) -- Checking Vincent's last messages space.index['primary']:select({'Vincent', 'The Wolf!'}) -- Checking The Wolf's last messages @@ -95,8 +95,8 @@ space:delete{'The Wolf!', 'Vincent', 1, 'Come again?'} -- -- Update test -- -space:update({'The Wolf!', 'Vincent', 1}, {{'=', 3, '<ooops>'}}) -space:update({'Vincent', 'The Wolf!', 1}, {{'=', 3, '<ooops>'}}) +space:update({'The Wolf!', 'Vincent', 1}, {{'=', 4, '<ooops>'}}) +space:update({'Vincent', 'The Wolf!', 1}, {{'=', 4, '<ooops>'}}) -- Checking Vincent's last messages space.index['primary']:select({'Vincent', 'The Wolf!'}) @@ -104,11 +104,11 @@ space.index['primary']:select({'Vincent', 'The Wolf!'}) space.index['primary']:select({'The Wolf!', 'Vincent'}) -- try to update a nonexistent message -space:update({'Vincent', 'The Wolf!', 3}, {{'=', 3, '<ooops>'}}) +space:update({'Vincent', 'The Wolf!', 4}, {{'=', 4, '<ooops>'}}) -- try to update patrial defined key -space:update({'Vincent', 'The Wolf!'}, {{'=', 3, '<ooops>'}}) +space:update({'Vincent', 'The Wolf!'}, {{'=', 4, '<ooops>'}}) -- try to update by invalid key -space:update({'The Wolf!', 'Vincent', 1, 'Come again?'}, {{'=', 3, '<ooops>'}}) +space:update({'The Wolf!', 'Vincent', 1, 'Come again?'}, {{'=', 4, '<ooops>'}}) space:len() space:truncate() space:len() diff --git a/test/box/alter.result b/test/box/alter.result index 12d55ce0271427daf19f877cde65a64c314e40a0..1d454079d4b400085b3c122fb1ee105c30f1e6c0 100644 --- a/test/box/alter.result +++ b/test/box/alter.result @@ -69,11 +69,11 @@ _space:delete{_index.id} -- -- Can't change properties of a space -- -_space:update({_space.id}, {{'+', 0, 1}}) +_space:update({_space.id}, {{'+', 1, 1}}) --- - error: 'Can''t modify space 280: space id is immutable' ... -_space:update({_space.id}, {{'+', 0, 2}}) +_space:update({_space.id}, {{'+', 1, 2}}) --- - error: 'Can''t modify space 280: space id is immutable' ... @@ -114,7 +114,7 @@ space:replace{0, 0} --- - error: 'No index #0 is defined in space 321' ... -space:update({0}, {{'+', 0, 1}}) +space:update({0}, {{'+', 1, 1}}) --- - error: 'No index #0 is defined in space 321' ... diff --git a/test/box/alter.test.lua b/test/box/alter.test.lua index a72891e5c8eca2cde0a93dadf55372ea6ace70a1..5a2345ed07d9e26d1e7ba94c07cfa175930d8a9c 100644 --- a/test/box/alter.test.lua +++ b/test/box/alter.test.lua @@ -33,8 +33,8 @@ _space:delete{_index.id} -- -- Can't change properties of a space -- -_space:update({_space.id}, {{'+', 0, 1}}) -_space:update({_space.id}, {{'+', 0, 2}}) +_space:update({_space.id}, {{'+', 1, 1}}) +_space:update({_space.id}, {{'+', 1, 2}}) -- -- Create a space -- @@ -50,7 +50,7 @@ space.index[0] space:select{0} space:insert{0, 0} space:replace{0, 0} -space:update({0}, {{'+', 0, 1}}) +space:update({0}, {{'+', 1, 1}}) space:delete{0} t = _space:delete{space.id} space_deleted = box.space[t[1]] diff --git a/test/box/alter_limits.result b/test/box/alter_limits.result index 18463c9a7075f960799aba2106250d012effc83a..f03a38d38630c715a302a785cab82b37fb0201f8 100644 --- a/test/box/alter_limits.result +++ b/test/box/alter_limits.result @@ -145,7 +145,7 @@ s:delete{0} --- - error: 'No index #0 is defined in space 512' ... -s:update(0, {{"=", 0, 0}}) +s:update(0, {{"=", 1, 0}}) --- - error: 'No index #0 is defined in space 512' ... @@ -257,7 +257,7 @@ FIELD_COUNT = 4 --- ... -- increase field_count -- error -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 3}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) --- - error: 'Can''t modify space 512: can not change field count on a non-empty space' ... @@ -266,12 +266,12 @@ s:select{} - - [1, 2] ... -- decrease field_count - error -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 1}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 1}}) --- - error: 'Can''t modify space 512: can not change field count on a non-empty space' ... -- remove field_count - ok -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 0}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 0}}) --- - [512, 1, 'test', 'memtx', 0, ''] ... @@ -280,7 +280,7 @@ s:select{} - - [1, 2] ... -- increase field_count - error -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 3}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) --- - error: 'Can''t modify space 512: can not change field count on a non-empty space' ... @@ -292,7 +292,7 @@ s:select{} - [] ... -- set field_count of an empty space -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 3}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) --- - [512, 1, 'test', 'memtx', 3, ''] ... @@ -778,7 +778,7 @@ s.index.primary:select{} - ['Homevideo', 2011] - ['No such movie', 999] ... -box.space['_index']:update({s.id, s.index.year.id}, {{"=", 7, 'num'}}) +box.space['_index']:update({s.id, s.index.year.id}, {{"=", 8, 'num'}}) --- - [512, 1, 'year', 'tree', 0, 1, 1, 'num'] ... diff --git a/test/box/alter_limits.test.lua b/test/box/alter_limits.test.lua index 8bad5a54ebfaf5e03d29275874dbadd7c3d304aa..1406fec524dd76b1c4e1e354fdb551d12712eb1f 100644 --- a/test/box/alter_limits.test.lua +++ b/test/box/alter_limits.test.lua @@ -52,7 +52,7 @@ s = box.schema.create_space('tweedledum') s:insert{0} s:select{} s:delete{0} -s:update(0, {{"=", 0, 0}}) +s:update(0, {{"=", 1, 0}}) s:insert{0} s.index[0] s:truncate() @@ -91,19 +91,19 @@ s:select{} FIELD_COUNT = 4 -- increase field_count -- error -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 3}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) s:select{} -- decrease field_count - error -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 1}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 1}}) -- remove field_count - ok -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 0}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 0}}) s:select{} -- increase field_count - error -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 3}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) s:truncate() s:select{} -- set field_count of an empty space -box.space['_space']:update(s.id, {{"=", FIELD_COUNT, 3}}) +box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) s:select{} -- field_count actually works s:insert{3, 4} @@ -270,7 +270,7 @@ s:create_index('nodups', { type = 'tree', unique=true, parts = { 2, 'num'} }) -- change of non-unique index to unique: same effect s.index.year:alter({unique=true}) s.index.primary:select{} -box.space['_index']:update({s.id, s.index.year.id}, {{"=", 7, 'num'}}) +box.space['_index']:update({s.id, s.index.year.id}, {{"=", 8, 'num'}}) -- ambiguous field type s:create_index('str', { type = 'tree', unique = false, parts = { 2, 'str'}}) -- create index on a non-existing field diff --git a/test/box/call.result b/test/box/call.result index 0f05df40b861b10ba1de97bd29cb8ee46debc8bd..85128be8445e3e45f84b9430bcbb8533f011b301 100644 --- a/test/box/call.result +++ b/test/box/call.result @@ -326,7 +326,7 @@ call myinsert(3, 'old', 2) errcode: ER_TUPLE_FOUND errmsg: Duplicate key exists in unique index 0 ... -space:update({3}, {{'=', 0, 4}, {'=', 1, 'new'}}) +space:update({3}, {{'=', 1, 4}, {'=', 2, 'new'}}) --- - [4, 'new', 2] ... @@ -338,11 +338,11 @@ call space:select(4) --- - [4, 'new', 2] ... -space:update({4}, {{'+', 2, 1}}) +space:update({4}, {{'+', 3, 1}}) --- - [4, 'new', 3] ... -space:update({4}, {{'-', 2, 1}}) +space:update({4}, {{'-', 3, 1}}) --- - [4, 'new', 2] ... diff --git a/test/box/call.test.py b/test/box/call.test.py index 0cccbc9dc57de1cd81f63ecdf0389f3edc499553..30e9c12d2e6d87f64c0aa47120685540dad931af 100644 --- a/test/box/call.test.py +++ b/test/box/call.test.py @@ -108,11 +108,11 @@ sql("call space:delete(2)") sql("call myinsert(3, 'old', 2)") # test that insert produces a duplicate key error sql("call myinsert(3, 'old', 2)") -admin("space:update({3}, {{'=', 0, 4}, {'=', 1, 'new'}})") +admin("space:update({3}, {{'=', 1, 4}, {'=', 2, 'new'}})") sql("call space:get(4)") sql("call space:select(4)") -admin("space:update({4}, {{'+', 2, 1}})") -admin("space:update({4}, {{'-', 2, 1}})") +admin("space:update({4}, {{'+', 3, 1}})") +admin("space:update({4}, {{'-', 3, 1}})") sql("call space:get(4)") sql("call space:select(4)") admin("function field_x(key, field_index) return space:get(key)[field_index] end") diff --git a/test/box/errinj.result b/test/box/errinj.result index 98730488624ee0fe13b87b8b8bd779456c619633..b12dcf3861ef1132049fb4c0361740b3e3b92460 100644 --- a/test/box/errinj.result +++ b/test/box/errinj.result @@ -65,7 +65,7 @@ errinj.set("ERRINJ_WAL_IO", true) --- - ok ... -space:update(1, {{'=', 0, 2}}) +space:update(1, {{'=', 1, 2}}) --- - error: Failed to write to disk ... @@ -107,7 +107,7 @@ errinj.set("ERRINJ_WAL_ROTATE", true) --- - ok ... -space:update(1, {{'=', 0, 2}}) +space:update(1, {{'=', 1, 2}}) --- - error: Failed to write to disk ... @@ -122,7 +122,7 @@ errinj.set("ERRINJ_WAL_ROTATE", false) --- - ok ... -space:update(1, {{'=', 0, 2}}) +space:update(1, {{'=', 1, 2}}) --- - [2] ... diff --git a/test/box/errinj.test.lua b/test/box/errinj.test.lua index cfcdc98e19523f50413d37c729028267fddfc373..45bebb3f53f9415929048e0466303c325c8ef814 100644 --- a/test/box/errinj.test.lua +++ b/test/box/errinj.test.lua @@ -18,7 +18,7 @@ space:get{1} errinj.set("ERRINJ_WAL_IO", false) space:insert{1} errinj.set("ERRINJ_WAL_IO", true) -space:update(1, {{'=', 0, 2}}) +space:update(1, {{'=', 1, 2}}) space:get{1} space:get{2} errinj.set("ERRINJ_WAL_IO", false) @@ -31,11 +31,11 @@ space:get{1} errinj.set("ERRINJ_WAL_ROTATE", false) space:insert{1} errinj.set("ERRINJ_WAL_ROTATE", true) -space:update(1, {{'=', 0, 2}}) +space:update(1, {{'=', 1, 2}}) space:get{1} space:get{2} errinj.set("ERRINJ_WAL_ROTATE", false) -space:update(1, {{'=', 0, 2}}) +space:update(1, {{'=', 1, 2}}) space:get{1} space:get{2} errinj.set("ERRINJ_WAL_ROTATE", true) diff --git a/test/box/fiber.result b/test/box/fiber.result index fa4ab8e60ff2347455204a5683a5c2c9e527cfbb..a6f61ceb1fc557816885a27ae5dd08a148906269 100644 --- a/test/box/fiber.result +++ b/test/box/fiber.result @@ -143,26 +143,26 @@ space:insert{1953719668, 'old', 1684234849} --- - error: Duplicate key exists in unique index 0 ... -space:update(1953719668, {{'=', 0, 1936941424}, {'=', 1, 'new'}}) +space:update(1953719668, {{'=', 1, 1936941424}, {'=', 2, 'new'}}) --- - [1936941424, 'new', 1684234849] ... -space:update(1234567890, {{'+', 2, 1}}) +space:update(1234567890, {{'+', 3, 1}}) --- ... -space:update(1936941424, {{'+', 2, 1}}) +space:update(1936941424, {{'+', 3, 1}}) --- - [1936941424, 'new', 1684234850] ... -space:update(1936941424, {{'-', 2, 1}}) +space:update(1936941424, {{'-', 3, 1}}) --- - [1936941424, 'new', 1684234849] ... -space:update(1936941424, {{'-', 2, 1}}) +space:update(1936941424, {{'-', 3, 1}}) --- - [1936941424, 'new', 1684234848] ... -space:update(1936941424, {{'+', 2, 1}}) +space:update(1936941424, {{'+', 3, 1}}) --- - [1936941424, 'new', 1684234849] ... @@ -191,7 +191,7 @@ space:insert{1953719668, 'hello world'} --- - [1953719668, 'hello world'] ... -space:update(1953719668, {{'=', 1, 'bye, world'}}) +space:update(1953719668, {{'=', 2, 'bye, world'}}) --- - [1953719668, 'bye, world'] ... diff --git a/test/box/fiber.test.lua b/test/box/fiber.test.lua index 08d422aeac79b01dbfb5c65ef56ac3d693958ce5..87c8b1a03f84d3eca36ce9f838cb52365285a128 100644 --- a/test/box/fiber.test.lua +++ b/test/box/fiber.test.lua @@ -42,12 +42,12 @@ space:delete{1667655012} space:insert{1953719668, 'old', 1684234849} -- test that insert produces a duplicate key error space:insert{1953719668, 'old', 1684234849} -space:update(1953719668, {{'=', 0, 1936941424}, {'=', 1, 'new'}}) -space:update(1234567890, {{'+', 2, 1}}) -space:update(1936941424, {{'+', 2, 1}}) -space:update(1936941424, {{'-', 2, 1}}) -space:update(1936941424, {{'-', 2, 1}}) -space:update(1936941424, {{'+', 2, 1}}) +space:update(1953719668, {{'=', 1, 1936941424}, {'=', 2, 'new'}}) +space:update(1234567890, {{'+', 3, 1}}) +space:update(1936941424, {{'+', 3, 1}}) +space:update(1936941424, {{'-', 3, 1}}) +space:update(1936941424, {{'-', 3, 1}}) +space:update(1936941424, {{'+', 3, 1}}) space:delete{1936941424} -- must be read-only @@ -56,7 +56,7 @@ space:insert{1684234849} space:delete{1953719668} space:delete{1684234849} space:insert{1953719668, 'hello world'} -space:update(1953719668, {{'=', 1, 'bye, world'}}) +space:update(1953719668, {{'=', 2, 'bye, world'}}) space:delete{1953719668} -- test tuple iterators t = space:insert{1953719668} diff --git a/test/box/lua/fifo.lua b/test/box/lua/fifo.lua index b181c7c3b3cf438c054b3d2a8f69050062cb2681..ae1cd835b41daa11bba8824d5eb24babb1fa40ea 100644 --- a/test/box/lua/fifo.lua +++ b/test/box/lua/fifo.lua @@ -23,7 +23,7 @@ function fifo_push(space, name, val) elseif bottom == top then bottom = bottom + 1 end - return space:update({name}, {{'=', 1, top}, {'=', 2, bottom }, {'=', top - 1, val}}) + return space:update({name}, {{'=', 2, top}, {'=', 3, bottom }, {'=', top, val}}) end function fifo_top(space, name) fifo = find_or_create_fifo(space, name) diff --git a/test/box/net.box.result b/test/box/net.box.result index 6b99b180672543749b26b18180c883119902ffc4..6adeae9833e6ad5dcdc9199c128828bb152a57cd 100644 --- a/test/box/net.box.result +++ b/test/box/net.box.result @@ -213,7 +213,7 @@ type(foo) --- - table ... -space:update(123, {{'=', 1, 'test1-updated'}}) +space:update(123, {{'=', 2, 'test1-updated'}}) --- - [123, 'test1-updated', 'test2'] ... diff --git a/test/box/net.box.test.lua b/test/box/net.box.test.lua index b983d359f1b4df267b6dd3cdfd81f2a7e89b3a72..b4f98eed617fa03a11fece3f82d05f262cb6e2db 100644 --- a/test/box/net.box.test.lua +++ b/test/box/net.box.test.lua @@ -66,7 +66,7 @@ slf, foo = require('box.internal').call_loadproc('box.net.self:select') type(slf) type(foo) -space:update(123, {{'=', 1, 'test1-updated'}}) +space:update(123, {{'=', 2, 'test1-updated'}}) remote:update(space.id, 123, {{'=', 2, 'test2-updated'}}) space:insert{123, 'test1', 'test2'} diff --git a/test/box/temp_spaces.result b/test/box/temp_spaces.result index 54cdd138b5b4ac55f0f1e6a1b463fc72078c8fe5..1fc7150176400cefce9d3ed93b79b199f4de1253 100644 --- a/test/box/temp_spaces.result +++ b/test/box/temp_spaces.result @@ -1,6 +1,6 @@ -- temporary spaces -- not a temporary -FLAGS = 5 +FLAGS = 6 --- ... s = box.schema.create_space('t', { temporary = true }) @@ -63,7 +63,7 @@ box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, ''}}) ... --# stop server default --# start server default -FLAGS = 5 +FLAGS = 6 --- ... s = box.space.t @@ -79,7 +79,7 @@ s.temporary ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}}) --- -- [512, 1, 't', 'memtx', 0, 'no-temporary'] +- [512, 1, 't', 'memtx', 0, 'no-temporary', 'temporary'] ... s.temporary --- @@ -87,7 +87,7 @@ s.temporary ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, ',:asfda:temporary'}}) --- -- [512, 1, 't', 'memtx', 0, ',:asfda:temporary'] +- [512, 1, 't', 'memtx', 0, ',:asfda:temporary', 'temporary'] ... s.temporary --- @@ -95,7 +95,7 @@ s.temporary ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'a,b,c,d,e'}}) --- -- [512, 1, 't', 'memtx', 0, 'a,b,c,d,e'] +- [512, 1, 't', 'memtx', 0, 'a,b,c,d,e', 'temporary'] ... s.temporary --- @@ -103,7 +103,7 @@ s.temporary ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}}) --- -- [512, 1, 't', 'memtx', 0, 'temporary'] +- [512, 1, 't', 'memtx', 0, 'temporary', 'temporary'] ... s.temporary --- @@ -118,7 +118,7 @@ s:insert{1, 2, 3} ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}}) --- -- [512, 1, 't', 'memtx', 0, 'temporary'] +- [512, 1, 't', 'memtx', 0, 'temporary', 'temporary'] ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}}) --- @@ -130,7 +130,7 @@ s:delete{1} ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}}) --- -- [512, 1, 't', 'memtx', 0, 'no-temporary'] +- [512, 1, 't', 'memtx', 0, 'no-temporary', 'temporary'] ... s:drop() --- diff --git a/test/box/temp_spaces.test.lua b/test/box/temp_spaces.test.lua index 56830b91a3ec2c2b3736d6bee81b6c001f616555..82e4953fd05227aa035fbfc3d3db6560104a0a5f 100644 --- a/test/box/temp_spaces.test.lua +++ b/test/box/temp_spaces.test.lua @@ -1,6 +1,6 @@ -- temporary spaces -- not a temporary -FLAGS = 5 +FLAGS = 6 s = box.schema.create_space('t', { temporary = true }) s.temporary s:drop() @@ -27,7 +27,7 @@ box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, ''}}) --# stop server default --# start server default -FLAGS = 5 +FLAGS = 6 s = box.space.t s:len() diff --git a/test/box/update.result b/test/box/update.result index 8b5a6c36f6adc5d3f9f57c670f94becc58e2e1ad..89329cfdc859fbcf7cde378a8bdfc83f2dbf0077 100644 --- a/test/box/update.result +++ b/test/box/update.result @@ -9,23 +9,23 @@ s:insert{1000001, 1000002, 1000003, 1000004, 1000005} --- - [1000001, 1000002, 1000003, 1000004, 1000005] ... -s:update({1000001}, {{'#', 0, 1}}) +s:update({1000001}, {{'#', 1, 1}}) --- - [1000002, 1000003, 1000004, 1000005] ... -s:update({1000002}, {{'#', 0, 1}}) +s:update({1000002}, {{'#', 1, 1}}) --- - [1000003, 1000004, 1000005] ... -s:update({1000003}, {{'#', 0, 1}}) +s:update({1000003}, {{'#', 1, 1}}) --- - [1000004, 1000005] ... -s:update({1000004}, {{'#', 0, 1}}) +s:update({1000004}, {{'#', 1, 1}}) --- - [1000005] ... -s:update({1000005}, {{'#', 0, 1}}) +s:update({1000005}, {{'#', 1, 1}}) --- - error: Tuple field count 0 is less than required by a defined index (expected 1) ... @@ -37,43 +37,43 @@ s:insert{1, 0} --- - [1, 0] ... -s:update(1, {{'+', 1, 10}}) +s:update(1, {{'+', 2, 10}}) --- - [1, 10] ... -s:update(1, {{'+', 1, 15}}) +s:update(1, {{'+', 2, 15}}) --- - [1, 25] ... -s:update(1, {{'-', 1, 5}}) +s:update(1, {{'-', 2, 5}}) --- - [1, 20] ... -s:update(1, {{'-', 1, 20}}) +s:update(1, {{'-', 2, 20}}) --- - [1, 0] ... -s:update(1, {{'|', 1, 0x9}}) +s:update(1, {{'|', 2, 0x9}}) --- - [1, 9] ... -s:update(1, {{'|', 1, 0x6}}) +s:update(1, {{'|', 2, 0x6}}) --- - [1, 15] ... -s:update(1, {{'&', 1, 0xabcde}}) +s:update(1, {{'&', 2, 0xabcde}}) --- - [1, 14] ... -s:update(1, {{'&', 1, 0x2}}) +s:update(1, {{'&', 2, 0x2}}) --- - [1, 2] ... -s:update(1, {{'^', 1, 0xa2}}) +s:update(1, {{'^', 2, 0xa2}}) --- - [1, 160] ... -s:update(1, {{'^', 1, 0xa2}}) +s:update(1, {{'^', 2, 0xa2}}) --- - [1, 2] ... @@ -87,30 +87,30 @@ s:insert{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} ... s:update({0}, {{'#', 42, 1}}) --- -- error: Field 42 was not found in the tuple +- error: Field 41 was not found in the tuple ... -s:update({0}, {{'#', 3, 'abirvalg'}}) +s:update({0}, {{'#', 4, 'abirvalg'}}) --- - error: 'Argument type in operation on field 3 does not match field type: expected a UINT' ... -s:update({0}, {{'#', 1, 1}, {'#', 3, 2}, {'#', 5, 1}}) +s:update({0}, {{'#', 2, 1}, {'#', 4, 2}, {'#', 6, 1}}) --- - [0, 2, 3, 6, 7, 9, 10, 11, 12, 13, 14, 15] ... -s:update({0}, {{'#', 3, 3}}) +s:update({0}, {{'#', 4, 3}}) --- - [0, 2, 3, 10, 11, 12, 13, 14, 15] ... -s:update({0}, {{'#', 4, 123456}}) +s:update({0}, {{'#', 5, 123456}}) --- - [0, 2, 3, 10] ... -s:update({0}, {{'#', 2, 4294967295}}) +s:update({0}, {{'#', 3, 4294967295}}) --- - [0, 2] ... -s:update({0}, {{'#', 1, 0}}) +s:update({0}, {{'#', 2, 0}}) --- - error: 'Field 1 UPDATE error: cannot delete 0 fields' ... @@ -122,15 +122,15 @@ s:insert{1, 3, 6, 9} --- - [1, 3, 6, 9] ... -s:update({1}, {{'!', 1, 2}}) +s:update({1}, {{'!', 2, 2}}) --- - [1, 2, 3, 6, 9] ... -s:update({1}, {{'!', 3, 4}, {'!', 3, 5}, {'!', 4, 7}, {'!', 4, 8}}) +s:update({1}, {{'!', 4, 4}, {'!', 4, 5}, {'!', 5, 7}, {'!', 5, 8}}) --- - [1, 2, 3, 5, 8, 7, 4, 6, 9] ... -s:update({1}, {{'!', 9, 10}, {'!', 9, 11}, {'!', 9, 12}}) +s:update({1}, {{'!', 10, 10}, {'!', 10, 11}, {'!', 10, 12}}) --- - [1, 2, 3, 5, 8, 7, 4, 6, 9, 12, 11, 10] ... @@ -141,7 +141,7 @@ s:insert{1, 'tuple'} --- - [1, 'tuple'] ... -s:update({1}, {{'#', 1, 1}, {'!', 1, 'inserted tuple'}, {'=', 2, 'set tuple'}}) +s:update({1}, {{'#', 2, 1}, {'!', 2, 'inserted tuple'}, {'=', 3, 'set tuple'}}) --- - [1, 'inserted tuple', 'set tuple'] ... @@ -152,11 +152,11 @@ s:insert{1, 'tuple'} --- - [1, 'tuple'] ... -s:update({1}, {{'=', 1, 'set tuple'}, {'!', 1, 'inserted tuple'}, {'#', 2, 1}}) +s:update({1}, {{'=', 2, 'set tuple'}, {'!', 2, 'inserted tuple'}, {'#', 3, 1}}) --- - [1, 'inserted tuple'] ... -s:update({1}, {{'!', 0, 3}, {'!', 0, 2}}) +s:update({1}, {{'!', 1, 3}, {'!', 1, 2}}) --- - [2, 3, 1, 'inserted tuple'] ... @@ -168,17 +168,17 @@ s:replace{1, 'field string value'} --- - [1, 'field string value'] ... -s:update({1}, {{'=', 1, 'new field string value'}, {'=', 2, 42}, {'=', 3, 0xdeadbeef}}) +s:update({1}, {{'=', 2, 'new field string value'}, {'=', 3, 42}, {'=', 4, 0xdeadbeef}}) --- - [1, 'new field string value', 42, 3735928559] ... -- test multiple update opearations on the same field -s:update({1}, {{'+', 2, 16}, {'&', 3, 0xffff0000}, {'|', 3, 0x0000a0a0}, {'^', 3, 0xffff00aa}}) +s:update({1}, {{'+', 3, 16}, {'&', 4, 0xffff0000}, {'|', 4, 0x0000a0a0}, {'^', 4, 0xffff00aa}}) --- - error: 'Field 3 UPDATE error: double update of the same field' ... -- test update splice operation -s:update({1}, {{':', 1, 0, 3, 'the newest'}}) +s:update({1}, {{':', 2, 0, 3, 'the newest'}}) --- - [1, 'the newest field string value', 42, 3735928559] ... @@ -186,20 +186,20 @@ s:replace{1953719668, 'something to splice'} --- - [1953719668, 'something to splice'] ... -s:update(1953719668, {{':', 1, 0, 4, 'no'}}) +s:update(1953719668, {{':', 2, 0, 4, 'no'}}) --- - [1953719668, 'nothing to splice'] ... -s:update(1953719668, {{':', 1, 0, 2, 'every'}}) +s:update(1953719668, {{':', 2, 0, 2, 'every'}}) --- - [1953719668, 'everything to splice'] ... -- check an incorrect offset -s:update(1953719668, {{':', 1, 100, 2, 'every'}}) +s:update(1953719668, {{':', 2, 100, 2, 'every'}}) --- - [1953719668, 'everything to spliceevery'] ... -s:update(1953719668, {{':', 1, -100, 2, 'every'}}) +s:update(1953719668, {{':', 2, -100, 2, 'every'}}) --- - error: 'Field SPLICE error: offset is out of bound' ... @@ -220,7 +220,7 @@ s:insert{1953719668, 'hello world'} --- - [1953719668, 'hello world'] ... -s:update(1953719668, {{'=', 1, 'bye, world'}}) +s:update(1953719668, {{'=', 2, 'bye, world'}}) --- - [1953719668, 'bye, world'] ... @@ -229,22 +229,34 @@ s:delete{1953719668} - [1953719668, 'bye, world'] ... -- test update delete operations -s:update({1}, {{'#', 3, 1}, {'#', 2, 1}}) +s:update({1}, {{'#', 4, 1}, {'#', 3, 1}}) --- ... -- test update insert operations -s:update({1}, {{'!', 1, 1}, {'!', 1, 2}, {'!', 1, 3}, {'!', 1, 4}}) +s:update({1}, {{'!', 2, 1}, {'!', 2, 2}, {'!', 2, 3}, {'!', 2, 4}}) --- ... s:truncate() --- ... +-- s:update: zero field +s:insert{48} +--- +- [48] +... +s:update(48, {{'=', 0, 'hello'}}) +--- +- error: Field 0 was not found in the tuple +... +s:truncate() +--- +... -- s:update: push/pop fields s:insert{1684234849} --- - [1684234849] ... -s:update({1684234849}, {{'#', 1, 1}}) +s:update({1684234849}, {{'#', 2, 1}}) --- - error: Field 1 was not found in the tuple ... @@ -260,15 +272,15 @@ s:update({1684234849}, {{'=', -1, 'push3'}}) --- - [1684234849, 'push1', 'push2', 'push3'] ... -s:update({1684234849}, {{'#', 1, 1}, {'=', -1, 'swap1'}}) +s:update({1684234849}, {{'#', 2, 1}, {'=', -1, 'swap1'}}) --- - [1684234849, 'push2', 'push3', 'swap1'] ... -s:update({1684234849}, {{'#', 1, 1}, {'=', -1, 'swap2'}}) +s:update({1684234849}, {{'#', 2, 1}, {'=', -1, 'swap2'}}) --- - [1684234849, 'push3', 'swap1', 'swap2'] ... -s:update({1684234849}, {{'#', 1, 1}, {'=', -1, 'swap3'}}) +s:update({1684234849}, {{'#', 2, 1}, {'=', -1, 'swap3'}}) --- - [1684234849, 'swap1', 'swap2', 'swap3'] ... diff --git a/test/box/update.test.lua b/test/box/update.test.lua index 24c367851987078e51f0dbb0ba7e3ede68a0684a..4eec6c4af720c3daef27ce1222fa05a0212e4821 100644 --- a/test/box/update.test.lua +++ b/test/box/update.test.lua @@ -3,92 +3,97 @@ s:create_index('pk') -- test delete field s:insert{1000001, 1000002, 1000003, 1000004, 1000005} -s:update({1000001}, {{'#', 0, 1}}) -s:update({1000002}, {{'#', 0, 1}}) -s:update({1000003}, {{'#', 0, 1}}) -s:update({1000004}, {{'#', 0, 1}}) -s:update({1000005}, {{'#', 0, 1}}) +s:update({1000001}, {{'#', 1, 1}}) +s:update({1000002}, {{'#', 1, 1}}) +s:update({1000003}, {{'#', 1, 1}}) +s:update({1000004}, {{'#', 1, 1}}) +s:update({1000005}, {{'#', 1, 1}}) s:truncate() -- test arithmetic s:insert{1, 0} -s:update(1, {{'+', 1, 10}}) -s:update(1, {{'+', 1, 15}}) -s:update(1, {{'-', 1, 5}}) -s:update(1, {{'-', 1, 20}}) -s:update(1, {{'|', 1, 0x9}}) -s:update(1, {{'|', 1, 0x6}}) -s:update(1, {{'&', 1, 0xabcde}}) -s:update(1, {{'&', 1, 0x2}}) -s:update(1, {{'^', 1, 0xa2}}) -s:update(1, {{'^', 1, 0xa2}}) +s:update(1, {{'+', 2, 10}}) +s:update(1, {{'+', 2, 15}}) +s:update(1, {{'-', 2, 5}}) +s:update(1, {{'-', 2, 20}}) +s:update(1, {{'|', 2, 0x9}}) +s:update(1, {{'|', 2, 0x6}}) +s:update(1, {{'&', 2, 0xabcde}}) +s:update(1, {{'&', 2, 0x2}}) +s:update(1, {{'^', 2, 0xa2}}) +s:update(1, {{'^', 2, 0xa2}}) s:truncate() -- test delete multiple fields s:insert{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} s:update({0}, {{'#', 42, 1}}) -s:update({0}, {{'#', 3, 'abirvalg'}}) -s:update({0}, {{'#', 1, 1}, {'#', 3, 2}, {'#', 5, 1}}) -s:update({0}, {{'#', 3, 3}}) -s:update({0}, {{'#', 4, 123456}}) -s:update({0}, {{'#', 2, 4294967295}}) -s:update({0}, {{'#', 1, 0}}) +s:update({0}, {{'#', 4, 'abirvalg'}}) +s:update({0}, {{'#', 2, 1}, {'#', 4, 2}, {'#', 6, 1}}) +s:update({0}, {{'#', 4, 3}}) +s:update({0}, {{'#', 5, 123456}}) +s:update({0}, {{'#', 3, 4294967295}}) +s:update({0}, {{'#', 2, 0}}) s:truncate() -- test insert field s:insert{1, 3, 6, 9} -s:update({1}, {{'!', 1, 2}}) -s:update({1}, {{'!', 3, 4}, {'!', 3, 5}, {'!', 4, 7}, {'!', 4, 8}}) -s:update({1}, {{'!', 9, 10}, {'!', 9, 11}, {'!', 9, 12}}) +s:update({1}, {{'!', 2, 2}}) +s:update({1}, {{'!', 4, 4}, {'!', 4, 5}, {'!', 5, 7}, {'!', 5, 8}}) +s:update({1}, {{'!', 10, 10}, {'!', 10, 11}, {'!', 10, 12}}) s:truncate() s:insert{1, 'tuple'} -s:update({1}, {{'#', 1, 1}, {'!', 1, 'inserted tuple'}, {'=', 2, 'set tuple'}}) +s:update({1}, {{'#', 2, 1}, {'!', 2, 'inserted tuple'}, {'=', 3, 'set tuple'}}) s:truncate() s:insert{1, 'tuple'} -s:update({1}, {{'=', 1, 'set tuple'}, {'!', 1, 'inserted tuple'}, {'#', 2, 1}}) -s:update({1}, {{'!', 0, 3}, {'!', 0, 2}}) +s:update({1}, {{'=', 2, 'set tuple'}, {'!', 2, 'inserted tuple'}, {'#', 3, 1}}) +s:update({1}, {{'!', 1, 3}, {'!', 1, 2}}) s:truncate() -- test update's assign opearations s:replace{1, 'field string value'} -s:update({1}, {{'=', 1, 'new field string value'}, {'=', 2, 42}, {'=', 3, 0xdeadbeef}}) +s:update({1}, {{'=', 2, 'new field string value'}, {'=', 3, 42}, {'=', 4, 0xdeadbeef}}) -- test multiple update opearations on the same field -s:update({1}, {{'+', 2, 16}, {'&', 3, 0xffff0000}, {'|', 3, 0x0000a0a0}, {'^', 3, 0xffff00aa}}) +s:update({1}, {{'+', 3, 16}, {'&', 4, 0xffff0000}, {'|', 4, 0x0000a0a0}, {'^', 4, 0xffff00aa}}) -- test update splice operation -s:update({1}, {{':', 1, 0, 3, 'the newest'}}) +s:update({1}, {{':', 2, 0, 3, 'the newest'}}) s:replace{1953719668, 'something to splice'} -s:update(1953719668, {{':', 1, 0, 4, 'no'}}) -s:update(1953719668, {{':', 1, 0, 2, 'every'}}) +s:update(1953719668, {{':', 2, 0, 4, 'no'}}) +s:update(1953719668, {{':', 2, 0, 2, 'every'}}) -- check an incorrect offset -s:update(1953719668, {{':', 1, 100, 2, 'every'}}) -s:update(1953719668, {{':', 1, -100, 2, 'every'}}) +s:update(1953719668, {{':', 2, 100, 2, 'every'}}) +s:update(1953719668, {{':', 2, -100, 2, 'every'}}) s:truncate() s:insert{1953719668, 'hello', 'october', '20th'}:unpack() s:truncate() s:insert{1953719668, 'hello world'} -s:update(1953719668, {{'=', 1, 'bye, world'}}) +s:update(1953719668, {{'=', 2, 'bye, world'}}) s:delete{1953719668} -- test update delete operations -s:update({1}, {{'#', 3, 1}, {'#', 2, 1}}) +s:update({1}, {{'#', 4, 1}, {'#', 3, 1}}) -- test update insert operations -s:update({1}, {{'!', 1, 1}, {'!', 1, 2}, {'!', 1, 3}, {'!', 1, 4}}) +s:update({1}, {{'!', 2, 1}, {'!', 2, 2}, {'!', 2, 3}, {'!', 2, 4}}) s:truncate() +-- s:update: zero field +s:insert{48} +s:update(48, {{'=', 0, 'hello'}}) +s:truncate() + -- s:update: push/pop fields s:insert{1684234849} -s:update({1684234849}, {{'#', 1, 1}}) +s:update({1684234849}, {{'#', 2, 1}}) s:update({1684234849}, {{'=', -1, 'push1'}}) s:update({1684234849}, {{'=', -1, 'push2'}}) s:update({1684234849}, {{'=', -1, 'push3'}}) -s:update({1684234849}, {{'#', 1, 1}, {'=', -1, 'swap1'}}) -s:update({1684234849}, {{'#', 1, 1}, {'=', -1, 'swap2'}}) -s:update({1684234849}, {{'#', 1, 1}, {'=', -1, 'swap3'}}) +s:update({1684234849}, {{'#', 2, 1}, {'=', -1, 'swap1'}}) +s:update({1684234849}, {{'#', 2, 1}, {'=', -1, 'swap2'}}) +s:update({1684234849}, {{'#', 2, 1}, {'=', -1, 'swap3'}}) s:update({1684234849}, {{'#', -1, 1}, {'=', -1, 'noop1'}}) s:update({1684234849}, {{'#', -1, 1}, {'=', -1, 'noop2'}}) s:update({1684234849}, {{'#', -1, 1}, {'=', -1, 'noop3'}})