* [tarantool-patches] [PATCH v2 1/1] sql: ANSI aliases for LENGTH()
@ 2019-07-06 10:46 imeevma
2019-07-08 13:12 ` [tarantool-patches] " n.pettik
2019-07-11 7:48 ` Kirill Yukhin
0 siblings, 2 replies; 3+ messages in thread
From: imeevma @ 2019-07-06 10:46 UTC (permalink / raw)
To: korablev; +Cc: tarantool-patches
This patch creates aliases CHARACTER_LENGTH() and CHAR_LENGTH()
for LENGTH(). These functions are added because they are described
in ANSI.
Closes #3929
@TarantoolBot document
Title: SQL functions CHAR_LENGTH() and CHARACTER_LENGTH()
The SQL functions CHAR_LENGTH() and CHARACTER_LENGTH() work the
same as the LENGTH() function. They take exactly one argument. If
an argument of type TEXT or can be cast to a TEXT value using
internal casting rules, these functions return the length of the
TEXT value that represents the argument. They throw an error if
the argument cannot be cast to a TEXT value.
---
https://github.com/tarantool/tarantool/issues/3929
https://github.com/tarantool/tarantool/tree/imeevma/gh-3929-character-length-functions
src/box/sql/func.c | 3 +++
test/sql-tap/func3.test.lua | 23 ++++++++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 761a3ab..98cad51 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1893,6 +1893,9 @@ sqlRegisterBuiltinFunctions(void)
FIELD_TYPE_STRING),
FUNCTION2(length, 1, 0, 0, lengthFunc, SQL_FUNC_LENGTH,
FIELD_TYPE_INTEGER),
+ FUNCTION(char_length, 1, 0, 0, lengthFunc, FIELD_TYPE_INTEGER),
+ FUNCTION(character_length, 1, 0, 0, lengthFunc,
+ FIELD_TYPE_INTEGER),
FUNCTION(position, 2, 0, 1, position_func, FIELD_TYPE_INTEGER),
FUNCTION(printf, -1, 0, 0, printfFunc, FIELD_TYPE_STRING),
FUNCTION(unicode, 1, 0, 0, unicodeFunc, FIELD_TYPE_STRING),
diff --git a/test/sql-tap/func3.test.lua b/test/sql-tap/func3.test.lua
index 6d6411c..2d0579d 100755
--- a/test/sql-tap/func3.test.lua
+++ b/test/sql-tap/func3.test.lua
@@ -1,6 +1,6 @@
#!/usr/bin/env tarantool
test = require("sqltester")
-test:plan(25)
+test:plan(35)
--!./tcltestrunner.lua
-- 2010 August 27
@@ -285,5 +285,26 @@ test:do_test(
end, test:execsql "EXPLAIN SELECT min(1.0+'2.0',4*11)")
+--
+-- gh-3929: sql: ANSI aliases for LENGTH().
+--
+suits = {}
+suits[1] = {str = '123456789', len = 9}
+suits[2] = {str = '\x80', len = 1}
+suits[3] = {str = '\x61\x62\x63', len = 3}
+suits[4] = {str = '\x7f\x80\x81', len = 3}
+suits[5] = {str = '\x61\xc0', len = 2}
+suits[6] = {str = '\x61\xc0\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80', len = 12}
+suits[7] = {str = '\xc0\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80', len = 11}
+suits[8] = {str = '\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80', len = 10}
+suits[9] = {str = '\x80\x80\x80\x80\x80\xf0\x80\x80\x80\x80', len = 7}
+suits[10] = {str = '\x80\x80\x80\x80\x80\xf0\x80\x80\x80\xff', len = 7}
+
+for k,v in pairs(suits) do
+ test:do_execsql_test(
+ "func3-6."..k,
+ "SELECT CHAR_LENGTH('"..v.str.."'), CHARACTER_LENGTH('"..v.str.."');",
+ {v.len, v.len})
+end
test:finish_test()
--
2.7.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tarantool-patches] Re: [PATCH v2 1/1] sql: ANSI aliases for LENGTH()
2019-07-06 10:46 [tarantool-patches] [PATCH v2 1/1] sql: ANSI aliases for LENGTH() imeevma
@ 2019-07-08 13:12 ` n.pettik
2019-07-11 7:48 ` Kirill Yukhin
1 sibling, 0 replies; 3+ messages in thread
From: n.pettik @ 2019-07-08 13:12 UTC (permalink / raw)
To: tarantool-patches; +Cc: Imeev Mergen
> src/box/sql/func.c | 3 +++
> test/sql-tap/func3.test.lua | 23 ++++++++++++++++++++++-
> 2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> index 761a3ab..98cad51 100644
> --- a/src/box/sql/func.c
> +++ b/src/box/sql/func.c
> @@ -1893,6 +1893,9 @@ sqlRegisterBuiltinFunctions(void)
> FIELD_TYPE_STRING),
> FUNCTION2(length, 1, 0, 0, lengthFunc, SQL_FUNC_LENGTH,
> FIELD_TYPE_INTEGER),
> + FUNCTION(char_length, 1, 0, 0, lengthFunc, FIELD_TYPE_INTEGER),
> + FUNCTION(character_length, 1, 0, 0, lengthFunc,
> + FIELD_TYPE_INTEGER),
Please, verify usage of SQL_FUNC_LEGTH flag. I see that it serves
to provide certain optimisation, but it is likely to be inapplicable to
the current SQL implementation. Hence, I guess we should remove
it now and create an issue to resurrect it in the future (if it is possible at all).
lgtm
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tarantool-patches] Re: [PATCH v2 1/1] sql: ANSI aliases for LENGTH()
2019-07-06 10:46 [tarantool-patches] [PATCH v2 1/1] sql: ANSI aliases for LENGTH() imeevma
2019-07-08 13:12 ` [tarantool-patches] " n.pettik
@ 2019-07-11 7:48 ` Kirill Yukhin
1 sibling, 0 replies; 3+ messages in thread
From: Kirill Yukhin @ 2019-07-11 7:48 UTC (permalink / raw)
To: tarantool-patches; +Cc: korablev
Hello,
On 06 Jul 13:46, imeevma@tarantool.org wrote:
> This patch creates aliases CHARACTER_LENGTH() and CHAR_LENGTH()
> for LENGTH(). These functions are added because they are described
> in ANSI.
>
> Closes #3929
I've checked your patch into master.
--
Regards, Kirill Yukhin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-11 7:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-06 10:46 [tarantool-patches] [PATCH v2 1/1] sql: ANSI aliases for LENGTH() imeevma
2019-07-08 13:12 ` [tarantool-patches] " n.pettik
2019-07-11 7:48 ` Kirill Yukhin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox