should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,96 @@
# name: test/sql/function/blob/base64.test
# description: Test blob base64 functions
# group: [blob]
statement ok
PRAGMA enable_verification
# test base64 encoding
query I
SELECT base64(encode(''))
----
(empty)
query I
SELECT base64(encode('a'))
----
YQ==
query I
SELECT base64(encode('ab'))
----
YWI=
query I
SELECT base64(encode('abc'))
----
YWJj
query I
SELECT base64(encode('üäabcdef'))
----
w7zDpGFiY2RlZg==
query I
SELECT base64(encode('iJWERiuhjruhwuiehr8493231'))
----
aUpXRVJpdWhqcnVod3VpZWhyODQ5MzIzMQ==
query I
SELECT base64(encode('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'))
----
YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1Njc4OTA=
query I
SELECT to_base64(encode('base64 encoded string'));
----
YmFzZTY0IGVuY29kZWQgc3RyaW5n
# test base64 decoding round-trip
query I
SELECT from_base64(base64(encode('')))
----
(empty)
query I
SELECT from_base64(base64(encode('a')))
----
a
query I
SELECT from_base64(base64(encode('ab')))
----
ab
query I
SELECT from_base64(base64(encode('abc')))
----
abc
query I
SELECT from_base64(base64(encode('iJWERiuhjruhwuiehr8493231')))
----
iJWERiuhjruhwuiehr8493231
query I
SELECT from_base64(base64(encode('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')))
----
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
query I
select from_base64('AAAA');
----
\x00\x00\x00
# malformed base64
# must be multiple of 4
statement error
SELECT from_base64('ab');
----
<REGEX>:.*Conversion Error: Could not decode string.*
# unknown bytes
statement error
SELECT from_base64('üab');
----
<REGEX>:.*Conversion Error: Could not decode string.*

View File

