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,20 @@
# name: test/sql/function/array/array_and_map.test
# description: Test flattening ARRAY types inside the MAP function.
# group: [array]
query I
SELECT MAP([MAP([ARRAY_VALUE('1', NULL), ARRAY_VALUE(NULL, '2')], [1, 2])], [1]);
----
{{[1, NULL]=1, [NULL, 2]=2}=1}
query I
SELECT MAP([2], [{'key1': MAP([ARRAY_VALUE('1', NULL), ARRAY_VALUE(NULL, '2')], [1, 2])}]);
----
{2={'key1': {[1, NULL]=1, [NULL, 2]=2}}}
# Issue https://github.com/duckdb/duckdb/issues/12007.
query I
SELECT [MAP([2], [{'key1': MAP([ARRAY_VALUE('1', NULL), ARRAY_VALUE(NULL, '2')], [1, 2]), 'key2': 2}])];
----
[{2={'key1': {[1, NULL]=1, [NULL, 2]=2}, 'key2': 2}}]

View File

@@ -0,0 +1,50 @@
# name: test/sql/function/array/array_cosine_distance.test
# group: [array]
foreach type FLOAT DOUBLE
# The distance between a vector and itself should be 0
query I
SELECT array_cosine_distance([1, 2, 3]::${type}[3], [1, 2, 3]::${type}[3]);
----
0.0
# Opposite vectors should have a distance of 2
query I
SELECT array_cosine_distance([2, 2, 2]::${type}[3], [-2, -2, -2]::${type}[3]);
----
2.0
statement ok
CREATE OR REPLACE TABLE arrays (l ${type}[3]);
statement ok
INSERT INTO arrays VALUES ([1, 2, 3]), ([4, 5, 6]), ([7, 8, 9]), ([-1, -2, -3]), (NULL);
query I
SELECT array_cosine_distance(l, [1, 2, 3]::${type}[3]) FROM arrays;
----
0.0
0.02536815
0.04058805
2.0
NULL
statement error
SELECT array_cosine_distance([1, NULL, 3]::${type}[3], [1, 2, 3]::${type}[3]);
----
left argument can not contain NULL values
statement error
SELECT array_cosine_distance([1, 2, 3]::${type}[3], [1, NULL, 3]::${type}[3]);
----
right argument can not contain NULL values
statement error
SELECT array_cosine_distance([1, 2, 3]::${type}[3], [1, 2, 3, 4]::${type}[4]);
----
array_cosine_distance: Array arguments must be of the same size
endloop

View File

@@ -0,0 +1,43 @@
# name: test/sql/function/array/array_cosine_similarity.test
# group: [array]
foreach type FLOAT DOUBLE
query I
SELECT array_cosine_similarity([1, 2, 3]::${type}[3], [1, 2, 3]::${type}[3]);
----
1.0
statement ok
CREATE OR REPLACE TABLE arrays (l ${type}[3]);
statement ok
INSERT INTO arrays VALUES ([1, 2, 3]), ([4, 5, 6]), ([7, 8, 9]), ([-1, -2, -3]), (NULL);
query I
SELECT array_cosine_similarity(l, [1, 2, 3]::${type}[3]) FROM arrays;
----
0.99999994
0.9746318
0.95941186
-0.99999994
NULL
statement error
SELECT array_cosine_similarity([1, NULL, 3]::${type}[3], [1, 2, 3]::${type}[3]);
----
left argument can not contain NULL values
statement error
SELECT array_cosine_similarity([1, 2, 3]::${type}[3], [1, NULL, 3]::${type}[3]);
----
right argument can not contain NULL values
statement error
SELECT array_cosine_similarity([1, 2, 3]::${type}[3], [1, 2, 3, 4]::${type}[4]);
----
array_cosine_similarity: Array arguments must be of the same size
endloop

View File

