From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 2326222A23 for ; Thu, 18 Jul 2019 12:00:00 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id scihoWpJpA7I for ; Thu, 18 Jul 2019 11:59:59 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 425C42264F for ; Thu, 18 Jul 2019 11:59:57 -0400 (EDT) From: "n.pettik" Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_6B8B7DE5-7E07-4F65-87AE-DDAFDFD626A1" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: [tarantool-patches] Re: [PATCH v1 1/1] sql: Fix UPDATE for types unknown to SQL. Date: Thu, 18 Jul 2019 18:59:54 +0300 In-Reply-To: <20190716141951.GA6901@tarantool.org> References: <132ca83597d0e9c2b4ef75bc8f0d03d22cdf27dd.1561736006.git.imeevma@gmail.com> <20190708101336.GA10686@tarantool.org> <09286d9d-870b-f5dd-f328-56d374173160@tarantool.org> <598DA602-A524-48B9-8D15-78E67A61852B@tarantool.org> <20190716141951.GA6901@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: Imeev Mergen --Apple-Mail=_6B8B7DE5-7E07-4F65-87AE-DDAFDFD626A1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > New patch: >=20 > =46rom 1d6abdeb18652890c1819349f24d8b450f6ed6c7 Mon Sep 17 00:00:00 = 2001 > Date: Fri, 28 Jun 2019 18:16:16 +0300 > Subject: [PATCH] sql: add ARRAY, MAP and ANY types to mem_apply_type() >=20 > Function mem_apply_type() implements implicit type conversion. As > a rule, tuple to be inserted to the space is exposed to this > conversion which is invoked during execution of OP_MakeRecord > opcode (which in turn forms tuple). This function was not adjusted > to operate on ARRAY, MAP and ANY field types since they are poorly > supported in current SQL implementation. Hence, when tuple to be > inserted in space having mentioned field types reaches this > function, it results in error. Note that we can't set ARRAY or MAP > types in SQL, but such situation may appear during UPDATE > operation on space created via Lua interface. This problem is > solved by extending implicit type conversions with obvious casts: > array field can be casted to array, map to map and any to any. >=20 > Closes #4189 >=20 > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 9f4ee7a..cf4715d 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -292,7 +292,19 @@ mem_apply_numeric_type(struct Mem *record) > * Convert mem to a string representation. > * > * SCALAR: > - * Mem is unchanged, but flag is set to BLOB. > + * Mem is unchanged, but flag is set to BLOB in case of > + * scalar-like type. Otherwise, (MAP, ARRAY) conversion > + * is impossible. > + * > + * BOOLEAN: > + * If memory holds BOOLEAN no actions take place. > + * > + * ANY: > + * Mem is unchanged, no actions take place. > + * > + * MAP/ARRAY: > + * These types can't be casted to scalar ones, or to each > + * other. So the only valid conversion is to type itself. > * > * @param record The value to apply type to. > * @param type The type to be applied. > @@ -338,6 +350,27 @@ mem_apply_type(struct Mem *record, enum = field_type type) > record->flags &=3D ~(MEM_Real | MEM_Int); > return 0; > case FIELD_TYPE_SCALAR: > + /* Can't cast MAP and ARRAY to scalar types. */ > + if ((record->flags & MEM_Subtype) !=3D 0 && > + record->subtype =3D=3D SQL_SUBTYPE_MSGPACK) { > + assert(mp_typeof(*record->z) =3D=3D MP_MAP || > + mp_typeof(*record->z) =3D=3D MP_ARRAY); > + return -1; > + } > + return 0; > + case FIELD_TYPE_MAP: > + if ((record->flags & MEM_Subtype) !=3D 0 && > + record->subtype =3D=3D SQL_SUBTYPE_MSGPACK && > + mp_typeof(*record->z) =3D=3D MP_MAP) > + return 0; > + return -1; > + case FIELD_TYPE_ARRAY: > + if ((record->flags & MEM_Subtype) !=3D 0 && > + record->subtype =3D=3D SQL_SUBTYPE_MSGPACK && > + mp_typeof(*record->z) =3D=3D MP_ARRAY) > + return 0; > + return -1; > + case FIELD_TYPE_ANY: > return 0; > default: > return -1; > @@ -2662,8 +2695,17 @@ case OP_ApplyType: { > assert(pIn1 <=3D &p->aMem[(p->nMem+1 - p->nCursor)]); > assert(memIsValid(pIn1)); > if (mem_apply_type(pIn1, type) !=3D 0) { > - diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > - sql_value_text(pIn1), > + const char *value; > + if ((pIn1->flags & MEM_Subtype) !=3D 0 && > + pIn1->subtype =3D=3D SQL_SUBTYPE_MSGPACK) { > + if (mp_typeof(*pIn1->z) =3D=3D MP_MAP) > + value =3D "map=E2=80=9D; Please move this fix alongside with test to a separate patch. > + else > + value =3D "array"; > + } else { > + value =3D (const char = *)sql_value_text(pIn1); > + } > + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, = value, > field_type_strs[type]); > goto abort_due_to_error; > } --Apple-Mail=_6B8B7DE5-7E07-4F65-87AE-DDAFDFD626A1 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