@@ -0,0 +1,351 @@
# name: test/sql/function/blob/create_sort_key.test
# description: Test create_sort_key function
# group: [blob]
statement ok
PRAGMA enable_verification
# test integer types with all modifiers
statement ok
CREATE TABLE integers(i INTEGER);
statement ok
INSERT INTO integers VALUES (1), (2), (3), (NULL)
query I
SELECT * FROM integers ORDER BY create_sort_key(i, 'ASC NULLS LAST')
----
1
2
3
NULL
query I
SELECT * FROM integers ORDER BY create_sort_key(i, 'ASC NULLS FIRST')
----
NULL
1
2
3
query I
SELECT * FROM integers ORDER BY create_sort_key(i, 'DESC NULLS LAST')
----
3
2
1
NULL
query I
SELECT * FROM integers ORDER BY create_sort_key(i, 'DESC NULLS FIRST')
----
NULL
3
2
1
# test varchar types
statement ok
CREATE TABLE varchars(v VARCHAR);
statement ok
INSERT INTO varchars VALUES ('hello'), ('hello' || chr(0) || chr(0)), ('world'), (''), (NULL)
query I
SELECT * FROM varchars ORDER BY create_sort_key(v, 'ASC NULLS LAST')
----
(empty)
hello
hello\0\0
world
NULL
query I
SELECT * FROM varchars ORDER BY create_sort_key(v, 'ASC NULLS FIRST')
----
NULL
(empty)
hello
hello\0\0
world
query I
SELECT * FROM varchars ORDER BY create_sort_key(v, 'DESC NULLS LAST')
----
world
hello\0\0
hello
(empty)
NULL
query I
SELECT * FROM varchars ORDER BY create_sort_key(v, 'DESC NULLS FIRST')
----
NULL
world
hello\0\0
hello
(empty)
# test list types
statement ok
CREATE TABLE int_list(l INT[]);
statement ok
INSERT INTO int_list VALUES ([1, 2, 3]), ([]), ([1]), ([2]), ([NULL]), (NULL);
query I
SELECT l FROM int_list ORDER BY create_sort_key(l, 'ASC NULLS LAST')
----
[]
[1]
[1, 2, 3]
[2]
[NULL]
NULL
query I
SELECT l FROM int_list ORDER BY create_sort_key(l, 'DESC NULLS LAST')
----
[NULL]
[2]
[1, 2, 3]
[1]
[]
NULL
query I
SELECT l FROM int_list ORDER BY create_sort_key(l, 'ASC NULLS FIRST')
----
NULL
[]
[1]
[1, 2, 3]
[2]
[NULL]
query I
SELECT l FROM int_list ORDER BY create_sort_key(l, 'DESC NULLS FIRST')
----
NULL
[NULL]
[2]
[1, 2, 3]
[1]
[]
# test struct types
statement ok
CREATE TABLE structs(s ROW(i INT, v VARCHAR));
statement ok
INSERT INTO structs VALUES ({'i': 42, v: 'hello'}), ({'i': 42, v: 'hello' || chr(0)}), ({'i': 43, v: ''}), (NULL), ({'i': 42, v: NULL}), ({'i': NULL, v: ''})
query I
SELECT * FROM structs ORDER BY create_sort_key(s, 'ASC NULLS LAST')
----
{'i': 42, 'v': hello}
{'i': 42, 'v': hello\0}
{'i': 42, 'v': NULL}
{'i': 43, 'v': ''}
{'i': NULL, 'v': ''}
NULL
query II
SELECT s.i, s.v FROM structs ORDER BY create_sort_key(s.i, 'ASC NULLS LAST', s.v, 'ASC NULLS LAST')
----
42 hello
42 hello\0
42 NULL
43 (empty)
NULL (empty)
NULL NULL
query I
SELECT * FROM structs ORDER BY create_sort_key(s, 'DESC NULLS FIRST')
----
NULL
{'i': NULL, 'v': ''}
{'i': 43, 'v': ''}
{'i': 42, 'v': NULL}
{'i': 42, 'v': hello\0}
{'i': 42, 'v': hello}
query II
SELECT s.i, s.v FROM structs ORDER BY create_sort_key(s.i, 'DESC NULLS FIRST', s.v, 'DESC NULLS FIRST')
----
NULL NULL
NULL (empty)
43 (empty)
42 NULL
42 hello\0
42 hello
# test struct types
statement ok
CREATE TABLE list_of_structs(s ROW(i INT, v VARCHAR)[]);
statement ok
INSERT INTO list_of_structs VALUES
([{'i': 42, v: 'hello'}]),
([]),
([{'i': 42, v: 'hello'}, {'i': 84, v: ''}]),
([{'i': 43, v: ''}]),
(NULL),
([NULL]),
([{'i': 42, v: NULL}]),
([{'i': NULL, v: ''}]),
([{'i': 42, v: 'hello'}, {'i': 84, v: chr(0)}]),
([{'i': 42, v: 'hello'}, NULL, {'i': 84, v: ''}])
query I
SELECT * FROM list_of_structs ORDER BY create_sort_key(s, 'ASC NULLS LAST')
----
[]
[{'i': 42, 'v': hello}]
[{'i': 42, 'v': hello}, {'i': 84, 'v': ''}]
[{'i': 42, 'v': hello}, {'i': 84, 'v': \0}]
[{'i': 42, 'v': hello}, NULL, {'i': 84, 'v': ''}]
[{'i': 42, 'v': NULL}]
[{'i': 43, 'v': ''}]
[{'i': NULL, 'v': ''}]
[NULL]
NULL
query I
SELECT * FROM list_of_structs ORDER BY create_sort_key(s, 'DESC NULLS FIRST')
----
NULL
[NULL]
[{'i': NULL, 'v': ''}]
[{'i': 43, 'v': ''}]
[{'i': 42, 'v': NULL}]
[{'i': 42, 'v': hello}, NULL, {'i': 84, 'v': ''}]
[{'i': 42, 'v': hello}, {'i': 84, 'v': \0}]
[{'i': 42, 'v': hello}, {'i': 84, 'v': ''}]
[{'i': 42, 'v': hello}]
[]
# test nested lists
statement ok
CREATE TABLE nested_lists(s INT[][]);
statement ok
INSERT INTO nested_lists VALUES
([]),
([[], []]),
(NULL),
([NULL]),
([[NULL]]),
([[42, 84]]),
([[42], [84]]),
([[42], NULL, [84]]),
([[42], [NULL], [84]]),
([[1, 2, 3, 4, 5, 6, 7, 8, 9]])
query I
SELECT * FROM nested_lists ORDER BY create_sort_key(s, 'ASC NULLS LAST')
----
[]
[[], []]
[[1, 2, 3, 4, 5, 6, 7, 8, 9]]
[[42], [84]]
[[42], [NULL], [84]]
[[42], NULL, [84]]
[[42, 84]]
[[NULL]]
[NULL]
NULL
query I
SELECT * FROM nested_lists ORDER BY create_sort_key(s, 'DESC NULLS FIRST')
----
NULL
[NULL]
[[NULL]]
[[42, 84]]
[[42], NULL, [84]]
[[42], [NULL], [84]]
[[42], [84]]
[[1, 2, 3, 4, 5, 6, 7, 8, 9]]
[[], []]
[]
# test blobs
statement ok
CREATE TABLE blobs(b BLOB, c BLOB);
statement ok
INSERT INTO blobs VALUES (NULL, NULL), ('hello\x00\x00\x00\x00\x00', NULL), ('hello', 'world'), ('hello\x01\x01\x01', 'world'), ('', ''), ('hello\x00\x00\x00\x00\x00', 'world'), ('hello\x00', NULL)
query I
SELECT b FROM blobs ORDER BY create_sort_key(b, 'ASC NULLS LAST')
----
(empty)
hello
hello\x00
hello\x00\x00\x00\x00\x00
hello\x00\x00\x00\x00\x00
hello\x01\x01\x01
NULL
query I
SELECT b FROM blobs ORDER BY create_sort_key(b, 'DESC NULLS FIRST')
----
NULL
hello\x01\x01\x01
hello\x00\x00\x00\x00\x00
hello\x00\x00\x00\x00\x00
hello\x00
hello
(empty)
query II
SELECT * FROM blobs ORDER BY create_sort_key(b, 'ASC NULLS LAST', c, 'ASC NULLS LAST')
----
(empty) (empty)
hello world
hello\x00 NULL
hello\x00\x00\x00\x00\x00 world
hello\x00\x00\x00\x00\x00 NULL
hello\x01\x01\x01 world
NULL NULL
query II
SELECT * FROM blobs ORDER BY create_sort_key(b, 'DESC NULLS FIRST', c, 'DESC NULLS FIRST')
----
NULL NULL
hello\x01\x01\x01 world
hello\x00\x00\x00\x00\x00 NULL
hello\x00\x00\x00\x00\x00 world
hello\x00 NULL
hello world
(empty) (empty)
# test array type
statement ok
CREATE TABLE arrays(l INT[3]);
statement ok
INSERT INTO arrays VALUES ([1, 2, 3]), (NULL), ([NULL, NULL, NULL]), ([1, NULL, 3]), ([2, 3, 4]);
query I
SELECT l FROM arrays ORDER BY create_sort_key(l, 'ASC NULLS LAST')
----
[1, 2, 3]
[1, NULL, 3]
[2, 3, 4]
[NULL, NULL, NULL]
NULL
query I
SELECT l FROM arrays ORDER BY create_sort_key(l, 'DESC NULLS FIRST')
----
NULL
[NULL, NULL, NULL]
[2, 3, 4]
[1, NULL, 3]
[1, 2, 3]

