added more flexible output values

This commit is contained in:
Andy Eschbacher 2015-06-24 11:03:16 -04:00
parent d124776c4e
commit 97140b17c9

View File

@ -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;