New = patch:

=46rom = 1d6abdeb18652890c1819349f24d8b450f6ed6c7 Mon Sep 17 00:00:00 = 2001
Date: Fri, 28 = Jun 2019 18:16:16 +0300
Subject: [PATCH] sql: add ARRAY, MAP and ANY types to = mem_apply_type()

Function mem_apply_type() implements implicit type = conversion. As
a rule, tuple to be inserted to the space is exposed to = this
conversion = which is invoked during execution of OP_MakeRecord
opcode (which in turn forms = tuple). This function was not adjusted
to operate on ARRAY, MAP and ANY field types since they are = poorly
supported in = current SQL implementation. Hence, when tuple to be
inserted in space having = mentioned field types reaches this
function, it results in error. Note that we can't set ARRAY = or MAP
types in SQL, = but such situation may appear during UPDATE
operation on space created via = Lua interface. This problem is
solved by extending implicit type conversions with obvious = casts:
array field = can be casted to array, map to map and any to any.

Closes #4189

diff --git a/src/box/sql/vdbe.c = b/src/box/sql/vdbe.c
index 9f4ee7a..cf4715d 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -292,7 +292,19 @@ mem_apply_numeric_type(struct Mem = *record)
 * =    Convert mem to a string representation.
 *
 * SCALAR:
- *    Mem is = unchanged, but flag is set to BLOB.
+ *    Mem is unchanged, but flag is set to = BLOB in case of
+ *    scalar-like type. Otherwise, (MAP, = ARRAY) conversion
+ *    is impossible.
+ *
+ * BOOLEAN:
+ *    If memory = holds BOOLEAN no actions take place.
+ *
+ * ANY:
+ *    Mem is unchanged, no actions take = place.
+ *
+ * MAP/ARRAY:
+ *    These = types can't be casted to scalar ones, or to each
+ *    other. So = the only valid conversion is to type itself.
 *
 * @param record The value = to apply type to.
 * @param type The type to be applied.
@@ -338,6 +350,27 @@ = mem_apply_type(struct Mem *record, enum field_type type)
record->flags &=3D ~(MEM_Real | MEM_Int);
return 0;
= case = FIELD_TYPE_SCALAR:
+ = /* Can't cast = MAP and ARRAY to scalar types. */
+ = if = ((record->flags & MEM_Subtype) !=3D 0 &&
+     record->= subtype =3D=3D SQL_SUBTYPE_MSGPACK) {
+ = assert(mp_typeof(*record->z) =3D=3D MP_MAP ||
+ =       = ; mp_typeof(*record->z) =3D=3D MP_ARRAY);
+ = return = -1;
+ }
+ return 0;
+ case FIELD_TYPE_MAP:
+ = if = ((record->flags & MEM_Subtype) !=3D 0 &&
+     record->= subtype =3D=3D SQL_SUBTYPE_MSGPACK &&
+     mp_typeof(*= record->z) =3D=3D MP_MAP)
+ = return = 0;
+ return -1;
+ case FIELD_TYPE_ARRAY:
+ = if = ((record->flags & MEM_Subtype) !=3D 0 &&
+     record->= subtype =3D=3D SQL_SUBTYPE_MSGPACK &&
+     mp_typeof(*= record->z) =3D=3D MP_ARRAY)
+ = return = 0;
+ return -1;
+ case FIELD_TYPE_ANY:
= return = 0;
default:
= return = -1;
@@ -2662,8 = +2695,17 @@ case OP_ApplyType: {
= assert(pIn1 = <=3D &p->aMem[(p->nMem+1 - p->nCursor)]);
assert(memIsValid(pIn1));
= if = (mem_apply_type(pIn1, type) !=3D 0) {
- = diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
- =  sql_value_text(pIn1),<= br style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: normal; letter-spacing: normal; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: = none;" class=3D"">+ = const char = *value;
+ = if = ((pIn1->flags & MEM_Subtype) !=3D 0 &&
+ =     pIn1->su= btype =3D=3D SQL_SUBTYPE_MSGPACK) {
+ = if (mp_typeof(*pIn1->z) =3D=3D MP_MAP)
+ = value =3D "map=E2=80=9D;

Please move this fix alongside with test to a = separate patch.

+ = else
+ = = value =3D = "array";
+ = } else = {
+ = value =3D = (const char *)sql_value_text(pIn1);
+ = }
+ = diag_set(ClientError, ER_SQL_TYPE_MISMATCH, value,
=  field_type_strs[type]);
= goto = abort_due_to_error;
= }

= --Apple-Mail=_6B8B7DE5-7E07-4F65-87AE-DDAFDFD626A1--