Skip to content

DBT Test: Check Id Palm Domestic Indonesia Palm Oil Sei Pcs V1 3 Seipcs 2021

DBT test name: check_id_palm_domestic_indonesia_palm_oil_sei_pcs_v1_3_seipcs_2021_

DBT details


Description

No description


Details

{{ test_check_id_palm_domestic(**_dbt_generic_test_kwargs) }}{{ config(alias="check_id_palm_domestic_indones_92d78d36607a8ebbbecd0a7a10bca9aa") }}
/*
 * 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 "memory"."main"."indonesia_palm_oil_sei_pcs_v1_3_seipcs_2021"
        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 "memory"."main"."indonesia_palm_oil_sei_pcs_v1_3_seipcs_2021"
    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'))
    )
)
/* ------------------------------------------------------------------------------------
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 "memory"."main"."indonesia_palm_oil_sei_pcs_v1_3_seipcs_2021"
    where key = 'DOMESTIC' and not (
        commodity = 'CPO'
    )
)
/* ------------------------------------------------------------------------------------
Our fourth test is that domestic flows are always unknown mill
------------------------------------------------------------------------------------- */
union all
(
    select 'some flows are not unrefined palm oil' as error
    from "memory"."main"."indonesia_palm_oil_sei_pcs_v1_3_seipcs_2021"
    where key = 'DOMESTIC' and not (
        mill = 'UNKNOWN' and
        mill_group = 'UNKNOWN'
    )
)