[tarantool-patches] [PATCH 1/4] tuple: expose JSON go_to_key and go_to_index functions

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sun Sep 15 20:32:14 MSK 2019


They are needed in JSON path update for a case, when a final part
of the path may not exist, and go_to_path returns an error.

That case is '=' and '!' on not existing fields. For example,
in {'=', '[1][2][3]', 20} field [3] can be not existing.

For these cases JSON update will have its own implementation of
go_to_path allowing optional last field.

Needed for #1261
---
 src/box/tuple.c | 21 ++-------------------
 src/box/tuple.h | 23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/src/box/tuple.c b/src/box/tuple.c
index bf4ea711d..261505f9a 100644
--- a/src/box/tuple.c
+++ b/src/box/tuple.c
@@ -385,15 +385,7 @@ tuple_free(void)
 
 /* {{{ tuple_field_* getters */
 
-/**
- * Propagate @a field to MessagePack(field)[index].
- * @param[in][out] field Field to propagate.
- * @param index 0-based index to propagate to.
- *
- * @retval  0 Success, the index was found.
- * @retval -1 Not found.
- */
-static inline int
+int
 tuple_field_go_to_index(const char **field, uint64_t index)
 {
 	enum mp_type type = mp_typeof(**field);
@@ -428,16 +420,7 @@ tuple_field_go_to_index(const char **field, uint64_t index)
 	return -1;
 }
 
-/**
- * Propagate @a field to MessagePack(field)[key].
- * @param[in][out] field Field to propagate.
- * @param key Key to propagate to.
- * @param len Length of @a key.
- *
- * @retval  0 Success, the index was found.
- * @retval -1 Not found.
- */
-static inline int
+int
 tuple_field_go_to_key(const char **field, const char *key, int len)
 {
 	enum mp_type type = mp_typeof(**field);
diff --git a/src/box/tuple.h b/src/box/tuple.h
index 4c4050ca8..ab0c7a99b 100644
--- a/src/box/tuple.h
+++ b/src/box/tuple.h
@@ -551,6 +551,29 @@ int
 tuple_go_to_path(const char **data, const char *path, uint32_t path_len,
 		 int multikey_idx);
 
+/**
+ * Propagate @a field to MessagePack(field)[index].
+ * @param[in][out] field Field to propagate.
+ * @param index 0-based index to propagate to.
+ *
+ * @retval  0 Success, the index was found.
+ * @retval -1 Not found.
+ */
+int
+tuple_field_go_to_index(const char **field, uint64_t index);
+
+/**
+ * Propagate @a field to MessagePack(field)[key].
+ * @param[in][out] field Field to propagate.
+ * @param key Key to propagate to.
+ * @param len Length of @a key.
+ *
+ * @retval  0 Success, the index was found.
+ * @retval -1 Not found.
+ */
+int
+tuple_field_go_to_key(const char **field, const char *key, int len);
+
 /**
  * Get tuple field by field index, relative JSON path and
  * multikey_idx.
-- 
2.20.1 (Apple Git-117)





More information about the Tarantool-patches mailing list