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 A79D824C4B for ; Tue, 30 Jul 2019 09:44:58 -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 AGgt7Y7IS9ev for ; Tue, 30 Jul 2019 09:44:58 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 662A224C41 for ; Tue, 30 Jul 2019 09:44:58 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: [tarantool-patches] Re: [PATCH 5/5] sql: introduce VARBINARY column type From: "n.pettik" In-Reply-To: <24a34647-0d0c-7950-b92e-6c8bf3f16d92@tarantool.org> Date: Tue, 30 Jul 2019 16:44:54 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <63A0BD0D-69A9-4CD6-942B-EB9CDDDB21F3@tarantool.org> References: <49a188eb-dafe-44e7-a0fd-e9244b68e721@tarantool.org> <1293710C-85CC-4F5A-A7CF-4677D901DCE9@tarantool.org> <24a34647-0d0c-7950-b92e-6c8bf3f16d92@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: Vladislav Shpilevoy >>> 2. Please, add tests on varbinary values binding. >>=20 >> Could you suggest the way to force MP_BIN format from Lua? >> I see the only test on VARBINARY type = (test/box/varbinary_type.test.lua), >> but this approach is unlikely to be applicable for bindings. >=20 > I can, but you won't like it. >=20 > box.cfg{listen =3D 3313} > netbox =3D require('net.box') > buffer =3D require('buffer') > ffi =3D require('ffi') >=20 > ffi.cdef[[ > typedef struct box_tuple_format_t box_tuple_format_t; > typedef struct box_tuple_t box_tuple_t; >=20 > int > box_insert(uint32_t space_id, const char *tuple, const char = *tuple_end, > box_tuple_t **result); > ]] >=20 > s =3D box.schema.create_space('test') > pk =3D s:create_index('pk', {parts =3D {{1, 'scalar'}}}) >=20 > box.schema.user.grant('guest','read, write, execute', = 'universe') > box.schema.user.grant('guest', 'create', 'space') > cn =3D netbox.connect(box.cfg.listen) >=20 > data =3D buffer.static_alloc('char', 1 + 6) > data[0] =3D 0x91 > data[1] =3D 0xc4 > data[2] =3D 3 > data[3] =3D string.byte('b') > data[4] =3D string.byte('i') > data[5] =3D string.byte('n') > ffi.C.box_insert(s.id, data, data + 6, nil) >=20 > cn:execute('SELECT typeof(?);', s:select()[1]) >=20 > This returns: >=20 > --- > - metadata: > - name: typeof(?) > type: string > rows: > - ['varbinary'] > ... >=20 > I used the fact that netbox encodes 'execute' bind array as a > tuple. So I inserted MP_BIN into a tuple, and used it as a > bind array. Ok, I can=E2=80=99t come up with better option, so I slightly simplified your example: there=E2=80=99s no need to use FFI to insert MP_BIN since we can use SQL facilities to do so. diff --git a/test/sql/bind.test.lua b/test/sql/bind.test.lua index 3e0eed29a..51a87b0ee 100644 --- a/test/sql/bind.test.lua +++ b/test/sql/bind.test.lua @@ -93,7 +93,20 @@ execute('SELECT :value', parameters) -- execute('SELECT ? ', {18446744073709551615ULL}) =20 +-- Make sure that VARBINARY values can be bound. Note that +-- at the moment there's no direct way to encode value as MP_BIN, +-- so we have to use workaround only with remote option. +-- test_run:cmd("setopt delimiter ';'") + +if remote then + execute("CREATE TABLE t(a VARBINARY PRIMARY KEY);") + execute("INSERT INTO t VALUES (X'00');") + res =3D execute("SELECT typeof(?);", box.space.T:select()[1]) + assert(res['rows'][1][1] =3D=3D "varbinary") + execute("DROP TABLE t;") +end; + if remote then cn:close() box.schema.user.revoke('guest', 'read, write, execute', = 'universe') >=20 >>> 3. BLOB keyword is reserved, but also it is used in parse.y:980. >>> Should not it be deleted from all the rules, and be just >>> reserved? >>=20 >> It=E2=80=99s rule for declaring blob (aka binary string) literals. >> I can rename it, but TBO it looks OK to me. >=20 > Could you please provide an example, how to use BLOB keyword to > declare a literal? I can't find any test, using BLOB in a query > string for anything. I meant that it=E2=80=99s not the rule that allows BLOB keyword but the rule to process X=E2=80=99=E2=80=A6=E2=80=99 literals. When string = is processed by lexer (tokenize.c) its token type is assigned to TK_BLOB. BLOB keyword itself is banned in mkkeywordhash.c since it has token type TK_STANDARD. In case you suggest to rename token type from TK_BLOB to smth else - I see no reason to do so, it=E2=80=99s quite brief and clear. If some day we decide to add BLOB keyword, its type will be TK_BLOB_KW to avoid any confusions. > Also, I've found, that 'blob' type is still mentioned in > sql-tap/e_expr.test.lua quite a lot. And in sql-tap/types2.test.lua, > where it is still used as a column type. These tests are disabled. > Why? See = https://github.com/tarantool/tarantool/issues/3102#issuecomment-437274405 Seems that they contain a lot of type mess, I guess. Nothing prevents us from resurrecting them, expect for time.