Skip to content

Commit

Permalink
test: reduce round precision to avoid platform diff (#5013)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhenchi <[email protected]>
  • Loading branch information
zhongzc authored Nov 18, 2024
1 parent 4402f63 commit 73e6bf3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/common/function/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ s2 = { version = "0.0.12", optional = true }
serde.workspace = true
serde_json.workspace = true
session.workspace = true
simsimd = "4"
simsimd = "6"
snafu.workspace = true
sql.workspace = true
statrs = "0.16"
Expand Down
66 changes: 33 additions & 33 deletions tests/cases/standalone/common/types/vector/vector.result
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ SELECT * FROM t;
| 1970-01-01 00:00:00.003000 | "[7,8,9]" |
+----------------------------+-----------+

SELECT round(cos_distance(v, '[0.0, 0.0, 0.0]'), 4) FROM t;
SELECT round(cos_distance(v, '[0.0, 0.0, 0.0]'), 2) FROM t;

+-----------------------------------------------------------+
| round(cos_distance(t.v,Utf8("[0.0, 0.0, 0.0]")),Int64(4)) |
| round(cos_distance(t.v,Utf8("[0.0, 0.0, 0.0]")),Int64(2)) |
+-----------------------------------------------------------+
| 1.0 |
| 1.0 |
| 1.0 |
+-----------------------------------------------------------+

SELECT *, round(cos_distance(v, '[0.0, 0.0, 0.0]'), 4) as d FROM t ORDER BY d;
SELECT *, round(cos_distance(v, '[0.0, 0.0, 0.0]'), 2) as d FROM t ORDER BY d;

+-------------------------+--------------------------+-----+
| ts | v | d |
Expand All @@ -51,30 +51,30 @@ SELECT *, round(cos_distance(v, '[0.0, 0.0, 0.0]'), 4) as d FROM t ORDER BY d;
| 1970-01-01T00:00:00.003 | 0000e0400000004100001041 | 1.0 |
+-------------------------+--------------------------+-----+

SELECT round(cos_distance('[7.0, 8.0, 9.0]', v), 4) FROM t;
SELECT round(cos_distance('[7.0, 8.0, 9.0]', v), 2) FROM t;

+-----------------------------------------------------------+
| round(cos_distance(Utf8("[7.0, 8.0, 9.0]"),t.v),Int64(4)) |
| round(cos_distance(Utf8("[7.0, 8.0, 9.0]"),t.v),Int64(2)) |
+-----------------------------------------------------------+
| 0.0406 |
| 0.0018 |
| 0.04 |
| 0.0 |
| 0.0 |
+-----------------------------------------------------------+

SELECT *, round(cos_distance('[7.0, 8.0, 9.0]', v), 4) as d FROM t ORDER BY d;
SELECT *, round(cos_distance('[7.0, 8.0, 9.0]', v), 2) as d FROM t ORDER BY d;

+-------------------------+--------------------------+--------+
| ts | v | d |
+-------------------------+--------------------------+--------+
| 1970-01-01T00:00:00.003 | 0000e0400000004100001041 | 0.0 |
| 1970-01-01T00:00:00.002 | 000080400000a0400000c040 | 0.0018 |
| 1970-01-01T00:00:00.001 | 0000803f0000004000004040 | 0.0406 |
+-------------------------+--------------------------+--------+
+-------------------------+--------------------------+------+
| ts | v | d |
+-------------------------+--------------------------+------+
| 1970-01-01T00:00:00.002 | 000080400000a0400000c040 | 0.0 |
| 1970-01-01T00:00:00.003 | 0000e0400000004100001041 | 0.0 |
| 1970-01-01T00:00:00.001 | 0000803f0000004000004040 | 0.04 |
+-------------------------+--------------------------+------+

SELECT round(cos_distance(v, v), 4) FROM t;
SELECT round(cos_distance(v, v), 2) FROM t;

+---------------------------------------+
| round(cos_distance(t.v,t.v),Int64(4)) |
| round(cos_distance(t.v,t.v),Int64(2)) |
+---------------------------------------+
| 0.0 |
| 0.0 |
Expand All @@ -91,17 +91,17 @@ SELECT cos_distance(v, 1.0) FROM t;

Error: 3001(EngineExecuteQuery), Invalid argument error: Encountered non UTF-8 data: invalid utf-8 sequence of 1 bytes from index 2

SELECT round(l2sq_distance(v, '[0.0, 0.0, 0.0]'), 4) FROM t;
SELECT round(l2sq_distance(v, '[0.0, 0.0, 0.0]'), 2) FROM t;

+------------------------------------------------------------+
| round(l2sq_distance(t.v,Utf8("[0.0, 0.0, 0.0]")),Int64(4)) |
| round(l2sq_distance(t.v,Utf8("[0.0, 0.0, 0.0]")),Int64(2)) |
+------------------------------------------------------------+
| 14.0 |
| 77.0 |
| 194.0 |
+------------------------------------------------------------+

SELECT *, round(l2sq_distance(v, '[0.0, 0.0, 0.0]'), 4) as d FROM t ORDER BY d;
SELECT *, round(l2sq_distance(v, '[0.0, 0.0, 0.0]'), 2) as d FROM t ORDER BY d;

+-------------------------+--------------------------+-------+
| ts | v | d |
Expand All @@ -111,17 +111,17 @@ SELECT *, round(l2sq_distance(v, '[0.0, 0.0, 0.0]'), 4) as d FROM t ORDER BY d;
| 1970-01-01T00:00:00.003 | 0000e0400000004100001041 | 194.0 |
+-------------------------+--------------------------+-------+

SELECT round(l2sq_distance('[7.0, 8.0, 9.0]', v), 4) FROM t;
SELECT round(l2sq_distance('[7.0, 8.0, 9.0]', v), 2) FROM t;

+------------------------------------------------------------+
| round(l2sq_distance(Utf8("[7.0, 8.0, 9.0]"),t.v),Int64(4)) |
| round(l2sq_distance(Utf8("[7.0, 8.0, 9.0]"),t.v),Int64(2)) |
+------------------------------------------------------------+
| 108.0 |
| 27.0 |
| 0.0 |
+------------------------------------------------------------+

SELECT *, round(l2sq_distance('[7.0, 8.0, 9.0]', v), 4) as d FROM t ORDER BY d;
SELECT *, round(l2sq_distance('[7.0, 8.0, 9.0]', v), 2) as d FROM t ORDER BY d;

+-------------------------+--------------------------+-------+
| ts | v | d |
Expand All @@ -131,10 +131,10 @@ SELECT *, round(l2sq_distance('[7.0, 8.0, 9.0]', v), 4) as d FROM t ORDER BY d;
| 1970-01-01T00:00:00.001 | 0000803f0000004000004040 | 108.0 |
+-------------------------+--------------------------+-------+

SELECT round(l2sq_distance(v, v), 4) FROM t;
SELECT round(l2sq_distance(v, v), 2) FROM t;

+----------------------------------------+
| round(l2sq_distance(t.v,t.v),Int64(4)) |
| round(l2sq_distance(t.v,t.v),Int64(2)) |
+----------------------------------------+
| 0.0 |
| 0.0 |
Expand All @@ -151,17 +151,17 @@ SELECT l2sq_distance(v, 1.0) FROM t;

Error: 3001(EngineExecuteQuery), Invalid argument error: Encountered non UTF-8 data: invalid utf-8 sequence of 1 bytes from index 2

SELECT round(dot_product(v, '[0.0, 0.0, 0.0]'), 4) FROM t;
SELECT round(dot_product(v, '[0.0, 0.0, 0.0]'), 2) FROM t;

+----------------------------------------------------------+
| round(dot_product(t.v,Utf8("[0.0, 0.0, 0.0]")),Int64(4)) |
| round(dot_product(t.v,Utf8("[0.0, 0.0, 0.0]")),Int64(2)) |
+----------------------------------------------------------+
| 0.0 |
| 0.0 |
| 0.0 |
+----------------------------------------------------------+

SELECT *, round(dot_product(v, '[0.0, 0.0, 0.0]'), 4) as d FROM t ORDER BY d;
SELECT *, round(dot_product(v, '[0.0, 0.0, 0.0]'), 2) as d FROM t ORDER BY d;

+-------------------------+--------------------------+-----+
| ts | v | d |
Expand All @@ -171,17 +171,17 @@ SELECT *, round(dot_product(v, '[0.0, 0.0, 0.0]'), 4) as d FROM t ORDER BY d;
| 1970-01-01T00:00:00.003 | 0000e0400000004100001041 | 0.0 |
+-------------------------+--------------------------+-----+

SELECT round(dot_product('[7.0, 8.0, 9.0]', v), 4) FROM t;
SELECT round(dot_product('[7.0, 8.0, 9.0]', v), 2) FROM t;

+----------------------------------------------------------+
| round(dot_product(Utf8("[7.0, 8.0, 9.0]"),t.v),Int64(4)) |
| round(dot_product(Utf8("[7.0, 8.0, 9.0]"),t.v),Int64(2)) |
+----------------------------------------------------------+
| 50.0 |
| 122.0 |
| 194.0 |
+----------------------------------------------------------+

SELECT *, round(dot_product('[7.0, 8.0, 9.0]', v), 4) as d FROM t ORDER BY d;
SELECT *, round(dot_product('[7.0, 8.0, 9.0]', v), 2) as d FROM t ORDER BY d;

+-------------------------+--------------------------+-------+
| ts | v | d |
Expand All @@ -191,10 +191,10 @@ SELECT *, round(dot_product('[7.0, 8.0, 9.0]', v), 4) as d FROM t ORDER BY d;
| 1970-01-01T00:00:00.003 | 0000e0400000004100001041 | 194.0 |
+-------------------------+--------------------------+-------+

SELECT round(dot_product(v, v), 4) FROM t;
SELECT round(dot_product(v, v), 2) FROM t;

+--------------------------------------+
| round(dot_product(t.v,t.v),Int64(4)) |
| round(dot_product(t.v,t.v),Int64(2)) |
+--------------------------------------+
| 14.0 |
| 77.0 |
Expand Down
30 changes: 15 additions & 15 deletions tests/cases/standalone/common/types/vector/vector.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ SELECT * FROM t;
-- SQLNESS PROTOCOL POSTGRES
SELECT * FROM t;

SELECT round(cos_distance(v, '[0.0, 0.0, 0.0]'), 4) FROM t;
SELECT round(cos_distance(v, '[0.0, 0.0, 0.0]'), 2) FROM t;

SELECT *, round(cos_distance(v, '[0.0, 0.0, 0.0]'), 4) as d FROM t ORDER BY d;
SELECT *, round(cos_distance(v, '[0.0, 0.0, 0.0]'), 2) as d FROM t ORDER BY d;

SELECT round(cos_distance('[7.0, 8.0, 9.0]', v), 4) FROM t;
SELECT round(cos_distance('[7.0, 8.0, 9.0]', v), 2) FROM t;

SELECT *, round(cos_distance('[7.0, 8.0, 9.0]', v), 4) as d FROM t ORDER BY d;
SELECT *, round(cos_distance('[7.0, 8.0, 9.0]', v), 2) as d FROM t ORDER BY d;

SELECT round(cos_distance(v, v), 4) FROM t;
SELECT round(cos_distance(v, v), 2) FROM t;

-- Unexpected dimension --
SELECT cos_distance(v, '[1.0]') FROM t;

-- Invalid type --
SELECT cos_distance(v, 1.0) FROM t;

SELECT round(l2sq_distance(v, '[0.0, 0.0, 0.0]'), 4) FROM t;
SELECT round(l2sq_distance(v, '[0.0, 0.0, 0.0]'), 2) FROM t;

SELECT *, round(l2sq_distance(v, '[0.0, 0.0, 0.0]'), 4) as d FROM t ORDER BY d;
SELECT *, round(l2sq_distance(v, '[0.0, 0.0, 0.0]'), 2) as d FROM t ORDER BY d;

SELECT round(l2sq_distance('[7.0, 8.0, 9.0]', v), 4) FROM t;
SELECT round(l2sq_distance('[7.0, 8.0, 9.0]', v), 2) FROM t;

SELECT *, round(l2sq_distance('[7.0, 8.0, 9.0]', v), 4) as d FROM t ORDER BY d;
SELECT *, round(l2sq_distance('[7.0, 8.0, 9.0]', v), 2) as d FROM t ORDER BY d;

SELECT round(l2sq_distance(v, v), 4) FROM t;
SELECT round(l2sq_distance(v, v), 2) FROM t;

-- Unexpected dimension --
SELECT l2sq_distance(v, '[1.0]') FROM t;
Expand All @@ -44,15 +44,15 @@ SELECT l2sq_distance(v, '[1.0]') FROM t;
SELECT l2sq_distance(v, 1.0) FROM t;


SELECT round(dot_product(v, '[0.0, 0.0, 0.0]'), 4) FROM t;
SELECT round(dot_product(v, '[0.0, 0.0, 0.0]'), 2) FROM t;

SELECT *, round(dot_product(v, '[0.0, 0.0, 0.0]'), 4) as d FROM t ORDER BY d;
SELECT *, round(dot_product(v, '[0.0, 0.0, 0.0]'), 2) as d FROM t ORDER BY d;

SELECT round(dot_product('[7.0, 8.0, 9.0]', v), 4) FROM t;
SELECT round(dot_product('[7.0, 8.0, 9.0]', v), 2) FROM t;

SELECT *, round(dot_product('[7.0, 8.0, 9.0]', v), 4) as d FROM t ORDER BY d;
SELECT *, round(dot_product('[7.0, 8.0, 9.0]', v), 2) as d FROM t ORDER BY d;

SELECT round(dot_product(v, v), 4) FROM t;
SELECT round(dot_product(v, v), 2) FROM t;

-- Unexpected dimension --
SELECT dot_product(v, '[1.0]') FROM t;
Expand Down

0 comments on commit 73e6bf3

Please sign in to comment.