@@ -0,0 +1,52 @@
# name: test/sql/function/array/array_cross_product.test
# group: [array]
# This tests the vector cross product
foreach TYPE DOUBLE FLOAT
query I rowsort
SELECT array_cross_product(l, r) FROM (VALUES
([-1, -2, 3]::${TYPE}[3], [4, 0, -8]::${TYPE}[3]),
([1,2,3]::${TYPE}[3], [1,5,7]::${TYPE}[3]),
([1,2,3]::${TYPE}[3], NULL::${TYPE}[3]),
(NULL::${TYPE}[3], [1,5,7]::${TYPE}[3]),
(NULL::${TYPE}[3], NULL::${TYPE}[3])
) as t(l,r);
----
NULL
NULL
NULL
[-1.0, -4.0, 3.0]
[16.0, 4.0, 8.0]
# Constant case
query I
SELECT array_cross_product([1,2,3]::${TYPE}[3], [1,5,7]::${TYPE}[3]);
----
[-1.0, -4.0, 3.0]
# Constant Null case
query I
SELECT array_cross_product([1,2,3]::${TYPE}[3], NULL::${TYPE}[3]);
----
NULL
statement error
SELECT array_cross_product([1,NULL,3]::${TYPE}[3], [1,5,7]::${TYPE}[3]);
----
array_cross_product: left argument can not contain NULL values
statement error
SELECT array_cross_product([1,5,7]::${TYPE}[3], [1,NULL,3]::${TYPE}[3]);
----
array_cross_product: right argument can not contain NULL values
# Now we can also try implict casts
query I
SELECT array_cross_product(array_value(1,2,3), array_value(1.0,5.0,7.0)::${TYPE}[3]);
----
[-1.0, -4.0, 3.0]
endloop

View File

@@ -0,0 +1,43 @@
# name: test/sql/function/array/array_distance.test
# group: [array]
foreach type FLOAT
query I
SELECT array_distance([1, 2, 3]::${type}[3], [1, 2, 3]::${type}[3]);
----
0.0
statement ok
CREATE OR REPLACE TABLE arrays (l ${type}[3]);
statement ok
INSERT INTO arrays VALUES ([1, 2, 3]), ([1, 2, 4]), ([7, 8, 9]), ([-1, -2, -3]), (NULL);
query I
SELECT array_distance(l, [1, 2, 3]::${type}[3]) FROM arrays;
----
0.0
1.0
10.392304
7.483315
NULL
statement error
SELECT array_distance([1, NULL, 3]::${type}[3], [1, 2, 3]::${type}[3]);
----
left argument can not contain NULL values
statement error
SELECT array_distance([1, 2, 3]::${type}[3], [1, NULL, 3]::${type}[3]);
----
right argument can not contain NULL values
statement error
SELECT array_distance([1, 2, 3]::${type}[3], [1, 2, 3, 4]::${type}[4]);
----
array_distance: Array arguments must be of the same size
endloop

View File

@@ -0,0 +1,13 @@
# name: test/sql/function/array/array_flatten.test
# description: Test array flatten function
# group: [array]
statement error
select flatten(['a', 'b', 'c']::varchar[3]);
----
No function matches the given name and argument types
query I
select flatten([['a'], ['b'], ['c']]::varchar[1][3]);
----
[a, b, c]

View File

@@ -0,0 +1,60 @@
# name: test/sql/function/array/array_inner_product.test
# group: [array]
# Error message coverage test
statement error
SELECT array_inner_product('foo', 'bar');
----
Could not choose a best candidate function
statement error
SELECT array_inner_product([1,2,3]::INT[3], ['a','b','c']::VARCHAR[3]);
----
Binder Error: No function matches the given name and argument types
statement error
SELECT array_distance(['a','b']::VARCHAR[2],['foo','bar']::VARCHAR[2]);
----
Binder Error: No function matches the given name and argument types
# Tests for supported types
foreach type FLOAT DOUBLE
query I
SELECT array_inner_product([1, 1, 1]::${type}[3], [1, 1, 1]::${type}[3]);
----
3.0
statement ok
CREATE OR REPLACE TABLE arrays (l ${type}[3]);
statement ok
INSERT INTO arrays VALUES ([1, 2, 3]), ([1, 2, 4]), ([7, 8, 9]), ([-1, -2, -3]), (NULL);
query I
SELECT array_inner_product(l, [1, 2, 3]::${type}[3]) FROM arrays;
----
14.0
17.0
50.0
-14.0
NULL
statement error
SELECT array_inner_product([1, NULL, 3]::${type}[3], [1, 2, 3]::${type}[3]);
----
left argument can not contain NULL values
statement error
SELECT array_inner_product([1, 2, 3]::${type}[3], [1, NULL, 3]::${type}[3]);
----
right argument can not contain NULL values
statement error
SELECT array_inner_product([1, 2, 3]::${type}[3], [1, 2, 3, 4]::${type}[4]);
----
array_inner_product: Array arguments must be of the same size
endloop

