mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge pull request #57821 from rschu1ze/consolidate-substring-tests
Dumb down `substring()` tests
This commit is contained in:
commit
414a2893d0
@ -533,8 +533,8 @@ Result:
|
||||
|
||||
```result
|
||||
┌─concatWithSeparator('a', '1', '2', '3', '4')─┐
|
||||
│ 1a2a3a4 │
|
||||
└───────────────────────────────────┘
|
||||
│ 1a2a3a4 │
|
||||
└──────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## concatWithSeparatorAssumeInjective
|
||||
|
@ -56,23 +56,28 @@ public:
|
||||
{
|
||||
/// UTF8 variant is not available for FixedString and Enum arguments.
|
||||
if (!isString(arguments[0]))
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of first argument of function {}",
|
||||
arguments[0]->getName(), getName());
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||
"Illegal type {} of first argument of function {}, expected String",
|
||||
arguments[0]->getName(), getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isStringOrFixedString(arguments[0]) && !isEnum(arguments[0]))
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of first argument of function {}",
|
||||
arguments[0]->getName(), getName());
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||
"Illegal type {} of first argument of function {}, expected String, FixedString or Enum",
|
||||
arguments[0]->getName(), getName());
|
||||
}
|
||||
|
||||
if (!isNativeNumber(arguments[1]))
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of second argument of function {}",
|
||||
arguments[1]->getName(), getName());
|
||||
throw Exception(
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||
"Illegal type {} of second argument of function {}, expected (U)Int*",
|
||||
arguments[1]->getName(), getName());
|
||||
|
||||
if (number_of_arguments == 3 && !isNativeNumber(arguments[2]))
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of second argument of function {}",
|
||||
arguments[2]->getName(), getName());
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||
"Illegal type {} of second argument of function {}, expected (U)Int*",
|
||||
arguments[2]->getName(), getName());
|
||||
|
||||
return std::make_shared<DataTypeString>();
|
||||
}
|
||||
|
@ -1,155 +0,0 @@
|
||||
-- Positive offsets (slice from left)
|
||||
Offset: 1 Length: 1 hello shark h s
|
||||
Offset: 1 Length: 2 hello shark he sh
|
||||
Offset: 1 Length: 3 hello shark hel sha
|
||||
Offset: 1 Length: 4 hello shark hell shar
|
||||
Offset: 1 Length: 5 hello shark hello shark
|
||||
Offset: 1 Length: 6 hello shark hello shark
|
||||
Offset: 2 Length: 1 ello hark e h
|
||||
Offset: 2 Length: 2 ello hark el ha
|
||||
Offset: 2 Length: 3 ello hark ell har
|
||||
Offset: 2 Length: 4 ello hark ello hark
|
||||
Offset: 2 Length: 5 ello hark ello hark
|
||||
Offset: 2 Length: 6 ello hark ello hark
|
||||
Offset: 3 Length: 1 llo ark l a
|
||||
Offset: 3 Length: 2 llo ark ll ar
|
||||
Offset: 3 Length: 3 llo ark llo ark
|
||||
Offset: 3 Length: 4 llo ark llo ark
|
||||
Offset: 3 Length: 5 llo ark llo ark
|
||||
Offset: 3 Length: 6 llo ark llo ark
|
||||
Offset: 4 Length: 1 lo rk l r
|
||||
Offset: 4 Length: 2 lo rk lo rk
|
||||
Offset: 4 Length: 3 lo rk lo rk
|
||||
Offset: 4 Length: 4 lo rk lo rk
|
||||
Offset: 4 Length: 5 lo rk lo rk
|
||||
Offset: 4 Length: 6 lo rk lo rk
|
||||
Offset: 5 Length: 1 o k o k
|
||||
Offset: 5 Length: 2 o k o k
|
||||
Offset: 5 Length: 3 o k o k
|
||||
Offset: 5 Length: 4 o k o k
|
||||
Offset: 5 Length: 5 o k o k
|
||||
Offset: 5 Length: 6 o k o k
|
||||
Offset: 6 Length: 1
|
||||
Offset: 6 Length: 2
|
||||
Offset: 6 Length: 3
|
||||
Offset: 6 Length: 4
|
||||
Offset: 6 Length: 5
|
||||
Offset: 6 Length: 6
|
||||
Offset: 1 Length: 1 world eagle w e
|
||||
Offset: 1 Length: 2 world eagle wo ea
|
||||
Offset: 1 Length: 3 world eagle wor eag
|
||||
Offset: 1 Length: 4 world eagle worl eagl
|
||||
Offset: 1 Length: 5 world eagle world eagle
|
||||
Offset: 1 Length: 6 world eagle world eagle
|
||||
Offset: 2 Length: 1 orld agle o a
|
||||
Offset: 2 Length: 2 orld agle or ag
|
||||
Offset: 2 Length: 3 orld agle orl agl
|
||||
Offset: 2 Length: 4 orld agle orld agle
|
||||
Offset: 2 Length: 5 orld agle orld agle
|
||||
Offset: 2 Length: 6 orld agle orld agle
|
||||
Offset: 3 Length: 1 rld gle r g
|
||||
Offset: 3 Length: 2 rld gle rl gl
|
||||
Offset: 3 Length: 3 rld gle rld gle
|
||||
Offset: 3 Length: 4 rld gle rld gle
|
||||
Offset: 3 Length: 5 rld gle rld gle
|
||||
Offset: 3 Length: 6 rld gle rld gle
|
||||
Offset: 4 Length: 1 ld le l l
|
||||
Offset: 4 Length: 2 ld le ld le
|
||||
Offset: 4 Length: 3 ld le ld le
|
||||
Offset: 4 Length: 4 ld le ld le
|
||||
Offset: 4 Length: 5 ld le ld le
|
||||
Offset: 4 Length: 6 ld le ld le
|
||||
Offset: 5 Length: 1 d e d e
|
||||
Offset: 5 Length: 2 d e d e
|
||||
Offset: 5 Length: 3 d e d e
|
||||
Offset: 5 Length: 4 d e d e
|
||||
Offset: 5 Length: 5 d e d e
|
||||
Offset: 5 Length: 6 d e d e
|
||||
Offset: 6 Length: 1
|
||||
Offset: 6 Length: 2
|
||||
Offset: 6 Length: 3
|
||||
Offset: 6 Length: 4
|
||||
Offset: 6 Length: 5
|
||||
Offset: 6 Length: 6
|
||||
-- Negative offsets (slice from right)
|
||||
Offset: -1 Length: 1 o k o k
|
||||
Offset: -1 Length: 2 o k o k
|
||||
Offset: -1 Length: 3 o k o k
|
||||
Offset: -1 Length: 4 o k o k
|
||||
Offset: -1 Length: 5 o k o k
|
||||
Offset: -1 Length: 6 o k o k
|
||||
Offset: -2 Length: 1 lo rk l r
|
||||
Offset: -2 Length: 2 lo rk lo rk
|
||||
Offset: -2 Length: 3 lo rk lo rk
|
||||
Offset: -2 Length: 4 lo rk lo rk
|
||||
Offset: -2 Length: 5 lo rk lo rk
|
||||
Offset: -2 Length: 6 lo rk lo rk
|
||||
Offset: -3 Length: 1 llo ark l a
|
||||
Offset: -3 Length: 2 llo ark ll ar
|
||||
Offset: -3 Length: 3 llo ark llo ark
|
||||
Offset: -3 Length: 4 llo ark llo ark
|
||||
Offset: -3 Length: 5 llo ark llo ark
|
||||
Offset: -3 Length: 6 llo ark llo ark
|
||||
Offset: -4 Length: 1 ello hark e h
|
||||
Offset: -4 Length: 2 ello hark el ha
|
||||
Offset: -4 Length: 3 ello hark ell har
|
||||
Offset: -4 Length: 4 ello hark ello hark
|
||||
Offset: -4 Length: 5 ello hark ello hark
|
||||
Offset: -4 Length: 6 ello hark ello hark
|
||||
Offset: -5 Length: 1 hello shark h s
|
||||
Offset: -5 Length: 2 hello shark he sh
|
||||
Offset: -5 Length: 3 hello shark hel sha
|
||||
Offset: -5 Length: 4 hello shark hell shar
|
||||
Offset: -5 Length: 5 hello shark hello shark
|
||||
Offset: -5 Length: 6 hello shark hello shark
|
||||
Offset: -6 Length: 1 hello shark
|
||||
Offset: -6 Length: 2 hello shark h s
|
||||
Offset: -6 Length: 3 hello shark he sh
|
||||
Offset: -6 Length: 4 hello shark hel sha
|
||||
Offset: -6 Length: 5 hello shark hell shar
|
||||
Offset: -6 Length: 6 hello shark hello shark
|
||||
Offset: -1 Length: 1 d e d e
|
||||
Offset: -1 Length: 2 d e d e
|
||||
Offset: -1 Length: 3 d e d e
|
||||
Offset: -1 Length: 4 d e d e
|
||||
Offset: -1 Length: 5 d e d e
|
||||
Offset: -1 Length: 6 d e d e
|
||||
Offset: -2 Length: 1 ld le l l
|
||||
Offset: -2 Length: 2 ld le ld le
|
||||
Offset: -2 Length: 3 ld le ld le
|
||||
Offset: -2 Length: 4 ld le ld le
|
||||
Offset: -2 Length: 5 ld le ld le
|
||||
Offset: -2 Length: 6 ld le ld le
|
||||
Offset: -3 Length: 1 rld gle r g
|
||||
Offset: -3 Length: 2 rld gle rl gl
|
||||
Offset: -3 Length: 3 rld gle rld gle
|
||||
Offset: -3 Length: 4 rld gle rld gle
|
||||
Offset: -3 Length: 5 rld gle rld gle
|
||||
Offset: -3 Length: 6 rld gle rld gle
|
||||
Offset: -4 Length: 1 orld agle o a
|
||||
Offset: -4 Length: 2 orld agle or ag
|
||||
Offset: -4 Length: 3 orld agle orl agl
|
||||
Offset: -4 Length: 4 orld agle orld agle
|
||||
Offset: -4 Length: 5 orld agle orld agle
|
||||
Offset: -4 Length: 6 orld agle orld agle
|
||||
Offset: -5 Length: 1 world eagle w e
|
||||
Offset: -5 Length: 2 world eagle wo ea
|
||||
Offset: -5 Length: 3 world eagle wor eag
|
||||
Offset: -5 Length: 4 world eagle worl eagl
|
||||
Offset: -5 Length: 5 world eagle world eagle
|
||||
Offset: -5 Length: 6 world eagle world eagle
|
||||
Offset: -6 Length: 1 world eagle
|
||||
Offset: -6 Length: 2 world eagle w e
|
||||
Offset: -6 Length: 3 world eagle wo ea
|
||||
Offset: -6 Length: 4 world eagle wor eag
|
||||
Offset: -6 Length: 5 world eagle worl eagl
|
||||
Offset: -6 Length: 6 world eagle world eagle
|
||||
-- Zero offset/length
|
||||
Offset: 0 Length: 0
|
||||
Offset: 0 Length: 1
|
||||
Offset: 1 Length: 0 hello shark
|
||||
Offset: 0 Length: 0
|
||||
Offset: 0 Length: 1
|
||||
Offset: 1 Length: 0 world eagle
|
||||
-- Constant enums
|
||||
f fo
|
@ -1,32 +0,0 @@
|
||||
DROP TABLE IF EXISTS tab;
|
||||
CREATE TABLE tab(e8 Enum8('hello' = -5, 'world' = 15), e16 Enum16('shark' = -999, 'eagle' = 9999)) ENGINE MergeTree ORDER BY tuple();
|
||||
INSERT INTO TABLE tab VALUES ('hello', 'shark'), ('world', 'eagle');
|
||||
|
||||
SELECT '-- Positive offsets (slice from left)';
|
||||
WITH cte AS (SELECT number + 1 AS n FROM system.numbers LIMIT 6),
|
||||
permutations AS (SELECT c1.n AS offset, c2.n AS length FROM cte AS c1 CROSS JOIN cte AS c2)
|
||||
SELECT 'Offset: ', p.offset, 'Length: ', p.length,
|
||||
substring(e8, p.offset) AS s1, substring(e16, p.offset) AS s2,
|
||||
substring(e8, p.offset, p.length) AS s3, substring(e16, p.offset, p.length) AS s4
|
||||
FROM tab LEFT JOIN permutations AS p ON true;
|
||||
|
||||
SELECT '-- Negative offsets (slice from right)';
|
||||
WITH cte AS (SELECT number + 1 AS n FROM system.numbers LIMIT 6),
|
||||
permutations AS (SELECT -c1.n AS offset, c2.n AS length FROM cte AS c1 CROSS JOIN cte AS c2)
|
||||
SELECT 'Offset: ', p.offset, 'Length: ', p.length,
|
||||
substring(e8, p.offset) AS s1, substring(e16, p.offset) AS s2,
|
||||
substring(e8, p.offset, p.length) AS s3, substring(e16, p.offset, p.length) AS s4
|
||||
FROM tab LEFT JOIN permutations AS p ON true;
|
||||
|
||||
SELECT '-- Zero offset/length';
|
||||
WITH cte AS (SELECT number AS n FROM system.numbers LIMIT 2),
|
||||
permutations AS (SELECT c1.n AS offset, c2.n AS length FROM cte AS c1 CROSS JOIN cte AS c2 LIMIT 3)
|
||||
SELECT 'Offset: ', p.offset, 'Length: ', p.length,
|
||||
substring(e8, p.offset) AS s1, substring(e16, p.offset) AS s2,
|
||||
substring(e8, p.offset, p.length) AS s3, substring(e16, p.offset, p.length) AS s4
|
||||
FROM tab LEFT JOIN permutations AS p ON true;
|
||||
|
||||
SELECT '-- Constant enums';
|
||||
SELECT substring(CAST('foo', 'Enum8(\'foo\' = 1)'), 1, 1), substring(CAST('foo', 'Enum16(\'foo\' = 1111)'), 1, 2);
|
||||
|
||||
DROP TABLE tab;
|
@ -1,52 +0,0 @@
|
||||
hello\0\0\0
|
||||
hello\0\0\0
|
||||
0\0\0\0\0\0\0\0
|
||||
1\0\0\0\0\0\0\0
|
||||
2\0\0\0\0\0\0\0
|
||||
3\0\0\0\0\0\0\0
|
||||
4\0\0\0\0\0\0\0
|
||||
5\0\0\0\0\0\0\0
|
||||
6\0\0\0\0\0\0\0
|
||||
7\0\0\0\0\0\0\0
|
||||
8\0\0\0\0\0\0\0
|
||||
9\0\0\0\0\0\0\0
|
||||
995
|
||||
996
|
||||
997
|
||||
998
|
||||
999
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
|
||||
9
|
||||
99
|
||||
998
|
||||
999\0
|
||||
|
||||
1
|
||||
10
|
||||
100
|
||||
1004
|
||||
995\0
|
||||
96\0
|
||||
7\0
|
||||
\0
|
||||
|
||||
1000
|
||||
001
|
||||
02
|
||||
3
|
||||
|
||||
995
|
||||
9
|
||||
7\0
|
||||
\0
|
||||
|
||||
10
|
||||
001
|
||||
0
|
||||
3
|
||||
|
@ -1,7 +0,0 @@
|
||||
SELECT substring(toFixedString('hello', 16), 1, 8);
|
||||
SELECT substring(toFixedString(materialize('hello'), 16), 1, 8);
|
||||
SELECT substring(toFixedString(toString(number), 16), 1, 8) FROM system.numbers LIMIT 10;
|
||||
SELECT substring(toFixedString(toString(number), 4), 1, 3) FROM system.numbers LIMIT 995, 10;
|
||||
SELECT substring(toFixedString(toString(number), 4), 1, number % 5) FROM system.numbers LIMIT 995, 10;
|
||||
SELECT substring(toFixedString(toString(number), 4), 1 + number % 5) FROM system.numbers LIMIT 995, 10;
|
||||
SELECT substring(toFixedString(toString(number), 4), 1 + number % 5, 1 + number % 3) FROM system.numbers LIMIT 995, 10;
|
@ -1,40 +0,0 @@
|
||||
abc
|
||||
abc
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
abc
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
abc
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
abc
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
@ -1,4 +0,0 @@
|
||||
SELECT substring('abc', number - 5) FROM system.numbers LIMIT 10;
|
||||
SELECT substring(materialize('abc'), number - 5) FROM system.numbers LIMIT 10;
|
||||
SELECT substring(toFixedString('abc', 3), number - 5) FROM system.numbers LIMIT 10;
|
||||
SELECT substring(materialize(toFixedString('abc', 3)), number - 5) FROM system.numbers LIMIT 10;
|
@ -1,4 +0,0 @@
|
||||
SELECT substring('hello', []); -- { serverError 43 }
|
||||
SELECT substring('hello', 1, []); -- { serverError 43 }
|
||||
SELECT substring(materialize('hello'), -1, -1);
|
||||
SELECT substring(materialize('hello'), 0); -- { serverError 135 }
|
173
tests/queries/0_stateless/01033_function_substring.reference
Normal file
173
tests/queries/0_stateless/01033_function_substring.reference
Normal file
@ -0,0 +1,173 @@
|
||||
-- argument validation
|
||||
|
||||
-- FixedString arguments
|
||||
hello\0\0\0
|
||||
hello\0\0\0
|
||||
0\0\0\0\0\0\0\0
|
||||
1\0\0\0\0\0\0\0
|
||||
2\0\0\0\0\0\0\0
|
||||
3\0\0\0\0\0\0\0
|
||||
4\0\0\0\0\0\0\0
|
||||
5\0\0\0\0\0\0\0
|
||||
6\0\0\0\0\0\0\0
|
||||
7\0\0\0\0\0\0\0
|
||||
8\0\0\0\0\0\0\0
|
||||
9\0\0\0\0\0\0\0
|
||||
995
|
||||
996
|
||||
997
|
||||
998
|
||||
999
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
|
||||
9
|
||||
99
|
||||
998
|
||||
999\0
|
||||
|
||||
1
|
||||
10
|
||||
100
|
||||
1004
|
||||
995\0
|
||||
96\0
|
||||
7\0
|
||||
\0
|
||||
|
||||
1000
|
||||
001
|
||||
02
|
||||
3
|
||||
|
||||
995
|
||||
9
|
||||
7\0
|
||||
\0
|
||||
|
||||
10
|
||||
001
|
||||
0
|
||||
3
|
||||
|
||||
-- Enum arguments
|
||||
hello shark
|
||||
world eagle
|
||||
ello hark
|
||||
orld agle
|
||||
o k
|
||||
d e
|
||||
lo rk
|
||||
ld le
|
||||
|
||||
|
||||
-- Constant enums
|
||||
f fo
|
||||
-- negative offset argument
|
||||
abc
|
||||
abc
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
abc
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
abc
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
abc
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
abc
|
||||
bc
|
||||
c
|
||||
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
-- negative length argument
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
23456
|
||||
bcdef
|
||||
3456
|
||||
bcdef
|
||||
2345
|
||||
bcdef
|
||||
345
|
||||
bcdef
|
||||
23456
|
||||
bcdef
|
||||
3456
|
||||
bcdef
|
||||
2345
|
||||
bcdef
|
||||
345
|
||||
-- negative offset and size
|
||||
|
||||
|
||||
|
||||
g
|
||||
g
|
||||
g
|
||||
|
||||
|
||||
|
||||
g
|
||||
g
|
||||
g
|
||||
|
||||
|
||||
|
||||
6
|
||||
|
||||
|
||||
|
||||
|
||||
-
|
||||
|
||||
|
||||
|
||||
6
|
||||
|
||||
|
||||
|
||||
|
||||
UBSAN bug
|
146
tests/queries/0_stateless/01033_function_substring.sql
Normal file
146
tests/queries/0_stateless/01033_function_substring.sql
Normal file
@ -0,0 +1,146 @@
|
||||
SELECT '-- argument validation';
|
||||
|
||||
SELECT substring('hello', []); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||
SELECT substring('hello', 1, []); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||
SELECT substring(materialize('hello'), -1, -1);
|
||||
SELECT substring(materialize('hello'), 0); -- { serverError ZERO_ARRAY_OR_TUPLE_INDEX }
|
||||
|
||||
SELECT '-- FixedString arguments';
|
||||
|
||||
SELECT substring(toFixedString('hello', 16), 1, 8);
|
||||
SELECT substring(toFixedString(materialize('hello'), 16), 1, 8);
|
||||
SELECT substring(toFixedString(toString(number), 16), 1, 8) FROM system.numbers LIMIT 10;
|
||||
SELECT substring(toFixedString(toString(number), 4), 1, 3) FROM system.numbers LIMIT 995, 10;
|
||||
SELECT substring(toFixedString(toString(number), 4), 1, number % 5) FROM system.numbers LIMIT 995, 10;
|
||||
SELECT substring(toFixedString(toString(number), 4), 1 + number % 5) FROM system.numbers LIMIT 995, 10;
|
||||
SELECT substring(toFixedString(toString(number), 4), 1 + number % 5, 1 + number % 3) FROM system.numbers LIMIT 995, 10;
|
||||
|
||||
SELECT '-- Enum arguments';
|
||||
|
||||
DROP TABLE IF EXISTS tab;
|
||||
CREATE TABLE tab(e8 Enum8('hello' = -5, 'world' = 15), e16 Enum16('shark' = -999, 'eagle' = 9999)) ENGINE MergeTree ORDER BY tuple();
|
||||
INSERT INTO TABLE tab VALUES ('hello', 'shark'), ('world', 'eagle');
|
||||
|
||||
-- positive offsets (slice from left)
|
||||
SELECT substring(e8, 1), substring (e16, 1) FROM tab;
|
||||
SELECT substring(e8, 2, 10), substring (e16, 2, 10) FROM tab;
|
||||
-- negative offsets (slice from right)
|
||||
SELECT substring(e8, -1), substring (e16, -1) FROM tab;
|
||||
SELECT substring(e8, -2, 10), substring (e16, -2, 10) FROM tab;
|
||||
-- zero offset/length
|
||||
SELECT substring(e8, 1, 0), substring (e16, 1, 0) FROM tab;
|
||||
|
||||
SELECT '-- Constant enums';
|
||||
SELECT substring(CAST('foo', 'Enum8(\'foo\' = 1)'), 1, 1), substring(CAST('foo', 'Enum16(\'foo\' = 1111)'), 1, 2);
|
||||
|
||||
DROP TABLE tab;
|
||||
|
||||
SELECT '-- negative offset argument';
|
||||
|
||||
SELECT substring('abc', number - 5) FROM system.numbers LIMIT 10;
|
||||
SELECT substring(materialize('abc'), number - 5) FROM system.numbers LIMIT 10;
|
||||
SELECT substring(toFixedString('abc', 3), number - 5) FROM system.numbers LIMIT 10;
|
||||
SELECT substring(materialize(toFixedString('abc', 3)), number - 5) FROM system.numbers LIMIT 10;
|
||||
|
||||
SELECT substring('clickhouse', 2, -2);
|
||||
SELECT substring(materialize('clickhouse'), 2, -2);
|
||||
SELECT substring('clickhouse', materialize(2), -2);
|
||||
SELECT substring(materialize('clickhouse'), materialize(2), -2);
|
||||
SELECT substring('clickhouse', 2, materialize(-2));
|
||||
SELECT substring(materialize('clickhouse'), 2, materialize(-2));
|
||||
SELECT substring('clickhouse', materialize(2), materialize(-2));
|
||||
SELECT substring(materialize('clickhouse'), materialize(2), materialize(-2));
|
||||
|
||||
SELECT '-- negative length argument';
|
||||
|
||||
SELECT substring('abcdefgh', 2, -2);
|
||||
SELECT substring('abcdefgh', materialize(2), -2);
|
||||
SELECT substring('abcdefgh', 2, materialize(-2));
|
||||
SELECT substring('abcdefgh', materialize(2), materialize(-2));
|
||||
|
||||
SELECT substring(cast('abcdefgh' AS FixedString(8)), 2, -2);
|
||||
SELECT substring(cast('abcdefgh' AS FixedString(8)), materialize(2), -2);
|
||||
SELECT substring(cast('abcdefgh' AS FixedString(8)), 2, materialize(-2));
|
||||
SELECT substring(cast('abcdefgh' AS FixedString(8)), materialize(2), materialize(-2));
|
||||
|
||||
DROP TABLE IF EXISTS tab;
|
||||
CREATE TABLE tab (s String, l Int8, r Int8) ENGINE = Memory;
|
||||
INSERT INTO tab VALUES ('abcdefgh', 2, -2), ('12345678', 3, -3);
|
||||
|
||||
SELECT substring(s, 2, -2) FROM tab;
|
||||
SELECT substring(s, l, -2) FROM tab;
|
||||
SELECT substring(s, 2, r) FROM tab;
|
||||
SELECT substring(s, l, r) FROM tab;
|
||||
|
||||
DROP TABLE IF EXISTS tab;
|
||||
CREATE TABLE tab (s FixedString(8), l Int8, r Int8) ENGINE = Memory;
|
||||
INSERT INTO tab VALUES ('abcdefgh', 2, -2), ('12345678', 3, -3);
|
||||
|
||||
SELECT substring(s, 2, -2) FROM tab;
|
||||
SELECT substring(s, l, -2) FROM tab;
|
||||
SELECT substring(s, 2, r) FROM tab;
|
||||
SELECT substring(s, l, r) FROM tab;
|
||||
|
||||
DROP TABLE IF EXISTS tab;
|
||||
|
||||
SELECT '-- negative offset and size';
|
||||
|
||||
SELECT substring('abcdefgh', -2, -2);
|
||||
SELECT substring(materialize('abcdefgh'), -2, -2);
|
||||
SELECT substring(materialize('abcdefgh'), materialize(-2), materialize(-2));
|
||||
|
||||
SELECT substring('abcdefgh', -2, -1);
|
||||
SELECT substring(materialize('abcdefgh'), -2, -1);
|
||||
SELECT substring(materialize('abcdefgh'), materialize(-2), materialize(-1));
|
||||
|
||||
SELECT substring(cast('abcdefgh' AS FixedString(8)), -2, -2);
|
||||
SELECT substring(materialize(cast('abcdefgh' AS FixedString(8))), -2, -2);
|
||||
SELECT substring(materialize(cast('abcdefgh' AS FixedString(8))), materialize(-2), materialize(-2));
|
||||
|
||||
SELECT substring(cast('abcdefgh' AS FixedString(8)), -2, -1);
|
||||
SELECT substring(materialize(cast('abcdefgh' AS FixedString(8))), -2, -1);
|
||||
SELECT substring(materialize(cast('abcdefgh' AS FixedString(8))), materialize(-2), materialize(-1));
|
||||
|
||||
DROP TABLE IF EXISTS t;
|
||||
CREATE TABLE t
|
||||
(
|
||||
s String,
|
||||
l Int8,
|
||||
r Int8
|
||||
) ENGINE = Memory;
|
||||
|
||||
INSERT INTO t VALUES ('abcdefgh', -2, -2),('12345678', -3, -3);
|
||||
|
||||
SELECT substring(s, -2, -2) FROM t;
|
||||
SELECT substring(s, l, -2) FROM t;
|
||||
SELECT substring(s, -2, r) FROM t;
|
||||
SELECT substring(s, l, r) FROM t;
|
||||
|
||||
SELECT '-';
|
||||
DROP TABLE IF EXISTS t;
|
||||
CREATE TABLE t(
|
||||
s FixedString(8),
|
||||
l Int8,
|
||||
r Int8
|
||||
) engine = Memory;
|
||||
INSERT INTO t VALUES ('abcdefgh', -2, -2),('12345678', -3, -3);
|
||||
|
||||
SELECT substring(s, -2, -2) FROM t;
|
||||
SELECT substring(s, l, -2) FROM t;
|
||||
SELECT substring(s, -2, r) FROM t;
|
||||
SELECT substring(s, l, r) FROM t;
|
||||
|
||||
DROP table if exists t;
|
||||
|
||||
SELECT 'UBSAN bug';
|
||||
|
||||
/** NOTE: The behaviour of substring and substringUTF8 is inconsistent when negative offset is greater than string size:
|
||||
* substring:
|
||||
* hello
|
||||
* ^-----^ - offset -10, length 7, result: "he"
|
||||
* substringUTF8:
|
||||
* hello
|
||||
* ^-----^ - offset -10, length 7, result: "hello"
|
||||
* This may be subject for change.
|
||||
*/
|
||||
SELECT substringUTF8('hello, пÑ<C2BF>ивеÑ<C2B5>', -9223372036854775808, number) FROM numbers(16) FORMAT Null;
|
@ -1,8 +0,0 @@
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
||||
lickhou
|
@ -1,8 +0,0 @@
|
||||
SELECT substr('clickhouse', 2, -2);
|
||||
SELECT substr(materialize('clickhouse'), 2, -2);
|
||||
SELECT substr('clickhouse', materialize(2), -2);
|
||||
SELECT substr(materialize('clickhouse'), materialize(2), -2);
|
||||
SELECT substr('clickhouse', 2, materialize(-2));
|
||||
SELECT substr(materialize('clickhouse'), 2, materialize(-2));
|
||||
SELECT substr('clickhouse', materialize(2), materialize(-2));
|
||||
SELECT substr(materialize('clickhouse'), materialize(2), materialize(-2));
|
@ -1,27 +0,0 @@
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
-
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
bcdef
|
||||
-
|
||||
bcdef
|
||||
23456
|
||||
bcdef
|
||||
3456
|
||||
bcdef
|
||||
2345
|
||||
bcdef
|
||||
345
|
||||
-
|
||||
bcdef
|
||||
23456
|
||||
bcdef
|
||||
3456
|
||||
bcdef
|
||||
2345
|
||||
bcdef
|
||||
345
|
@ -1,36 +0,0 @@
|
||||
select substring('abcdefgh', 2, -2);
|
||||
select substring('abcdefgh', materialize(2), -2);
|
||||
select substring('abcdefgh', 2, materialize(-2));
|
||||
select substring('abcdefgh', materialize(2), materialize(-2));
|
||||
|
||||
select '-';
|
||||
|
||||
select substring(cast('abcdefgh' as FixedString(8)), 2, -2);
|
||||
select substring(cast('abcdefgh' as FixedString(8)), materialize(2), -2);
|
||||
select substring(cast('abcdefgh' as FixedString(8)), 2, materialize(-2));
|
||||
select substring(cast('abcdefgh' as FixedString(8)), materialize(2), materialize(-2));
|
||||
|
||||
select '-';
|
||||
|
||||
drop table if exists t;
|
||||
create table t (s String, l Int8, r Int8) engine = Memory;
|
||||
insert into t values ('abcdefgh', 2, -2), ('12345678', 3, -3);
|
||||
|
||||
select substring(s, 2, -2) from t;
|
||||
select substring(s, l, -2) from t;
|
||||
select substring(s, 2, r) from t;
|
||||
select substring(s, l, r) from t;
|
||||
|
||||
select '-';
|
||||
|
||||
drop table if exists t;
|
||||
create table t (s FixedString(8), l Int8, r Int8) engine = Memory;
|
||||
insert into t values ('abcdefgh', 2, -2), ('12345678', 3, -3);
|
||||
|
||||
select substring(s, 2, -2) from t;
|
||||
select substring(s, l, -2) from t;
|
||||
select substring(s, 2, r) from t;
|
||||
select substring(s, l, r) from t;
|
||||
|
||||
drop table if exists t;
|
||||
|
@ -1,10 +0,0 @@
|
||||
/** NOTE: The behaviour of substring and substringUTF8 is inconsistent when negative offset is greater than string size:
|
||||
* substring:
|
||||
* hello
|
||||
* ^-----^ - offset -10, length 7, result: "he"
|
||||
* substringUTF8:
|
||||
* hello
|
||||
* ^-----^ - offset -10, length 7, result: "hello"
|
||||
* This may be subject for change.
|
||||
*/
|
||||
SELECT substringUTF8('hello, пÑ<C2BF>ивеÑ<C2B5>', -9223372036854775808, number) FROM numbers(16) FORMAT Null;
|
@ -1,31 +0,0 @@
|
||||
|
||||
|
||||
|
||||
g
|
||||
g
|
||||
g
|
||||
-
|
||||
|
||||
|
||||
|
||||
g
|
||||
g
|
||||
g
|
||||
-
|
||||
|
||||
|
||||
|
||||
6
|
||||
|
||||
|
||||
|
||||
|
||||
-
|
||||
|
||||
|
||||
|
||||
6
|
||||
|
||||
|
||||
|
||||
|
@ -1,48 +0,0 @@
|
||||
select substring('abcdefgh', -2, -2);
|
||||
select substring(materialize('abcdefgh'), -2, -2);
|
||||
select substring(materialize('abcdefgh'), materialize(-2), materialize(-2));
|
||||
|
||||
select substring('abcdefgh', -2, -1);
|
||||
select substring(materialize('abcdefgh'), -2, -1);
|
||||
select substring(materialize('abcdefgh'), materialize(-2), materialize(-1));
|
||||
|
||||
select '-';
|
||||
select substring(cast('abcdefgh' as FixedString(8)), -2, -2);
|
||||
select substring(materialize(cast('abcdefgh' as FixedString(8))), -2, -2);
|
||||
select substring(materialize(cast('abcdefgh' as FixedString(8))), materialize(-2), materialize(-2));
|
||||
|
||||
select substring(cast('abcdefgh' as FixedString(8)), -2, -1);
|
||||
select substring(materialize(cast('abcdefgh' as FixedString(8))), -2, -1);
|
||||
select substring(materialize(cast('abcdefgh' as FixedString(8))), materialize(-2), materialize(-1));
|
||||
|
||||
select '-';
|
||||
drop table if exists t;
|
||||
create table t
|
||||
(
|
||||
s String,
|
||||
l Int8,
|
||||
r Int8
|
||||
) engine = Memory;
|
||||
|
||||
insert into t values ('abcdefgh', -2, -2),('12345678', -3, -3);
|
||||
|
||||
select substring(s, -2, -2) from t;
|
||||
select substring(s, l, -2) from t;
|
||||
select substring(s, -2, r) from t;
|
||||
select substring(s, l, r) from t;
|
||||
|
||||
select '-';
|
||||
drop table if exists t;
|
||||
create table t(
|
||||
s FixedString(8),
|
||||
l Int8,
|
||||
r Int8
|
||||
) engine = Memory;
|
||||
insert into t values ('abcdefgh', -2, -2),('12345678', -3, -3);
|
||||
|
||||
select substring(s, -2, -2) from t;
|
||||
select substring(s, l, -2) from t;
|
||||
select substring(s, -2, r) from t;
|
||||
select substring(s, l, r) from t;
|
||||
|
||||
drop table if exists t;
|
Loading…
Reference in New Issue
Block a user