Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, Nikita Pettik <korablev@tarantool.org>
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v1 1/1] sql: remove struct Enc
Date: Fri, 17 Aug 2018 17:04:12 +0300	[thread overview]
Message-ID: <b0ca2dd0-f524-4118-a75b-ca6944f6da65@tarantool.org> (raw)
In-Reply-To: <22d959eb-5c4e-fb12-f7de-cf10a237f0dd@tarantool.org>

On 17.08.2018 15:40, Vladislav Shpilevoy wrote:
> Hi! Please, do not use any Lua things in SQL.
> You should not even include this: #include "lua/msgpack.h".

======================================
diff --git a/src/box/sql.c b/src/box/sql.c
index f1e860d..321d3c4 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -56,7 +56,7 @@
 #include "xrow.h"
 #include "iproto_constants.h"
 #include "fkey.h"
-#include "lua/msgpack.h"
+#include "mpstream.h"
 #include "small/region.h"
 
 static sqlite3 *db = NULL;
@@ -1250,7 +1250,7 @@ sql_encode_table(struct region *region, struct Table *table, uint32_t *size)
 			pk_forced_int = pk;
 	}
 	uint32_t field_count = def->field_count;
-	luamp_encode_array(luaL_msgpack_default, &stream, field_count);
+	mpstream_encode_array(&stream, field_count);
 	for (uint32_t i = 0; i < field_count && !is_error; i++) {
 		const char *t;
 		uint32_t cid = def->fields[i].coll_id;
@@ -1261,13 +1261,10 @@ sql_encode_table(struct region *region, struct Table *table, uint32_t *size)
 			base_len += 1;
 		if (default_str != NULL)
 			base_len += 1;
-		luamp_encode_map(luaL_msgpack_default, &stream, base_len);
-		luamp_encode_str(luaL_msgpack_default, &stream, "name",
-				 strlen("name"));
-		luamp_encode_str(luaL_msgpack_default, &stream, field->name,
-				 strlen(field->name));
-		luamp_encode_str(luaL_msgpack_default, &stream, "type",
-				 strlen("type"));
+		mpstream_encode_map(&stream, base_len);
+		mpstream_encode_str(&stream, "name", strlen("name"));
+		mpstream_encode_str(&stream, field->name, strlen(field->name));
+		mpstream_encode_str(&stream, "type", strlen("type"));
 		if (i == pk_forced_int) {
 			t = "integer";
 		} else {
@@ -1280,32 +1277,30 @@ sql_encode_table(struct region *region, struct Table *table, uint32_t *size)
 		assert(def->fields[i].is_nullable ==
 			       action_is_nullable(def->fields[i].
 						  nullable_action));
-		luamp_encode_str(luaL_msgpack_default, &stream, t, strlen(t));
-		luamp_encode_str(luaL_msgpack_default, &stream, "affinity",
-				 strlen("affinity"));
-		luamp_encode_uint(luaL_msgpack_default, &stream,
+		mpstream_encode_str(&stream, t, strlen(t));
+		mpstream_encode_str(&stream, "affinity", strlen("affinity"));
+		mpstream_encode_uint(&stream,
 				  def->fields[i].affinity);
-		luamp_encode_str(luaL_msgpack_default, &stream, "is_nullable",
-				 strlen("is_nullable"));
-		luamp_encode_bool(luaL_msgpack_default, &stream,
+		mpstream_encode_str(&stream, "is_nullable",
+				    strlen("is_nullable"));
+		mpstream_encode_bool(&stream,
 				  def->fields[i].is_nullable);
-		luamp_encode_str(luaL_msgpack_default, &stream,
-				 "nullable_action", strlen("nullable_action"));
+		mpstream_encode_str(&stream, "nullable_action",
+				    strlen("nullable_action"));
 		assert(def->fields[i].nullable_action < on_conflict_action_MAX);
 		const char *action =
 			on_conflict_action_strs[def->fields[i].nullable_action];
-		luamp_encode_str(luaL_msgpack_default, &stream, action,
-				 strlen(action));
+		mpstream_encode_str(&stream, action, strlen(action));
 		if (cid != COLL_NONE) {
-			luamp_encode_str(luaL_msgpack_default, &stream,
-					 "collation", strlen("collation"));
-			luamp_encode_uint(luaL_msgpack_default, &stream, cid);
+			mpstream_encode_str(&stream, "collation",
+					    strlen("collation"));
+			mpstream_encode_uint(&stream, cid);
 		}
 		if (default_str != NULL) {
-			luamp_encode_str(luaL_msgpack_default, &stream,
-					 "default", strlen("default"));
-			luamp_encode_str(luaL_msgpack_default, &stream,
-					 default_str, strlen(default_str));
+			mpstream_encode_str(&stream, "default",
+					    strlen("default"));
+			mpstream_encode_str(&stream, default_str,
+					    strlen(default_str));
 		}
 	}
 	mpstream_flush(&stream);
@@ -1337,27 +1332,24 @@ sql_encode_table_opts(struct region *region, struct Table *table,
 		has_checks =  table->def->opts.checks != NULL;
 	}
 	uint32_t checks_cnt = has_checks ? table->def->opts.checks->nExpr : 0;
-	luamp_encode_map(luaL_msgpack_default, &stream,
-			 1 + is_view + (checks_cnt > 0));
+	mpstream_encode_map(&stream, 1 + is_view + (checks_cnt > 0));
 
-	luamp_encode_str(luaL_msgpack_default, &stream, "sql", strlen("sql"));
-	luamp_encode_str(luaL_msgpack_default, &stream, sql, strlen(sql));
+	mpstream_encode_str(&stream, "sql", strlen("sql"));
+	mpstream_encode_str(&stream, sql, strlen(sql));
 	if (is_view) {
-		luamp_encode_str(luaL_msgpack_default, &stream, "view",
-				 strlen("view"));
-		luamp_encode_bool(luaL_msgpack_default, &stream, true);
+		mpstream_encode_str(&stream, "view", strlen("view"));
+		mpstream_encode_bool(&stream, true);
 	}
 	if (checks_cnt == 0)
 		goto finish;
 
 	/* Encode checks. */
 	struct ExprList_item *a = table->def->opts.checks->a;
-	luamp_encode_str(luaL_msgpack_default, &stream, "checks",
-			 strlen("checks"));
-	luamp_encode_array(luaL_msgpack_default, &stream, checks_cnt);
+	mpstream_encode_str(&stream, "checks", strlen("checks"));
+	mpstream_encode_array(&stream, checks_cnt);
 	for (uint32_t i = 0; i < checks_cnt && !is_error; ++i) {
 		int items = (a[i].pExpr != NULL) + (a[i].zName != NULL);
-		luamp_encode_map(luaL_msgpack_default, &stream, items);
+		mpstream_encode_map(&stream, items);
 		/*
 		 * a[i].pExpr could be NULL for VIEW column names
 		 * represented as checks.
@@ -1365,17 +1357,14 @@ sql_encode_table_opts(struct region *region, struct Table *table,
 		if (a[i].pExpr != NULL) {
 			struct Expr *pExpr = a[i].pExpr;
 			assert(pExpr->u.zToken != NULL);
-			luamp_encode_str(luaL_msgpack_default, &stream, "expr",
-					 strlen("expr"));
-			luamp_encode_str(luaL_msgpack_default, &stream,
-					 pExpr->u.zToken,
-					 strlen(pExpr->u.zToken));
+			mpstream_encode_str(&stream, "expr", strlen("expr"));
+			mpstream_encode_str(&stream, pExpr->u.zToken,
+					    strlen(pExpr->u.zToken));
 		}
 		if (a[i].zName != NULL) {
-			luamp_encode_str(luaL_msgpack_default, &stream, "name",
-					 strlen("name"));
-			luamp_encode_str(luaL_msgpack_default, &stream,
-					 a[i].zName, strlen(a[i].zName));
+			mpstream_encode_str(&stream, "name", strlen("name"));
+			mpstream_encode_str(&stream, a[i].zName,
+					    strlen(a[i].zName));
 		}
 	}
 
@@ -1402,11 +1391,9 @@ fkey_encode_links(struct region *region, const struct fkey_def *def, int type,
 	mpstream_init(&stream, region, region_reserve_cb, region_alloc_cb,
 		      set_encode_error, &is_error);
 	uint32_t field_count = def->field_count;
-	luamp_encode_array(luaL_msgpack_default, &stream, field_count);
-	for (uint32_t i = 0; i < field_count && !is_error; ++i) {
-		luamp_encode_uint(luaL_msgpack_default, &stream,
-				  def->links[i].fields[type]);
-	}
+	mpstream_encode_array(&stream, field_count);
+	for (uint32_t i = 0; i < field_count && !is_error; ++i)
+		mpstream_encode_uint(&stream, def->links[i].fields[type]);
 	mpstream_flush(&stream);
 	if (is_error)
 		return NULL;
@@ -1451,7 +1438,7 @@ sql_encode_index_parts(struct region *region, struct SqliteIndex *index,
 	struct key_def *key_def = index->def->key_def;
 	uint32_t part_count = key_def->part_count;
 	struct key_part *part = key_def->parts;
-	luamp_encode_array(luaL_msgpack_default, &stream, part_count);
+	mpstream_encode_array(&stream, part_count);
 	for (uint32_t i = 0; i < part_count; ++i, ++part) {
 		uint32_t col = part->fieldno;
 		assert(fields[col].is_nullable ==
@@ -1465,37 +1452,33 @@ sql_encode_index_parts(struct region *region, struct SqliteIndex *index,
 		}
 		/* Do not decode default collation. */
 		uint32_t cid = part->coll_id;
-		luamp_encode_map(luaL_msgpack_default, &stream,
-				 5 + (cid != COLL_NONE));
-		luamp_encode_str(luaL_msgpack_default, &stream, "type",
-				 strlen("type"));
-		luamp_encode_str(luaL_msgpack_default, &stream, t, strlen(t));
-		luamp_encode_str(luaL_msgpack_default, &stream, "field",
-				 strlen("field"));
-		luamp_encode_uint(luaL_msgpack_default, &stream, col);
+		mpstream_encode_map(&stream, 5 + (cid != COLL_NONE));
+		mpstream_encode_str(&stream, "type", strlen("type"));
+		mpstream_encode_str(&stream, t, strlen(t));
+		mpstream_encode_str(&stream, "field", strlen("field"));
+		mpstream_encode_uint(&stream, col);
 		if (cid != COLL_NONE) {
-			luamp_encode_str(luaL_msgpack_default, &stream,
-					 "collation", strlen("collation"));
-			luamp_encode_uint(luaL_msgpack_default, &stream, cid);
+			mpstream_encode_str(&stream, "collation",
+					    strlen("collation"));
+			mpstream_encode_uint(&stream, cid);
 		}
-		luamp_encode_str(luaL_msgpack_default, &stream, "is_nullable",
-				 strlen("is_nullable"));
-		luamp_encode_bool(luaL_msgpack_default, &stream,
+		mpstream_encode_str(&stream, "is_nullable",
+				    strlen("is_nullable"));
+		mpstream_encode_bool(&stream,
 				  fields[col].is_nullable);
-		luamp_encode_str(luaL_msgpack_default, &stream,
-				 "nullable_action", strlen("nullable_action"));
+		mpstream_encode_str(&stream, "nullable_action",
+				    strlen("nullable_action"));
 		const char *action_str =
 			on_conflict_action_strs[fields[col].nullable_action];
-		luamp_encode_str(luaL_msgpack_default, &stream, action_str,
-				 strlen(action_str));
+		mpstream_encode_str(&stream, action_str, strlen(action_str));
 
-		luamp_encode_str(luaL_msgpack_default, &stream, "sort_order",
-				 strlen("sort_order"));
+		mpstream_encode_str(&stream, "sort_order",
+				    strlen("sort_order"));
 		enum sort_order sort_order = part->sort_order;
 		assert(sort_order < sort_order_MAX);
 		const char *sort_order_str = sort_order_strs[sort_order];
-		luamp_encode_str(luaL_msgpack_default, &stream, sort_order_str,
-				 strlen(sort_order_str));
+		mpstream_encode_str(&stream, sort_order_str,
+				    strlen(sort_order_str));
 	}
 	mpstream_flush(&stream);
 	if (is_error)
@@ -1518,10 +1501,9 @@ sql_encode_index_opts(struct region *region, struct SqliteIndex *index,
 	bool is_error = false;
 	mpstream_init(&stream, region, region_reserve_cb, region_alloc_cb,
 		      set_encode_error, &is_error);
-	luamp_encode_map(luaL_msgpack_default, &stream, 2);
+	mpstream_encode_map(&stream, 1 + (sql != NULL));
 	/* Mark as unique pk and unique indexes */
-	luamp_encode_str(luaL_msgpack_default, &stream, "unique",
-			 strlen("unique"));
+	mpstream_encode_str(&stream, "unique", strlen("unique"));
 	/* If user didn't defined ON CONFLICT OPTIONS, all uniqueness checks
 	 * will be made by Tarantool. However, Tarantool doesn't have ON
 	 * CONFLIT option, so in that case (except ON CONFLICT ABORT, which is
@@ -1529,10 +1511,11 @@ sql_encode_index_opts(struct region *region, struct SqliteIndex *index,
 	 * INSERT OR REPLACE/IGNORE uniqueness checks will be also done by
 	 * Tarantool.
 	 */
-	luamp_encode_bool(luaL_msgpack_default, &stream, IsUniqueIndex(index));
-	luamp_encode_str(luaL_msgpack_default, &stream, "sql", strlen("sql"));
-	luamp_encode_str(luaL_msgpack_default, &stream, sql,
-			 sql != NULL ? strlen(sql) : 0);
+	mpstream_encode_bool(&stream, IsUniqueIndex(index));
+	if (sql != NULL) {
+		mpstream_encode_str(&stream, "sql", strlen("sql"));
+		mpstream_encode_str(&stream, sql, strlen(sql));
+	}
 	mpstream_flush(&stream);
 	if (is_error)
 		return NULL;

  reply	other threads:[~2018-08-17 14:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-17 12:24 [tarantool-patches] " Kirill Shcherbatov
2018-08-17 12:40 ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-17 14:04   ` Kirill Shcherbatov [this message]
     [not found] ` <cover.1534514520.git.kshcherbatov@tarantool.org>
2018-08-17 14:04   ` [tarantool-patches] [PATCH v1 1/2] box: export mpstream methods to core Kirill Shcherbatov
2018-08-24 16:33     ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-21 12:09 ` [tarantool-patches] Re: [PATCH v1 1/1] sql: remove struct Enc n.pettik
2018-08-21 15:50   ` Kirill Shcherbatov
2018-08-24 16:33     ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b0ca2dd0-f524-4118-a75b-ca6944f6da65@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='[tarantool-patches] Re: [PATCH v1 1/1] sql: remove struct Enc' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox