From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 73511446445 for ; Wed, 23 Sep 2020 04:40:45 +0300 (MSK) From: Alexander Turenko Date: Wed, 23 Sep 2020 04:40:26 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1.10 13/16] WIP: module api: expose box_tuple_validate_key_parts() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org, Alexander Turenko XXX: Add a module API test. Part of #5273 (backported from commit 37b501a1982f903cef55e90e89fe3d42931e93d9) --- extra/exports | 1 + src/box/key_def_api.c | 23 +++++++++++++++++++++++ src/box/key_def_api.h | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/extra/exports b/extra/exports index 97d2a21b8..2afc36def 100644 --- a/extra/exports +++ b/extra/exports @@ -171,6 +171,7 @@ box_tuple_next box_tuple_update box_tuple_upsert box_tuple_extract_key +box_tuple_validate_key_parts box_tuple_compare box_tuple_compare_with_key box_return_tuple diff --git a/src/box/key_def_api.c b/src/box/key_def_api.c index 30ddde9c8..29203319c 100644 --- a/src/box/key_def_api.c +++ b/src/box/key_def_api.c @@ -36,6 +36,8 @@ #include "field_def.h" #include "coll_id_cache.h" #include "fiber.h" +#include "tuple.h" +#include /* {{{ Helpers */ @@ -229,6 +231,27 @@ box_key_def_dump_parts(const box_key_def_t *key_def, uint32_t *part_count_ptr) return parts; } +int +box_tuple_validate_key_parts(box_key_def_t *key_def, box_tuple_t *tuple) +{ + for (uint32_t idx = 0; idx < key_def->part_count; ++idx) { + struct key_part *part = &key_def->parts[idx]; + const char *field = tuple_field_by_part(tuple, part); + if (field == NULL) { + if (part->is_nullable) + continue; + diag_set(ClientError, ER_NO_SUCH_FIELD, + part->fieldno + TUPLE_INDEX_BASE); + return -1; + } + enum mp_type mp_type = mp_typeof(*field); + if (key_mp_type_validate(part->type, mp_type, ER_FIELD_TYPE, + idx, part->is_nullable) != 0) + return -1; + } + return 0; +} + int box_tuple_compare(const box_tuple_t *tuple_a, const box_tuple_t *tuple_b, box_key_def_t *key_def) diff --git a/src/box/key_def_api.h b/src/box/key_def_api.h index ee967c510..bdc3ecebd 100644 --- a/src/box/key_def_api.h +++ b/src/box/key_def_api.h @@ -169,6 +169,18 @@ box_key_def_delete(box_key_def_t *key_def); API_EXPORT box_key_part_def_t * box_key_def_dump_parts(const box_key_def_t *key_def, uint32_t *part_count_ptr); +/** + * Check that tuple fields match with given key definition. + * + * @param key_def Key definition. + * @param tuple Tuple to validate. + * + * @retval 0 The tuple is valid. + * @retval -1 The tuple is invalid. + */ +API_EXPORT int +box_tuple_validate_key_parts(box_key_def_t *key_def, box_tuple_t *tuple); + /** * Compare tuples using the key definition. * @param tuple_a first tuple -- 2.25.0