View File

@@ -0,0 +1,59 @@
# name: test/sql/function/array/array_length.test
# group: [array]
# Array length
query I
SELECT length(array_value(1, 2, 3));
----
3
# array length for NULL values
statement ok
create table arrays(a int[3]);
statement ok
insert into arrays values ([1, 2, 3]), ([4, 5, 6])
query I
select length(a) from arrays;
----
3
3
query I
select length(NULL::int[3]) from arrays;
----
NULL
NULL
statement ok
insert into arrays values (NULL);
query I
select length(a) from arrays;
----
3
3
NULL
# Array length with dimension argument
query I
SELECT array_length(array_value(array_value(1, 2, 2), array_value(3, 4, 3)), 1);
----
2
query I
SELECT array_length(array_value(array_value(1, 2, 2), array_value(3, 4, 3)), 2);
----
3
statement error
SELECT array_length(array_value(array_value(1, 2, 2), array_value(3, 4, 3)), 3);
----
Out of Range Error: array_length dimension '3' out of range (min: '1', max: '2')
statement error
SELECT array_length(array_value(array_value(1, 2, 2), array_value(3, 4, 3)), 0);
----
Out of Range Error: array_length dimension '0' out of range (min: '1', max: '2')

View File

@@ -0,0 +1,89 @@
# name: test/sql/function/array/array_list_functions.test
# group: [array]
# Just test that arrays are propely cast to lists when calling some list functions with special binding logic
# Aggregate example
query I
SELECT list_distinct(array_value(1,1,2,3,3)) = list_distinct([1,1,2,3,3]);
----
true
# Sort example:
query I
SELECT list_sort(array_value(3,2,1)) = list_sort([3,2,1]);
----
true
# Slice example:
query I
SELECT list_slice(array_value(1,2,3,4,5), 1, 3) = list_slice([1,2,3,4,5], 1, 3);
----
true
# Transform example
query I
SELECT list_transform(array_value(3,2,1), lambda x: x + 1) = list_transform([3,2,1], lambda x: x + 1);
----
true
# Filter example
query I
SELECT list_filter(array_value(3,2,1), lambda x: x > 1) = list_filter([3,2,1], lambda x: x > 1);
----
true
# Concat example(s)
query I
SELECT list_concat(array_value(1,2,3), array_value(4,5,6));
----
[1, 2, 3, 4, 5, 6]
query II
SELECT list_concat(array_value(1,2,3), NULL), list_concat(NULL, array_value(4,5,6));
----
[1, 2, 3] [4, 5, 6]
query I
SELECT list_resize(array_value(1,2), 3);
----
[1, 2, NULL]
query I
SELECT list_resize(array_value(1,2), 1);
----
[1]
query I
SELECT list_resize(array_value(1,2), 0);
----
[]
query I
SELECT list_position(array_value(1,2,3), 2);
----
2
query I
SELECT list_position(array_value(1,2,3), 4);
----
NULL
query I
SELECT list_contains(array_value(1,2,3), 2);
----
true
query I
SELECT list_contains(array_value(1,2,3), 4);
----
false
query I
SELECT list_extract(array_value(4,5,6), 2);
----
5
query I
SELECT list_extract(array_value(4,5,6), 4);
----
NULL