Skip to content

Commit bf843a1

Browse files
committed
get operation
1 parent 8b93aca commit bf843a1

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

crud/common/sharding.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,19 @@ function sharding.get_ddl_sharding_key(space_name)
8181
end
8282
end
8383

84+
function sharding.is_sharding_key_part_of_primary_index(sharding_index, sharding_key_fieldno)
85+
for _, fieldno in ipairs(sharding_key_fieldno) do
86+
local is_key_found = false
87+
for _, part in ipairs(sharding_index.parts) do
88+
if fieldno == part.fieldno then
89+
is_key_found = true
90+
break
91+
end
92+
if is_key_found == false then
93+
return false
94+
end
95+
end
96+
end
97+
end
98+
8499
return sharding

crud/common/utils.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ function utils.get_fieldno_by_name(space_format, field_name)
405405
return field_idx
406406
end
407407

408+
function utils.get_sharding_key_fieldno(space_format, sharding_key)
409+
key = {}
410+
for i, field_name in ipairs(sharding_key) do
411+
table.insert(key, utils.get_fieldno_by_name(space_format, field_name))
412+
end
413+
414+
return key
415+
end
416+
408417
local uuid_t = ffi.typeof('struct tt_uuid')
409418
function utils.is_uuid(value)
410419
return ffi.istype(uuid_t, value)

crud/get.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,22 @@ local function call_get_on_router(space_name, key, opts)
5353
if space == nil then
5454
return nil, GetError:new("Space %q doesn't exist", space_name), true
5555
end
56+
local primary_index = space.index[0]
57+
local space_format = space:format()
5658

5759
if box.tuple.is(key) then
5860
key = key:totable()
5961
end
6062

63+
local ddl_sharding_key = sharding.get_ddl_sharding_key(space_name)
64+
if ddl_sharding_key ~= nil then
65+
local key = utils.get_sharding_key_fieldno(space_format, ddl_sharding_key)
66+
local res = sharding.is_sharding_key_part_of_primary_index(primary_index, key)
67+
if res == false and opts.bucket_id == nil then
68+
return nil, GetError:new("Specify bucket_id"), true
69+
end
70+
end
71+
6172
local bucket_id = sharding.key_get_bucket_id(key, opts.bucket_id)
6273
local call_opts = {
6374
mode = opts.mode or 'read',

0 commit comments

Comments
 (0)