Skip to content

DBT Test: Check Id Palm Unrefined Indonesia Palm Oil Sei Pcs V1 3 Seipcs 2020

DBT test name: check_id_palm_unrefined_indonesia_palm_oil_sei_pcs_v1_3_seipcs_2020_

DBT details


Description

No description


Details

{{ test_check_id_palm_unrefined(**_dbt_generic_test_kwargs) }}{{ config(alias="check_id_palm_unrefined_indone_a7f46f34658e9a8b0952a53b86202393") }}
/*
 * This test fails if any unrefined flows of Indonesia palm oil do not have the correct
 * values. For speed the test will return only return a single row for each test with a
 * placeholder value.
 */

/* ------------------------------------------------------------------------------------
Our first test is that the commodity column contains the value CPO at least once
TODO - could run this test once per year?
------------------------------------------------------------------------------------- */
    select 'no such commodity=CPO' as error
    where not exists (
        select 1
        from "memory"."main"."indonesia_palm_oil_sei_pcs_v1_3_seipcs_2020"
        where commodity = 'CPO'
    )
/* ------------------------------------------------------------------------------------
Our second test is that the refinery etc. have specific values if and only if the
commodity is CPO
------------------------------------------------------------------------------------- */
union all
(
    select 'some columns have incorrect values' as error
    from "memory"."main"."indonesia_palm_oil_sei_pcs_v1_3_seipcs_2020"
    where
        -- the below rules do not apply to UNKNOWN COUNTRY flows
        country <> 'UNKNOWN'
        --
        and not (
            ((commodity = 'CPO') = (         refinery = 'NOT REFINED')) and
            ((commodity = 'CPO') = (   refinery_group = 'NOT REFINED')) and
            ((commodity = 'CPO') = (refinery_trase_id = 'ID-PALM-REFINERY-0000'))
        )
)