1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# name: test/sql/function/list/list_cosine_similarity.test
# group: [list]
foreach type FLOAT DOUBLE
query I
SELECT list_cosine_similarity([1, 2, 3]::${type}[], [1, 2, 3]::${type}[]);
----
1.0
statement ok
CREATE OR REPLACE TABLE lists (l ${type}[]);
statement ok
INSERT INTO lists VALUES ([1, 2, 3]), ([4, 5, 6]), ([7, 8, 9]), ([-1, -2, -3]), (NULL);
query I
SELECT list_cosine_similarity(l, [1, 2, 3]) FROM lists;
----
0.99999994
0.9746318
0.95941186
-0.99999994
NULL
statement error
SELECT list_cosine_similarity([1, NULL, 3]::${type}[], [1, 2, 3]::${type}[]);
----
left argument can not contain NULL values
statement error
SELECT list_cosine_similarity([1, 2, 3]::${type}[], [1, NULL, 3]::${type}[]);
----
right argument can not contain NULL values
statement error
SELECT list_cosine_similarity([1, 2, 3]::${type}[], [1, 2, 3, 4]::${type}[]);
----
list dimensions must be equal, got left length '3' and right length '4'
query I
SELECT list_cosine_similarity([], []);
----
NULL
query I
SELECT list_cosine_distance([1, 2, 3]::${type}[], [1, 2, 3]::${type}[]) = 1 - list_cosine_similarity([1, 2, 3]::${type}[], [1, 2, 3]::${type}[]);
----
true
endloop
|