From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 9DAA06EC55; Sat, 9 Oct 2021 00:58:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9DAA06EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633730314; bh=6ucrt/gpsAWD9X3nt6QcDyhzchNmYIwmfo+oVL+XCBw=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=F7PYHe4OL/qhmhzi7dfeYqdPTdBA8Aw8vemTz5quX1ZThKOnoJ0WQjK08QpeyO7kq rKhXZsf9mpqSBOD/GNOMEfvyYG56mdz6enaXlcbGPNK4FlbmkIPJHPniKt3RcBkBO9 yJVVebsIW6/BLf/wocEhjorC57n0MrxSynNzw5GE= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (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 89DD16EC55 for ; Sat, 9 Oct 2021 00:58:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 89DD16EC55 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1mYxsv-0007Dl-0T; Sat, 09 Oct 2021 00:58:33 +0300 Message-ID: Date: Fri, 8 Oct 2021 23:58:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9A6D4E3B1981C4C7DC8C09104FADB757A98AD8127042C5321182A05F538085040E921D9205E559069492F157F6B8E6160D7142236A302A0D5F70553BF23347748 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74B7EDB5828CF9C27EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372E9841F416E2DCCD8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D88E4A08B08043841641E7B82A00AC0CD7117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6B1CFA6D474D4A6A4089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505178C323EEE45813B40D5940AD60ABE8C X-C1DE0DAB: 0D63561A33F958A58826A7EA9B72189BDFEF561A675AEC2606B3A40D73B052FBD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA759D2A03B9C34326B3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C1D376EF32BB0896AB208D22372502FF7EE99797D7D04E4A01FC9BF38D6E87447773D8F9B17F3C741D7E09C32AA3244CE5994B726AEA430F9B4B7815E1D22035F165894D92D62706729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMZ06aokA6bpL6WUkApd29g== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D68231724375E88F4C78C9B59EE8ED96E3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 6/8] sql: rework POSITION() function X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! See 3 comments below. > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index 1d1a8b0cd..415a92738 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -530,6 +530,68 @@ func_trim_str(struct sql_context *ctx, int argc, struct Mem *argv) > ctx->is_aborted = true; > } > > +/** Implementation of the POSITION() function. */ > +static void > +func_position_octets(struct sql_context *ctx, int argc, struct Mem *argv) > +{ > + assert(argc == 2); > + (void)argc; > + if (mem_is_null(&argv[0]) || mem_is_null(&argv[1])) 1. There is mem_is_any_null(). The same in the next function. > + return; > + assert(mem_is_bytes(&argv[0]) && mem_is_bytes(&argv[1])); > + > + const char *key = argv[0].z; > + const char *str = argv[1].z; > + int key_size = argv[0].n; > + int str_size = argv[1].n; > + if (key_size <= 0) > + return mem_set_uint(ctx->pOut, 1); > + /* Matching time O(n * m). */ > + for (int i = 0; i <= str_size - key_size; ++i) { > + if (memcmp(&str[i], key, key_size) == 0) > + return mem_set_uint(ctx->pOut, i + 1); > + } 2. There is memmem(). > + return mem_set_uint(ctx->pOut, 0); > +} > diff --git a/test/sql-tap/position.test.lua b/test/sql-tap/position.test.lua > index 6a96ed9bc..5f62c7f54 100755 > --- a/test/sql-tap/position.test.lua > +++ b/test/sql-tap/position.test.lua > @@ -858,4 +858,14 @@ test:do_catchsql_test( > } > ) > > +-- gh-4145: Make sure that POSITION() can wirk with VARBINARY. 3. wirk -> work. > +test:do_execsql_test( > + "position-2", > + [[ > + SELECT POSITION(x'313233', x'30313231323334353132333435'); > + ]], { > + 4 > + } > +) > + > test:finish_test() >