Skip to content

DBT Test: Check Id Palm Unrefined Seipcs Indonesia Palm Oil 2021 Km 0 Mgd 30 Patched

DBT test name: check_id_palm_unrefined_seipcs_indonesia_palm_oil_2021_km_0_mgd_30_patched_

DBT details


Description

No description


Details

{{ test_check_id_palm_unrefined(**_dbt_generic_test_kwargs) }}{{ config(alias="check_id_palm_unrefined_seipcs_ea676c49edbc66cbb05ccab8f8ce65ae") }}
/*
 * 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 "trase_production"."main_indonesia_palm"."seipcs_indonesia_palm_oil_2021_km_0_mgd_30_patched"
        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 "trase_production"."main_indonesia_palm"."seipcs_indonesia_palm_oil_2021_km_0_mgd_30_patched"
    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'))
        )
    limit 1
)