added more flexible output values
This commit is contained in:
parent
d124776c4e
commit
97140b17c9
@ -5,11 +5,11 @@
|
|||||||
--
|
--
|
||||||
--
|
--
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION CDB_DistinctMeasure ( in_array text[], threshold numeric DEFAULT 0.90 ) RETURNS boolean as $$
|
CREATE OR REPLACE FUNCTION CDB_DistinctMeasure ( in_array text[], threshold numeric DEFAULT null ) RETURNS numeric as $$
|
||||||
DECLARE
|
DECLARE
|
||||||
element_count INT4;
|
element_count INT4;
|
||||||
maxval numeric;
|
maxval numeric;
|
||||||
passes boolean;
|
passes numeric;
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT count(e) INTO element_count FROM ( SELECT unnest(in_array) e ) x;
|
SELECT count(e) INTO element_count FROM ( SELECT unnest(in_array) e ) x;
|
||||||
|
|
||||||
@ -35,8 +35,11 @@ BEGIN
|
|||||||
SELECT max(cumsum) maxval FROM b'
|
SELECT max(cumsum) maxval FROM b'
|
||||||
INTO maxval
|
INTO maxval
|
||||||
USING element_count, in_array;
|
USING element_count, in_array;
|
||||||
|
IF threshold is null THEN
|
||||||
passes = (maxval >= threshold);
|
passes = maxval;
|
||||||
|
ELSE
|
||||||
|
passes = CASE WHEN (maxval >= threshold) THEN 1 ELSE 0 END;
|
||||||
|
END IF;
|
||||||
|
|
||||||
RETURN passes;
|
RETURN passes;
|
||||||
END;
|
END;
|
||||||
|
Loading…
Reference in New Issue
Block a user