Files
greptimedb/tests/cases/standalone/common/aggregate/corr.sql
LFC 2f637a262e chore: update datafusion to 50 (#7076)
* 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>
2025-10-23 07:18:36 +00:00

49 lines
1.0 KiB
SQL

-- Migrated from DuckDB test: test/sql/aggregate/aggregates/test_corr.test
-- Test CORR operator (correlation coefficient)
-- Corner cases
SELECT corr(NULL,NULL);
-- Single value returns NULL
SELECT corr(1,1);
-- Test with table
CREATE TABLE aggr(k INT, v DECIMAL(10,2), v2 DECIMAL(10, 2), ts TIMESTAMP TIME INDEX);
INSERT INTO aggr VALUES
(1, 10, null, 1000),
(2, 10, 11, 2000),
(2, 20, 22, 3000),
(2, 25, null, 4000),
(2, 30, 35, 5000);
SELECT k, corr(v, v2) FROM aggr GROUP BY k ORDER BY k;
SELECT corr(v, v2) FROM aggr;
-- Test with integer values
CREATE TABLE corr_test(x INTEGER, y INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO corr_test VALUES
(1, 2, 1000),
(2, 4, 2000),
(3, 6, 3000),
(4, 8, 4000),
(5, 10, 5000);
-- Perfect positive correlation
SELECT corr(x, y) FROM corr_test;
-- Test with negative correlation
INSERT INTO corr_test VALUES
(6, 5, 6000),
(7, 3, 7000),
(8, 1, 8000);
SELECT corr(x, y) FROM corr_test;
-- cleanup
DROP TABLE aggr;
DROP TABLE corr_test;