Skip to content

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

DBT test name: check_id_palm_domestic_seipcs_indonesia_palm_oil_2021_km_0_mgd_30_patched_

DBT details


Description

No description


Details

{{ test_check_id_palm_domestic(**_dbt_generic_test_kwargs) }}{{ config(alias="check_id_palm_domestic_seipcs__34bfb545eecb8f1716d76ecdbea29fcf") }}
/*
 * This test fails if any domestic 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 'key' column contains the value DOMESTIC at least once
TODO - could run this test once per year?
------------------------------------------------------------------------------------- */
    select 'no such key=DOMESTIC' as error
    where not exists (
        select 1
        from "trase_production"."main_indonesia_palm"."seipcs_indonesia_palm_oil_2021_km_0_mgd_30_patched"
        where key = 'DOMESTIC'
    )
/* ------------------------------------------------------------------------------------
Our second test is that the exporter etc. have specific values if and only if the key is
'DOMESTIC'
------------------------------------------------------------------------------------- */
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 not (
        ((key = 'DOMESTIC') = (         exporter = 'DOMESTIC PROCESSING AND CONSUMPTION')) and
        ((key = 'DOMESTIC') = (   exporter_group = 'DOMESTIC PROCESSING AND CONSUMPTION')) and
        ((key = 'DOMESTIC') = (         importer = 'DOMESTIC PROCESSING AND CONSUMPTION')) and
        ((key = 'DOMESTIC') = (   importer_group = 'DOMESTIC PROCESSING AND CONSUMPTION')) and
        ((key = 'DOMESTIC') = (   importer_group = 'DOMESTIC PROCESSING AND CONSUMPTION')) and
        ((key = 'DOMESTIC') = (    port_trase_id = 'ID-PORT-DOMESTIC'))
    )
    limit 1
)
/* ------------------------------------------------------------------------------------
Our third test is that domestic flows are always unrefined palm oil
------------------------------------------------------------------------------------- */
union all
(
    select 'some flows are not unrefined palm oil' as error
    from "trase_production"."main_indonesia_palm"."seipcs_indonesia_palm_oil_2021_km_0_mgd_30_patched"
    where key = 'DOMESTIC' and not (
        commodity = 'CPO'
    )
    limit 1
)
/* ------------------------------------------------------------------------------------
Our fourth test is that domestic flows are always unknown mill
------------------------------------------------------------------------------------- */
union all
(
    select 'some flows are not unrefined palm oil' as error
    from "trase_production"."main_indonesia_palm"."seipcs_indonesia_palm_oil_2021_km_0_mgd_30_patched"
    where key = 'DOMESTIC' and not (
        mill = 'UNKNOWN' and
        mill_group = 'UNKNOWN'
    )
    limit 1
)