solana-models/macros/tests/null_threshold.sql
desmond-hui eca2dc5e64
fix data types (#6)
* fix data types

* add null threshold test

* add null threshold for fee col
2022-03-04 10:22:19 -08:00

33 lines
614 B
SQL

{% test null_threshold(
model,
column_name,
threshold_percent
) %}
-- threshold_percent: decimal representing percent of values that should NOT be null
WITH t AS (
SELECT
COUNT(*) * {{ threshold_percent }} AS threshold_num
FROM
{{ model }}
),
C AS (
SELECT
COUNT(*) AS cnt
FROM
{{ model }}
WHERE
{{ column_name }} IS NOT NULL
)
SELECT
*
FROM
C
WHERE
C.cnt <= (
SELECT
MAX(threshold_num)
FROM
t
)
{% endtest %}