mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-22 07:50:38 +00:00
* chore: update datafusion to 50 Signed-off-by: luofucong <luofc@foxmail.com> * fix ci Signed-off-by: luofucong <luofc@foxmail.com> * fix: update datafusion_pg_catalog import * chore: fix toml format * chore: fix toml format again * fix nextest Signed-off-by: luofucong <luofc@foxmail.com> * fix sqlness Signed-off-by: luofucong <luofc@foxmail.com> * chore: switch datafusion-orc to upstream tag * fix sqlness Signed-off-by: luofucong <luofc@foxmail.com> * resolve PR comments Signed-off-by: luofucong <luofc@foxmail.com> --------- Signed-off-by: luofucong <luofc@foxmail.com> Co-authored-by: Ning Sun <sunning@greptime.com>
100 lines
2.0 KiB
Plaintext
100 lines
2.0 KiB
Plaintext
-- Migrated from DuckDB test: test/sql/aggregate/aggregates/test_corr.test
|
|
-- Test CORR operator (correlation coefficient)
|
|
-- Corner cases
|
|
SELECT corr(NULL,NULL);
|
|
|
|
+-----------------+
|
|
| corr(NULL,NULL) |
|
|
+-----------------+
|
|
| |
|
|
+-----------------+
|
|
|
|
-- Single value returns NULL
|
|
SELECT corr(1,1);
|
|
|
|
+-------------------------+
|
|
| corr(Int64(1),Int64(1)) |
|
|
+-------------------------+
|
|
| |
|
|
+-------------------------+
|
|
|
|
-- Test with table
|
|
CREATE TABLE aggr(k INT, v DECIMAL(10,2), v2 DECIMAL(10, 2), ts TIMESTAMP TIME INDEX);
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO aggr VALUES
|
|
(1, 10, null, 1000),
|
|
(2, 10, 11, 2000),
|
|
(2, 20, 22, 3000),
|
|
(2, 25, null, 4000),
|
|
(2, 30, 35, 5000);
|
|
|
|
Affected Rows: 5
|
|
|
|
SELECT k, corr(v, v2) FROM aggr GROUP BY k ORDER BY k;
|
|
|
|
+---+----------------------+
|
|
| k | corr(aggr.v,aggr.v2) |
|
|
+---+----------------------+
|
|
| 1 | |
|
|
| 2 | 0.9988445981121536 |
|
|
+---+----------------------+
|
|
|
|
SELECT corr(v, v2) FROM aggr;
|
|
|
|
+----------------------+
|
|
| corr(aggr.v,aggr.v2) |
|
|
+----------------------+
|
|
| 0.9988445981121532 |
|
|
+----------------------+
|
|
|
|
-- Test with integer values
|
|
CREATE TABLE corr_test(x INTEGER, y INTEGER, ts TIMESTAMP TIME INDEX);
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO corr_test VALUES
|
|
(1, 2, 1000),
|
|
(2, 4, 2000),
|
|
(3, 6, 3000),
|
|
(4, 8, 4000),
|
|
(5, 10, 5000);
|
|
|
|
Affected Rows: 5
|
|
|
|
-- Perfect positive correlation
|
|
SELECT corr(x, y) FROM corr_test;
|
|
|
|
+-------------------------------+
|
|
| corr(corr_test.x,corr_test.y) |
|
|
+-------------------------------+
|
|
| 0.9999999999999999 |
|
|
+-------------------------------+
|
|
|
|
-- Test with negative correlation
|
|
INSERT INTO corr_test VALUES
|
|
(6, 5, 6000),
|
|
(7, 3, 7000),
|
|
(8, 1, 8000);
|
|
|
|
Affected Rows: 3
|
|
|
|
SELECT corr(x, y) FROM corr_test;
|
|
|
|
+-------------------------------+
|
|
| corr(corr_test.x,corr_test.y) |
|
|
+-------------------------------+
|
|
| -0.12452312927991684 |
|
|
+-------------------------------+
|
|
|
|
-- cleanup
|
|
DROP TABLE aggr;
|
|
|
|
Affected Rows: 0
|
|
|
|
DROP TABLE corr_test;
|
|
|
|
Affected Rows: 0
|
|
|