-- Regression test for the NULL handling in the transition functions of the
-- trimmed aggregates.
--
-- Neither of the transition functions is strict, so NULL rows do reach them
-- and have to be ignored. Each function is exercised twice: once with all
-- input rows NULL (so the state stays NULL and the transition function
-- returns NULL), and once with a NULL row following a non-NULL one (so the
-- transition function returns the existing state unmodified).

-- tdigest_add_double_trimmed
SELECT tdigest_avg(v, 100, 0.0, 1.0) FROM (VALUES (NULL::double precision), (NULL)) AS t(v);
SELECT tdigest_avg(v, 100, 0.0, 1.0) FROM (VALUES (1.0), (NULL)) AS t(v);
SELECT tdigest_sum(v, 100, 0.0, 1.0) FROM (VALUES (NULL::double precision), (NULL)) AS t(v);
SELECT tdigest_sum(v, 100, 0.0, 1.0) FROM (VALUES (1.0), (NULL)) AS t(v);

-- tdigest_add_double_count_trimmed
SELECT tdigest_avg(v, 1::bigint, 100, 0.0, 1.0) FROM (VALUES (NULL::double precision), (NULL)) AS t(v);
SELECT tdigest_avg(v, 1::bigint, 100, 0.0, 1.0) FROM (VALUES (1.0), (NULL)) AS t(v);
SELECT tdigest_sum(v, 1::bigint, 100, 0.0, 1.0) FROM (VALUES (NULL::double precision), (NULL)) AS t(v);
SELECT tdigest_sum(v, 1::bigint, 100, 0.0, 1.0) FROM (VALUES (1.0), (NULL)) AS t(v);