View File

@@ -0,0 +1,41 @@
# name: test/sql/function/blob/encode.test
# description: Test blob encode/decode functions
# group: [blob]
statement ok
PRAGMA enable_verification
# test basic encode/decode usage
query I
SELECT encode('ü')
----
\xC3\xBC
query I
SELECT decode(encode('ü'))
----
ü
query I
SELECT decode('\xF0\x9F\xA6\x86'::BLOB)
----
🦆
# null byte
query I
SELECT decode('\x00'::BLOB)
----
\0
# test invalid decodes
statement error
SELECT decode('\xFF'::BLOB)
----
query I
SELECT decode(encode(a)) || a from (values ('hello'), ('world')) tbl(a);
----
hellohello
worldworld

View File

@@ -0,0 +1,71 @@
# name: test/sql/function/blob/test_blob_array_slice.test
# description: Blob slicing test
# group: [blob]
statement ok
PRAGMA enable_verification
query I
select array_slice(blob '\x00\x01\x02\x03\x04\x05', 2, 4)
----
\x01\x02\x03
# zero-offset works fine, too
query I
select array_slice(blob '\x00\x01\x02\x03\x04\x05', 0, 2)
----
\x00\x01
# other syntax works, too
query I
select (blob '\x00\x01\x02\x03\x04\x05'::BLOB)[2:4]
----
\x01\x02\x03
# we can have offsets bigger than length
query I
select array_slice(blob '\x00\x01\x02\x03\x04\x05', 4, 10)
----
\x03\x04\x05
# nonsensical offsets lead to empty BLOB
query I
select octet_length(array_slice(blob '\x00\x01\x02\x03\x04\x05', 4, 3))
----
0
# we can have negative offsets from back, this is somehow consistent with strings
query I
select array_slice(blob '\x00\x01\x02\x03\x04\x05', 2,-2)
----
\x01\x02\x03\x04
# both can be negative
# we can have negative offsets from back, this is somehow consistent with strings
query I
select array_slice(blob '\x00\x01\x02\x03\x04\x05', -4, -2)
----
\x02\x03\x04
# we can subset utf characters when they're blobs
query I
select array_slice(blob '\x00\xF0\x9F\xA6\x86\x00', 2, 3)
----
\xF0\x9F
# we can subset utf characters when they're blobs
query I
select array_slice(blob '\x00\xF0\x9F\xA6\x86\x00', 4, 6)
----
\xA6\x86\x00
# we can slice blob NULL
query I
select array_slice(NULL::BLOB, 4, 6)
----
NULL
statement error
select array_slice('hello world', 1, 8, 2);
----
Slice with steps has not been implemented for string types

View File

@@ -0,0 +1,28 @@
# name: test/sql/function/blob/test_concat_blob.test
# description: Test concat of blobs function
# group: [blob]
statement ok
PRAGMA enable_verification
# concat operator works with blobs
query I
SELECT blob 'aaa\x80' || blob 'aaa\x80'
----
aaa\x80aaa\x80
query I
SELECT typeof(blob 'aaa\x80' || blob 'aaa\x80')
----
BLOB
# concat function works - but it converts to varchar
query I
SELECT concat(blob 'aaa\x80', blob 'aaa\x80')
----
aaa\x80aaa\x80
query I
SELECT typeof(concat(blob 'aaa\x80', blob 'aaa\x80'))
----
VARCHAR